-
Notifications
You must be signed in to change notification settings - Fork 729
/
RedactionExtensions.cs
59 lines (51 loc) · 2.79 KB
/
RedactionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using Microsoft.Extensions.Compliance.Classification;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Extensions.Compliance.Redaction;
/// <summary>
/// Extensions to configure specific redactors.
/// </summary>
public static class RedactionExtensions
{
/// <summary>
/// Sets the HMAC redactor to use for a set of data classifications.
/// </summary>
/// <param name="builder">The builder to attach the redactor to.</param>
/// <param name="configure">The configuration function.</param>
/// <param name="classifications">The data classifications for which the redactor type should be used.</param>
/// <returns>The value of <paramref name="builder" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder"/>, <paramref name="configure" />, or <paramref name="classifications" /> is <see langword="null"/>.</exception>
public static IRedactionBuilder SetHmacRedactor(this IRedactionBuilder builder, Action<HmacRedactorOptions> configure, params DataClassificationSet[] classifications)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(configure);
_ = Throw.IfNull(classifications);
_ = builder
.Services
.AddOptionsWithValidateOnStart<HmacRedactorOptions, HmacRedactorOptionsValidator>()
.Configure(configure);
return builder.SetRedactor<HmacRedactor>(classifications);
}
/// <summary>
/// Sets the HMAC redactor to use for a set of data classifications.
/// </summary>
/// <param name="builder">The builder to attach the redactor to.</param>
/// <param name="section">The configuration section.</param>
/// <param name="classifications">The data classifications for which the redactor type should be used.</param>
/// <returns>The value of <paramref name="builder" />.</returns>
/// <exception cref="ArgumentNullException"><paramref name="builder"/>, <paramref name="section" />, or <paramref name="classifications" /> is <see langword="null"/>.</exception>
public static IRedactionBuilder SetHmacRedactor(this IRedactionBuilder builder, IConfigurationSection section, params DataClassificationSet[] classifications)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(section);
_ = Throw.IfNull(classifications);
_ = builder
.Services.AddOptionsWithValidateOnStart<HmacRedactorOptions, HmacRedactorOptionsValidator>()
.Services.Configure<HmacRedactorOptions>(section);
return builder.SetRedactor<HmacRedactor>(classifications);
}
}