Skip to content

Commit

Permalink
Package updates, code clean-up (#18)
Browse files Browse the repository at this point in the history
* nuget updates

* fixes after nuget updates, code clean-up
  • Loading branch information
MrZoidberg authored Oct 15, 2021
1 parent 7ebb080 commit 65a9220
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 45 deletions.
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<PackageReleaseNotes>https://github.com/MrZoidberg/VaultSharp.Extensions.Configuration/releases</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" PrivateAssets="All" Version="3.3.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.8.50" />
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" PrivateAssets="All" Version="5.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" PrivateAssets="All" Version="16.10.56" />
<PackageReference Include="MinVer" PrivateAssets="All" Version="2.5.0" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.118" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private async Task LoadVaultDataAsync(IVaultClient vaultClient)
}
}

private void SetData<TValue>(IEnumerable<KeyValuePair<string, TValue>> data, string key)
private void SetData<TValue>(IEnumerable<KeyValuePair<string, TValue>> data, string? key)
{
foreach (var pair in data)
{
Expand All @@ -142,20 +142,33 @@ private void SetData<TValue>(IEnumerable<KeyValuePair<string, TValue>> data, str
switch (token.Type)
{
case JTokenType.Object:
this.SetData<JToken?>(token.Value<JObject>(), nestedKey);
{
var jObject = token.Value<JObject>();
if (jObject != null)
{
this.SetData<JToken?>(jObject, nestedKey);
}

break;
}

case JTokenType.None:
case JTokenType.Array:
{
var array = (JArray)token;
for (var i = 0; i < array.Count; i++)
{
var arrElement = array[i];

if (array[i].Type == JTokenType.Array)
{
this.SetData<JToken?>(array[i].Value<JObject>(), $"{nestedKey}:{i}");
this.SetData(new[] { new KeyValuePair<string, JToken?>($"{nestedKey}:{i}", arrElement) }, null);
}
else if (array[i].Type == JTokenType.Object)
{
this.SetData<JToken?>(array[i].Value<JObject>(), $"{nestedKey}:{i}");
this.SetData(new[] { new KeyValuePair<string, JToken?>($"{nestedKey}:{i}", arrElement) }, null);

// this.SetData<JToken?>(arrElement, $"{nestedKey}:{i}");
}
else
{
Expand All @@ -164,6 +177,7 @@ private void SetData<TValue>(IEnumerable<KeyValuePair<string, TValue>> data, str
}

break;
}

case JTokenType.Property:
case JTokenType.Integer:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public VaultConfigurationSource(VaultOptions options, string basePath, string? m
this._logger = logger;
this.Options = options;
this.BasePath = basePath;
this.MountPoint = mountPoint ?? SecretsEngineDefaultPaths.KeyValueV2;
this.MountPoint = mountPoint ?? SecretsEngineMountPoints.Defaults.KeyValueV2;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.9" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.9" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.6.13" >
<PrivateAssets>All</PrivateAssets>
<PackageReference Include="GitVersion.MsBuild" Version="5.7.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="VaultSharp" Version="1.4.0.4" />
</ItemGroup>

<ItemGroup Label="Project References">
<PackageReference Include="GitVersionTask" Version="5.3.6">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.19" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.19" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.19" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.10.56">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="VaultSharp" Version="1.7.0" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions Tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

<ItemGroup Label="Package References">
<PackageReference Include="coverlet.collector" PrivateAssets="All" Version="1.3.0">
<PackageReference Include="coverlet.collector" PrivateAssets="All" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="Moq" Version="4.14.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="All" Version="2.4.2">
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="All" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
Expand Down
31 changes: 14 additions & 17 deletions Tests/VaultSharp.Extensions.Configuration.Test/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ namespace VaultSharp.Extensions.Configuration.Test
using DotNet.Testcontainers.Containers.WaitStrategies;
using FluentAssertions;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestPlatform.TestHost;
using Newtonsoft.Json;
using Serilog;
using Serilog.Core;
using Serilog.Extensions.Logging;
using VaultSharp.V1.AuthMethods.Token;
using Xunit;
Expand Down Expand Up @@ -49,7 +47,7 @@ private async Task LoadDataAsync(Dictionary<string, IEnumerable<KeyValuePair<str
{
var authMethod = new TokenAuthMethodInfo("root");

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

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

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

var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonData);
Expand All @@ -89,8 +87,9 @@ public async Task Success_SimpleTest_TokenAuth()
new KeyValuePair<string, object>("option1", "value1"),
new KeyValuePair<string, object>("option3", 5),
new KeyValuePair<string, object>("option4", true),
new KeyValuePair<string, object>("option5", new[] {"v1", "v2", "v3"}),
new KeyValuePair<string, object>("option6",
new KeyValuePair<string, object>("option5", new[] { "v1", "v2", "v3" }),
new KeyValuePair<string, object>(
"option6",
new[]
{
new TestConfigObject() {OptionA = "a1", OptionB = "b1"},
Expand Down Expand Up @@ -194,8 +193,8 @@ public async Task Success_WatcherTest_TokenAuth()
var values =
new Dictionary<string, IEnumerable<KeyValuePair<string, object>>>
{
{"test", new[] {new KeyValuePair<string, object>("option1", "value1"),}},
{"test/subsection", new[] {new KeyValuePair<string, object>("option2", "value2"),}},
{ "test", new[] { new KeyValuePair<string, object>("option1", "value1") } },
{ "test/subsection", new[] { new KeyValuePair<string, object>("option2", "value2") } },
};

var container = this.PrepareVaultContainer();
Expand All @@ -208,8 +207,7 @@ public async Task Success_WatcherTest_TokenAuth()
// act
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddVaultConfiguration(
() => new VaultOptions("http://localhost:8200", "root", reloadOnChange: true,
reloadCheckIntervalSeconds: 10),
() => new VaultOptions("http://localhost:8200", "root", reloadOnChange: true, reloadCheckIntervalSeconds: 10),
"test",
"secret",
this._logger);
Expand All @@ -226,12 +224,12 @@ public async Task Success_WatcherTest_TokenAuth()
// load new data and wait for reload
values = new Dictionary<string, IEnumerable<KeyValuePair<string, object>>>
{
{"test", new[] {new KeyValuePair<string, object>("option1", "value1_new"),}},
{"test/subsection", new[] {new KeyValuePair<string, object>("option2", "value2_new"),}},
{"test/subsection3", new[] {new KeyValuePair<string, object>("option3", "value3_new"),}},
{ "test", new[] { new KeyValuePair<string, object>("option1", "value1_new") } },
{ "test/subsection", new[] { new KeyValuePair<string, object>("option2", "value2_new") } },
{ "test/subsection3", new[] { new KeyValuePair<string, object>("option3", "value3_new") } },
};
await this.LoadDataAsync(values).ConfigureAwait(false);
await Task.Delay(TimeSpan.FromSeconds(15)).ConfigureAwait(true);
await Task.Delay(TimeSpan.FromSeconds(15), cts.Token).ConfigureAwait(true);

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


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

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

reloadToken.HasChanged.Should().BeTrue();
configurationRoot.GetValue<string>("option1").Should().Be("value1_new");
Expand All @@ -298,7 +296,6 @@ public async Task Success_WatcherTest_OmitVaultKey_TokenAuth()
await container.DisposeAsync().ConfigureAwait(false);
}
}

}

public class TestConfigObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DotNet.Testcontainers" Version="1.4.0" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.6.13" />
<PackageReference Include="DotNet.Testcontainers" Version="1.5.0" />
<PackageReference Include="FluentAssertions" Version="6.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.19" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.19" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.19" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="16.10.56" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ Task("Test")
NoRestore = true,
ResultsDirectory = artefactsDirectory,
ArgumentCustomization = x => x
.Append("--blame")
.AppendSwitch("--logger", $"html;LogFileName={project.GetFilenameWithoutExtension()}.html")
.Append("--collect:\"XPlat Code Coverage\"")
.Append("--settings runsettings.xml"),
Expand Down
2 changes: 1 addition & 1 deletion dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "0.38.5",
"version": "1.3.0",
"commands": [
"dotnet-cake"
]
Expand Down
Binary file modified tools/nuget.exe
Binary file not shown.

0 comments on commit 65a9220

Please sign in to comment.