Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Commit c419fe8

Browse files
shhhh
1 parent e95774d commit c419fe8

File tree

1 file changed

+56
-13
lines changed

1 file changed

+56
-13
lines changed

src/SqlStreamStore.Server/SqlStreamStoreServerConfiguration.cs

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Data.Common;
45
using System.Linq;
56
using System.Reflection;
67
using System.Text;
@@ -86,17 +87,7 @@ public ConfigurationData(IConfigurationRoot configuration)
8687

8788
public override string ToString()
8889
{
89-
var values = new Dictionary<string, (string source, string value)>();
90-
91-
foreach (var provider in _configuration.Providers)
92-
{
93-
var source = provider.GetType().Name;
94-
foreach (var key in provider.GetChildKeys(Enumerable.Empty<string>(), default))
95-
{
96-
if (provider.TryGet(key, out var value))
97-
values[key] = (source, value);
98-
}
99-
}
90+
var values = ProtectConfiguration(CollectConfiguration());
10091

10192
const string delimiter = " │ ";
10293

@@ -122,7 +113,7 @@ public override string ToString()
122113
}
123114
}
124115
.Concat(
125-
s_allKeys.Select(key => new[] {delimiter, key, values[key].value, values[key].source}))
116+
values.Keys.Select(key => new[] {delimiter, key, values[key].value, values[key].source}))
126117
.Aggregate(
127118
new StringBuilder().AppendLine("SQL Stream Store Configuration:"),
128119
(builder, v) => builder
@@ -133,6 +124,58 @@ public override string ToString()
133124
.AppendLine(v[3]))
134125
.ToString();
135126
}
127+
128+
private static string ProtectConfigurationString(string connectionString)
129+
{
130+
var builder = new DbConnectionStringBuilder(false)
131+
{
132+
ConnectionString = connectionString
133+
};
134+
135+
var sensitiveKeys = new[]
136+
{
137+
"Password",
138+
"Pwd",
139+
};
140+
141+
142+
foreach (var key in sensitiveKeys)
143+
{
144+
if (builder.ContainsKey(key))
145+
{
146+
builder[key] = "******";
147+
}
148+
}
149+
150+
return builder.ConnectionString;
151+
}
152+
153+
private IDictionary<string, (string source, string value)> ProtectConfiguration(
154+
IDictionary<string, (string source, string value)> values)
155+
=> values.ToDictionary(
156+
x => x.Key,
157+
x => x.Key == nameof(ConnectionString)
158+
? (x.Value.source, ProtectConfigurationString(x.Value.value))
159+
: x.Value);
160+
161+
private IDictionary<string, (string source, string value)> CollectConfiguration()
162+
{
163+
var values = new Dictionary<string, (string source, string value)>();
164+
165+
foreach (var provider in _configuration.Providers)
166+
{
167+
var source = provider.GetType().Name;
168+
foreach (var key in provider.GetChildKeys(Enumerable.Empty<string>(), default))
169+
{
170+
if (provider.TryGet(key, out var value))
171+
{
172+
values[key] = (source, value);
173+
}
174+
}
175+
}
176+
177+
return values;
178+
}
136179
}
137180

138181
private class DefaultSource : IConfigurationSource
@@ -179,7 +222,7 @@ private class CommandLine : CommandLineConfigurationProvider
179222
{
180223
public CommandLine(
181224
IEnumerable<string> args,
182-
IDictionary<string, string> switchMappings = null)
225+
IDictionary<string, string> switchMappings = null)
183226
: base(args, switchMappings)
184227
{
185228
}

0 commit comments

Comments
 (0)