diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-12-09 08:04:24 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-09 08:04:24 -0600 |
| commit | 24ce3f1b74a26b04dd96be62c07d25da0158df0b (patch) | |
| tree | 216be0fbdfdab5728cfcd14101cb85de39a4c3f1 /src/slskd/Common/Extensions.cs | |
| parent | ec60cfbd397badca9a76d3923c653ad7cb6561c5 (diff) | |
| parent | 2262e842f42ccef7f557cee4f7e05c9adf15b739 (diff) | |
| download | slskd-24ce3f1b74a26b04dd96be62c07d25da0158df0b.tar.gz | |
Merge pull request #299 from slskd/secrets
Explicitly redact secrets stored in options before exporting them
Diffstat (limited to 'src/slskd/Common/Extensions.cs')
| -rw-r--r-- | src/slskd/Common/Extensions.cs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/slskd/Common/Extensions.cs b/src/slskd/Common/Extensions.cs index d678541d..0f3f8362 100644 --- a/src/slskd/Common/Extensions.cs +++ b/src/slskd/Common/Extensions.cs @@ -308,6 +308,21 @@ namespace slskd } /// <summary> + /// Redacts this instance of Options, replacing properties marked with <see cref="SecretAttribute"/> with '*****'. + /// </summary> + /// <remarks> + /// Creates a deep clone before redacting. + /// </remarks> + /// <param name="options">The Options instance to redact.</param> + /// <returns>A redacted instance.</returns> + public static Options Redact(this Options options) + { + var redacted = options.ToJson().FromJson<Options>(); + Redactor.Redact(redacted, redactWith: "*****"); + return redacted; + } + + /// <summary> /// Creates a copy of this instance with the specified parameters changed. /// </summary> /// <param name="o">The options instance to copy.</param> @@ -350,6 +365,7 @@ namespace slskd var options = new JsonSerializerOptions(); options.Converters.Add(new IPAddressConverter()); options.Converters.Add(new JsonStringEnumConverter()); + options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; options.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; return options; } |
