A Kotlin compiler plugin that generates redacted toString() implementations.
A Kotlin compiler plugin that generates redacted
toString()implementations.
auto-value-redactedextension for AutoValue.
Include the gradle plugin in your project, define a
@Redactedannotation, and apply it to any properties that you wish to redact.
@Retention(SOURCE) @Target(PROPERTY) annotation class Redacteddata class User(val name: String, @Redacted val phoneNumber: String)
When you call
toString()any
@Redactedproperties are hidden:
User(name=Bob, phoneNumber=██)
If your annotation is applied to the class, then
toString()will emit a single replacement string:
@Retention(SOURCE) @Target(CLASS) annotation class Redacted@Redacted data class SensitiveData(val ssn: String, val birthday: String)
SensitiveData(██)
Apply the gradle plugin.
plugins { id("dev.zacsweers.redacted.redacted-gradle-plugin") version }
And that's it! The default configuration will add the
-annotationsartifact (which has a
@Redactedannotation you can use) and wire it all automatically. Just annotate what you want to redact.
You can configure custom behavior with properties on the
redactedextension.
redacted { // Define a custom annotation. The -annotations artifact won't be automatically added to // dependencies if you define your own! redactedAnnotation = "dev.zacsweers.redacted.annotations.Redacted" // Default// Define whether or not this is enabled. Useful if you want to gate this behind a dynamic // build configuration. enabled = true // Default
// Define a custom replacement string for redactions. replacementString = "██" // Default }
If using Android, you can optionally configure the plugin to be applied on a per-variant basis via
androidVariantFilter. This is similar to the Android Gradle Plugin's native
variantFilterAPI, except with an
overrideEnabledfunction to override the enabled status and there is no
defaultConfigproperty. If not overridden, the default is to match the
redactedextension's value. Other
VariantFilterAPIs should behave as expected (buildType, flavors, name, etc).
Note: Variants with different
enabledvalues will have to be compiled separately. This is common in most multi-variant projects anyway, but something to be aware of.
redacted { enabled = true // Default androidVariantFilter { // Don't enable on debug if (buildType.name == "debug") { overrideEnabled(false) } } }
Snapshots of the development version are available in Sonatype's
snapshotsrepository.
Copyright (C) 2018 Zac SweersLicensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.