• Stars
    star
    382
  • Rank 112,241 (Top 3 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Kotlin compiler plugin that generates redacted toString() implementations.

redacted-compiler-plugin

A multiplatform Kotlin compiler plugin that generates redacted toString() implementations.

Inspired by the auto-value-redacted extension for AutoValue.

Usage

Include the gradle plugin in your project, define a @Redacted annotation, and apply it to any properties that you wish to redact.

@Retention(SOURCE)
@Target(PROPERTY)
annotation class Redacted

data class User(val name: String, @Redacted val phoneNumber: String)

When you call toString() any @Redacted properties 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(██)

Installation

Apply the gradle plugin.

plugins {
  id("dev.zacsweers.redacted") version <version>
}

And that's it! The default configuration will add the multiplatform -annotations artifact (which has a @Redacted annotation you can use) and wire it all automatically. Just annotate what you want to redact.

You can configure custom behavior with properties on the redacted extension.

redacted {
  // Define a custom annotation. The -annotations artifact won't be automatically added to
  // dependencies if you define your own!
  // Note that this must be in the format of a string where packages are delimited by '/' and
  // classes by '.', e.g. "kotlin/Map.Entry"
  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
}

Snapshots of the development version are available in Sonatype's snapshots repository.

Supported platforms

The compiler plugin itself supports all multiplatform project types. The first-party annotations artifact is also multiplatform and supports all common JVM, JS, and native targets.

Caveats

  • Kotlin compiler plugins are not a stable API! Compiled outputs from this plugin should be stable, but usage in newer versions of kotlinc are not guaranteed to be stable.
  • IDE support is not currently possible. See #8.

License

Copyright (C) 2018 Zac Sweers

Licensed 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

   https://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.

More Repositories

1

CatchUp

An app for catching up on things.
Kotlin
1,871
star
2

barber

A custom view styling library for Android that generates the obtainStyledAttributes() and TypedArray boilerplate code for you.
Java
708
star
3

MoshiX

Extensions for Moshi including IR plugins, moshi-sealed, and more.
Kotlin
514
star
4

RxPalette

RxJava bindings for the Palette library on Android
Java
199
star
5

palettehelper

Utility Android app for generating color palettes of images using the Palette library. Written in Kotlin.
Kotlin
155
star
6

ticktock

A timezone data management library for the JVM and Android targeting java.time APIs in Java 8+
Java
138
star
7

auto-service-ksp

A KSP implementation of AutoService
Kotlin
124
star
8

inspector

A tiny class validation library.
Java
62
star
9

json-serialization-benchmarking

Miscellaneous benchmarks for JSON serialization on JVM/Android
Java
58
star
10

copydynamic

Prototype of generating `copyDynamic` extension functions for kotlin data classes
Kotlin
56
star
11

FB_Mod_Bot

A Facebook bot for moderating groups
Python
45
star
12

kgp-150-leak-patcher

A simple plugin to patch the memory leak in Kotlin Gradle Plugin 1.5.0
Kotlin
40
star
13

blackmirror

Java
39
star
14

FieldSpottr

An app for checking field permit status on nycgovparks
Kotlin
36
star
15

RxNormalize

A normalizing operator for RxJava Observables.
Java
27
star
16

SUREwalk_android

Source code for the SUREwalk Android app
Java
19
star
17

kotlin-template

Kotlin
16
star
18

ArraySetBackport

Backport of Android's ArraySet implementation that supports API 14+
Java
16
star
19

ZacSweers

Kotlin
15
star
20

SpursGifs_xposterbot

Reddit bot I wrote while sitting bored in a hotel room for x-posting gifs/vines/gyfcats from /r/coys to /r/SpursGifs
Python
11
star
21

check-gradle-checksums

Check your gradle-wrapper jar's checksum on CI
Shell
10
star
22

empty-android-project

Empty boilerplate Android project with my preferred defaults
Java
9
star
23

kotlinpoet-contracts

Contracts support for KotlinPoet
Kotlin
7
star
24

AutoTransient

A transient annotation for AutoValue extensions.
Java
7
star
25

auto-service-kt

A Kotlin compiler plugin implementation of AutoService
Kotlin
6
star
26

configurable-checkreturnvalue

Configurable Lint and Error-Prone checker alternatives for @CheckReturnValue
Java
6
star
27

gfy_mirror

Gfy_mirror bot source code
Python
6
star
28

kgp-160-patcher

A simple monkeypatch for issues in Kotlin Gradle Plugin 1.6.0.
5
star
29

android-codepad

Automatically exported from code.google.com/p/android-codepad
Java
4
star
30

Android-TicTacToe

Java
4
star
31

aak

An annotation processor to generate Proxy-based helper methods for creating Kotlin annotations at runtime. Based on Google's AutoAnnotation processor for Java.
Kotlin
4
star
32

LabStatus

A very minimal JSON API for the UTCS labs using cgi scripts
3
star
33

Holo-Goo.gl

My first Android application, a Holo Goo.gl URL shortening app.
Java
3
star
34

succession

Kotlin
3
star
35

akibstool

Akib's tool
Kotlin
2
star
36

fb_group_analytics

Some Python code for analyzing Facebook groups
Python
2
star
37

entitydataclassfrommodules

Demo project for https://issuetracker.google.com/issues/67181813
Kotlin
1
star
38

hzsweers.github.io

Moved to https://zacsweers.dev
CSS
1
star
39

zacsweers.github.io

HTML
1
star
40

373_practice

Python
1
star
41

371p_practice

A group for getting extra practice and review for Downing's 371p OOP class
C++
1
star