Skip to content

Commit 7d58bf4

Browse files
committed
config
1 parent b51a25f commit 7d58bf4

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

aws/logs_monitoring_go/internal/config/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ type Config struct {
2323
Source string
2424
Host string
2525
CustomTags string
26+
Scrubbing ScrubbingConfig
27+
}
28+
29+
type ScrubbingConfig struct {
30+
ScrubIP bool
31+
ScrubEmail bool
32+
CustomRule string
33+
CustomReplacement string
2634
}
2735

2836
func Load(ctx context.Context) (*Config, error) {
@@ -54,6 +62,12 @@ func loadConfig() *Config {
5462
Source: envOrDefault("DD_SOURCE", ""),
5563
Host: envOrDefault("DD_HOST", ""),
5664
CustomTags: envOrDefault("DD_TAGS", ""),
65+
Scrubbing: ScrubbingConfig{
66+
ScrubIP: envOrDefaultBool("REDACT_IP", false),
67+
ScrubEmail: envOrDefaultBool("REDACT_EMAIL", false),
68+
CustomRule: envOrDefault("DD_SCRUBBING_RULE", ""),
69+
CustomReplacement: envOrDefault("DD_SCRUBBING_RULE_REPLACEMENT", ""),
70+
},
5771
}
5872
}
5973

@@ -64,5 +78,8 @@ func (c Config) LogValue() slog.Value {
6478
slog.String("apiUrl", c.APIURL),
6579
slog.String("loglevel", c.LogLevel),
6680
slog.Bool("fips", c.UseFIPS),
81+
slog.Bool("redactIP", c.Scrubbing.ScrubIP),
82+
slog.Bool("redactEmail", c.Scrubbing.ScrubEmail),
83+
slog.Bool("customScrubbing", c.Scrubbing.CustomRule != ""),
6784
)
6885
}

aws/logs_monitoring_go/internal/config/config_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,29 @@ func TestLoadConfig(t *testing.T) {
6363
CustomTags: "env:prod,team:aws",
6464
},
6565
},
66+
"scrubbing_ip_enabled": {
67+
env: map[string]string{"REDACT_IP": "true"},
68+
want: Config{
69+
Site: "datadoghq.com",
70+
IntakeURL: "https://http-intake.logs.datadoghq.com",
71+
APIURL: "https://api.datadoghq.com",
72+
LogLevel: "INFO",
73+
Scrubbing: ScrubbingConfig{ScrubIP: true},
74+
},
75+
},
76+
"scrubbing_custom_rule": {
77+
env: map[string]string{
78+
"DD_SCRUBBING_RULE": `\d+`,
79+
"DD_SCRUBBING_RULE_REPLACEMENT": "X",
80+
},
81+
want: Config{
82+
Site: "datadoghq.com",
83+
IntakeURL: "https://http-intake.logs.datadoghq.com",
84+
APIURL: "https://api.datadoghq.com",
85+
LogLevel: "INFO",
86+
Scrubbing: ScrubbingConfig{CustomRule: `\d+`, CustomReplacement: "X"},
87+
},
88+
},
6689
}
6790

6891
for name, tc := range tests {

0 commit comments

Comments
 (0)