Skip to content

Commit 65a9220

Browse files
authored
Package updates, code clean-up (#18)
* nuget updates * fixes after nuget updates, code clean-up
1 parent 7ebb080 commit 65a9220

File tree

10 files changed

+56
-45
lines changed

10 files changed

+56
-45
lines changed

Directory.Build.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<PackageReleaseNotes>https://github.com/MrZoidberg/VaultSharp.Extensions.Configuration/releases</PackageReleaseNotes>
1717
</PropertyGroup>
1818
<ItemGroup Label="Package References">
19-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" Version="3.3.0" />
20-
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.8.50" />
21-
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.3.0" />
19+
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" PrivateAssets="All" Version="5.0.3" />
20+
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.10.56" />
21+
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.5.0" />
2222
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.118" />
2323
</ItemGroup>
2424
</Project>

Source/VaultSharp.Extensions.Configuration/VaultConfigurationProvider.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private async Task LoadVaultDataAsync(IVaultClient vaultClient)
116116
}
117117
}
118118

119-
private void SetData<TValue>(IEnumerable<KeyValuePair<string, TValue>> data, string key)
119+
private void SetData<TValue>(IEnumerable<KeyValuePair<string, TValue>> data, string? key)
120120
{
121121
foreach (var pair in data)
122122
{
@@ -142,20 +142,33 @@ private void SetData<TValue>(IEnumerable<KeyValuePair<string, TValue>> data, str
142142
switch (token.Type)
143143
{
144144
case JTokenType.Object:
145-
this.SetData<JToken?>(token.Value<JObject>(), nestedKey);
145+
{
146+
var jObject = token.Value<JObject>();
147+
if (jObject != null)
148+
{
149+
this.SetData<JToken?>(jObject, nestedKey);
150+
}
151+
146152
break;
153+
}
154+
147155
case JTokenType.None:
148156
case JTokenType.Array:
157+
{
149158
var array = (JArray)token;
150159
for (var i = 0; i < array.Count; i++)
151160
{
161+
var arrElement = array[i];
162+
152163
if (array[i].Type == JTokenType.Array)
153164
{
154-
this.SetData<JToken?>(array[i].Value<JObject>(), $"{nestedKey}:{i}");
165+
this.SetData(new[] { new KeyValuePair<string, JToken?>($"{nestedKey}:{i}", arrElement) }, null);
155166
}
156167
else if (array[i].Type == JTokenType.Object)
157168
{
158-
this.SetData<JToken?>(array[i].Value<JObject>(), $"{nestedKey}:{i}");
169+
this.SetData(new[] { new KeyValuePair<string, JToken?>($"{nestedKey}:{i}", arrElement) }, null);
170+
171+
// this.SetData<JToken?>(arrElement, $"{nestedKey}:{i}");
159172
}
160173
else
161174
{
@@ -164,6 +177,7 @@ private void SetData<TValue>(IEnumerable<KeyValuePair<string, TValue>> data, str
164177
}
165178

166179
break;
180+
}
167181

168182
case JTokenType.Property:
169183
case JTokenType.Integer:

Source/VaultSharp.Extensions.Configuration/VaultConfigurationSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public VaultConfigurationSource(VaultOptions options, string basePath, string? m
3333
this._logger = logger;
3434
this.Options = options;
3535
this.BasePath = basePath;
36-
this.MountPoint = mountPoint ?? SecretsEngineDefaultPaths.KeyValueV2;
36+
this.MountPoint = mountPoint ?? SecretsEngineMountPoints.Defaults.KeyValueV2;
3737
}
3838

3939
/// <summary>

Source/VaultSharp.Extensions.Configuration/VaultSharp.Extensions.Configuration.csproj

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,17 @@
1717
</PropertyGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
21-
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.8" />
22-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.9" />
23-
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.6.13" >
24-
<PrivateAssets>All</PrivateAssets>
20+
<PackageReference Include="GitVersion.MsBuild" Version="5.7.0">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2523
</PackageReference>
26-
<PackageReference Include="VaultSharp" Version="1.4.0.4" />
27-
</ItemGroup>
28-
29-
<ItemGroup Label="Project References">
30-
<PackageReference Include="GitVersionTask" Version="5.3.6">
24+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.19" />
25+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.19" />
26+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.19" />
27+
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.10.56">
3128
<PrivateAssets>All</PrivateAssets>
3229
</PackageReference>
30+
<PackageReference Include="VaultSharp" Version="1.7.0" />
3331
</ItemGroup>
3432

3533
</Project>

Tests/Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
44

55
<ItemGroup Label="Package References">
6-
<PackageReference Include="coverlet.collector" PrivateAssets="All" Version="1.3.0">
6+
<PackageReference Include="coverlet.collector" PrivateAssets="All" Version="3.1.0">
77
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
88
</PackageReference>
9-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
10-
<PackageReference Include="Moq" Version="4.14.7" />
9+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
10+
<PackageReference Include="Moq" Version="4.16.1" />
1111
<PackageReference Include="xunit" Version="2.4.1" />
12-
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="All" Version="2.4.2">
12+
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="All" Version="2.4.3">
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1414
</PackageReference>
1515
</ItemGroup>

Tests/VaultSharp.Extensions.Configuration.Test/IntegrationTests.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ namespace VaultSharp.Extensions.Configuration.Test
99
using DotNet.Testcontainers.Containers.WaitStrategies;
1010
using FluentAssertions;
1111
using Microsoft.Extensions.Configuration;
12-
using Microsoft.VisualStudio.TestPlatform.TestHost;
1312
using Newtonsoft.Json;
1413
using Serilog;
15-
using Serilog.Core;
1614
using Serilog.Extensions.Logging;
1715
using VaultSharp.V1.AuthMethods.Token;
1816
using Xunit;
@@ -49,7 +47,7 @@ private async Task LoadDataAsync(Dictionary<string, IEnumerable<KeyValuePair<str
4947
{
5048
var authMethod = new TokenAuthMethodInfo("root");
5149

52-
var vaultClientSettings = new VaultClientSettings("http://localhost:8200", authMethod);
50+
var vaultClientSettings = new VaultClientSettings("http://localhost:8200", authMethod) { SecretsEngineMountPoints = { KeyValueV2 = "secret" } };
5351
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
5452

5553
foreach (var sectionPair in values)
@@ -69,7 +67,7 @@ private async Task LoadDataAsync(string secretPath, string jsonData)
6967
{
7068
var authMethod = new TokenAuthMethodInfo("root");
7169

72-
var vaultClientSettings = new VaultClientSettings("http://localhost:8200", authMethod);
70+
var vaultClientSettings = new VaultClientSettings("http://localhost:8200", authMethod) { SecretsEngineMountPoints = { KeyValueV2 = "secret" } };
7371
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
7472

7573
var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonData);
@@ -89,8 +87,9 @@ public async Task Success_SimpleTest_TokenAuth()
8987
new KeyValuePair<string, object>("option1", "value1"),
9088
new KeyValuePair<string, object>("option3", 5),
9189
new KeyValuePair<string, object>("option4", true),
92-
new KeyValuePair<string, object>("option5", new[] {"v1", "v2", "v3"}),
93-
new KeyValuePair<string, object>("option6",
90+
new KeyValuePair<string, object>("option5", new[] { "v1", "v2", "v3" }),
91+
new KeyValuePair<string, object>(
92+
"option6",
9493
new[]
9594
{
9695
new TestConfigObject() {OptionA = "a1", OptionB = "b1"},
@@ -194,8 +193,8 @@ public async Task Success_WatcherTest_TokenAuth()
194193
var values =
195194
new Dictionary<string, IEnumerable<KeyValuePair<string, object>>>
196195
{
197-
{"test", new[] {new KeyValuePair<string, object>("option1", "value1"),}},
198-
{"test/subsection", new[] {new KeyValuePair<string, object>("option2", "value2"),}},
196+
{ "test", new[] { new KeyValuePair<string, object>("option1", "value1") } },
197+
{ "test/subsection", new[] { new KeyValuePair<string, object>("option2", "value2") } },
199198
};
200199

201200
var container = this.PrepareVaultContainer();
@@ -208,8 +207,7 @@ public async Task Success_WatcherTest_TokenAuth()
208207
// act
209208
ConfigurationBuilder builder = new ConfigurationBuilder();
210209
builder.AddVaultConfiguration(
211-
() => new VaultOptions("http://localhost:8200", "root", reloadOnChange: true,
212-
reloadCheckIntervalSeconds: 10),
210+
() => new VaultOptions("http://localhost:8200", "root", reloadOnChange: true, reloadCheckIntervalSeconds: 10),
213211
"test",
214212
"secret",
215213
this._logger);
@@ -226,12 +224,12 @@ public async Task Success_WatcherTest_TokenAuth()
226224
// load new data and wait for reload
227225
values = new Dictionary<string, IEnumerable<KeyValuePair<string, object>>>
228226
{
229-
{"test", new[] {new KeyValuePair<string, object>("option1", "value1_new"),}},
230-
{"test/subsection", new[] {new KeyValuePair<string, object>("option2", "value2_new"),}},
231-
{"test/subsection3", new[] {new KeyValuePair<string, object>("option3", "value3_new"),}},
227+
{ "test", new[] { new KeyValuePair<string, object>("option1", "value1_new") } },
228+
{ "test/subsection", new[] { new KeyValuePair<string, object>("option2", "value2_new") } },
229+
{ "test/subsection3", new[] { new KeyValuePair<string, object>("option3", "value3_new") } },
232230
};
233231
await this.LoadDataAsync(values).ConfigureAwait(false);
234-
await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(true);
232+
await Task.Delay(TimeSpan.FromSeconds(15), cts.Token).ConfigureAwait(true);
235233

236234
reloadToken.HasChanged.Should().BeTrue();
237235
configurationRoot.GetValue<string>("option1").Should().Be("value1_new");
@@ -257,7 +255,7 @@ public async Task Success_WatcherTest_OmitVaultKey_TokenAuth()
257255
var container = this.PrepareVaultContainer();
258256
try
259257
{
260-
await container.StartAsync().ConfigureAwait(false);
258+
await container.StartAsync(cts.Token).ConfigureAwait(false);
261259
await this.LoadDataAsync("myservice-config", jsonData).ConfigureAwait(false);
262260

263261

@@ -283,7 +281,7 @@ public async Task Success_WatcherTest_OmitVaultKey_TokenAuth()
283281
@"{""option1"": ""value1_new"",""subsection"": {""option2"": ""value2_new""},""subsection3"": {""option3"": ""value3_new""}}";
284282

285283
await this.LoadDataAsync("myservice-config", jsonData).ConfigureAwait(false);
286-
await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(true);
284+
await Task.Delay(TimeSpan.FromSeconds(15), cts.Token).ConfigureAwait(true);
287285

288286
reloadToken.HasChanged.Should().BeTrue();
289287
configurationRoot.GetValue<string>("option1").Should().Be("value1_new");
@@ -298,7 +296,6 @@ public async Task Success_WatcherTest_OmitVaultKey_TokenAuth()
298296
await container.DisposeAsync().ConfigureAwait(false);
299297
}
300298
}
301-
302299
}
303300

304301
public class TestConfigObject

Tests/VaultSharp.Extensions.Configuration.Test/VaultSharp.Extensions.Configuration.Test.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<PackageReference Include="DotNet.Testcontainers" Version="1.4.0" />
22-
<PackageReference Include="FluentAssertions" Version="5.10.3" />
23-
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
24-
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.6.13" />
21+
<PackageReference Include="DotNet.Testcontainers" Version="1.5.0" />
22+
<PackageReference Include="FluentAssertions" Version="6.1.0" />
23+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.19" />
24+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.19" />
25+
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.19" />
26+
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
27+
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.10.56" />
2528
</ItemGroup>
2629

2730
</Project>

build.cake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Task("Test")
5353
NoRestore = true,
5454
ResultsDirectory = artefactsDirectory,
5555
ArgumentCustomization = x => x
56-
.Append("--blame")
5756
.AppendSwitch("--logger", $"html;LogFileName={project.GetFilenameWithoutExtension()}.html")
5857
.Append("--collect:\"XPlat Code Coverage\"")
5958
.Append("--settings runsettings.xml"),

dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"isRoot": true,
44
"tools": {
55
"cake.tool": {
6-
"version": "0.38.5",
6+
"version": "1.3.0",
77
"commands": [
88
"dotnet-cake"
99
]

tools/nuget.exe

-6.21 MB
Binary file not shown.

0 commit comments

Comments
 (0)