Skip to content

Commit b4f999a

Browse files
authored
Refactoring to fix #31 (#32)
* Migrated to the latest version of VaultSharp. Migrated to System.Text.Json. Fixed issue #31 * changed year in copyright * added logs to the integration tests
1 parent b786db7 commit b4f999a

File tree

10 files changed

+345
-144
lines changed

10 files changed

+345
-144
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
uses: actions/setup-dotnet@v2
3131
with:
3232
dotnet-version: '6.0.x'
33+
- name: 'Fix permissions'
34+
run: chmod +x ./Tests/VaultSharp.Extensions.Configuration.Test/approle.sh && chmod +x ./Tests/VaultSharp.Extensions.Configuration.Test/approle_nolist.sh
35+
shell: bash
3336
- name: 'Dotnet Tool Restore'
3437
run: dotnet tool restore
3538
shell: pwsh

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PropertyGroup Label="Package">
88
<Authors>Mikhail Merkulov</Authors>
99
<Company>Mikhail Merkulov</Company>
10-
<Copyright>Copyright 2022 © Mikhail Merkulov. All rights Reserved</Copyright>
10+
<Copyright>Copyright 2023 © Mikhail Merkulov. All rights Reserved</Copyright>
1111
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1212
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1313
<PackageProjectUrl>https://github.com/MrZoidberg/VaultSharp.Extensions.Configuration</PackageProjectUrl>

Source/VaultSharp.Extensions.Configuration/VaultConfigurationProvider.cs

Lines changed: 94 additions & 113 deletions
Large diffs are not rendered by default.

Source/VaultSharp.Extensions.Configuration/VaultConfigurationSource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public sealed class VaultConfigurationSource : IConfigurationSource
1919
/// </summary>
2020
internal const string DefaultVaultToken = "root";
2121

22-
private readonly ILogger? _logger;
22+
private readonly ILogger? logger;
2323

2424
/// <summary>
2525
/// Initializes a new instance of the <see cref="VaultConfigurationSource"/> class.
@@ -30,7 +30,7 @@ public sealed class VaultConfigurationSource : IConfigurationSource
3030
/// <param name="logger">Logger instance.</param>
3131
public VaultConfigurationSource(VaultOptions options, string basePath, string? mountPoint = null, ILogger? logger = null)
3232
{
33-
this._logger = logger;
33+
this.logger = logger;
3434
this.Options = options;
3535
this.BasePath = basePath;
3636
this.MountPoint = mountPoint ?? SecretsEngineMountPoints.Defaults.KeyValueV2;
@@ -56,6 +56,6 @@ public VaultConfigurationSource(VaultOptions options, string basePath, string? m
5656
/// </summary>
5757
/// <param name="builder">Configuration builder.</param>
5858
/// <returns>Instance of <see cref="IConfigurationProvider"/>.</returns>
59-
public IConfigurationProvider Build(IConfigurationBuilder builder) => new VaultConfigurationProvider(this, this._logger);
59+
public IConfigurationProvider Build(IConfigurationBuilder builder) => new VaultConfigurationProvider(this, this.logger);
6060
}
6161
}

Source/VaultSharp.Extensions.Configuration/VaultOptions.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class VaultOptions
2121
/// <param name="omitVaultKeyName">Omit Vault Key Name in Configuration Keys.</param>
2222
/// <param name="additionalCharactersForConfigurationPath">Additional characters for the Configuration path.</param>
2323
/// <param name="namespace">Vault namespace.</param>
24+
/// <param name="alwaysAddTrailingSlashToBasePath">Should a trailing slash be added to the base path. See AlwaysAddTrailingSlashToBasePath property for details </param>
2425
public VaultOptions(
2526
string vaultAddress,
2627
string? vaultToken,
@@ -30,7 +31,8 @@ public VaultOptions(
3031
int reloadCheckIntervalSeconds = 300,
3132
bool omitVaultKeyName = false,
3233
IEnumerable<char>? additionalCharactersForConfigurationPath = null,
33-
string? @namespace = null)
34+
string? @namespace = null,
35+
bool alwaysAddTrailingSlashToBasePath = true)
3436
{
3537
this.VaultAddress = vaultAddress;
3638
this.VaultToken = vaultToken;
@@ -41,6 +43,7 @@ public VaultOptions(
4143
this.OmitVaultKeyName = omitVaultKeyName;
4244
this.AdditionalCharactersForConfigurationPath = additionalCharactersForConfigurationPath ?? Array.Empty<char>();
4345
this.Namespace = @namespace;
46+
this.AlwaysAddTrailingSlashToBasePath = alwaysAddTrailingSlashToBasePath;
4447
}
4548

4649
/// <summary>
@@ -53,14 +56,16 @@ public VaultOptions(
5356
/// <param name="omitVaultKeyName">Omit Vault Key Name in Configuration Keys.</param>
5457
/// <param name="additionalCharactersForConfigurationPath">Additional characters for the Configuration path.</param>
5558
/// <param name="namespace">Vault namespace.</param>
59+
/// <param name="alwaysAddTrailingSlashToBasePath">Should a trailing slash be added to the base path. See AlwaysAddTrailingSlashToBasePath property for details </param>
5660
public VaultOptions(
5761
string vaultAddress,
5862
IAuthMethodInfo authMethod,
5963
bool reloadOnChange = false,
6064
int reloadCheckIntervalSeconds = 300,
6165
bool omitVaultKeyName = false,
6266
IEnumerable<char>? additionalCharactersForConfigurationPath = null,
63-
string? @namespace = null)
67+
string? @namespace = null,
68+
bool alwaysAddTrailingSlashToBasePath = true)
6469
{
6570
this.VaultAddress = vaultAddress;
6671
this.AuthMethod = authMethod;
@@ -69,6 +74,7 @@ public VaultOptions(
6974
this.OmitVaultKeyName = omitVaultKeyName;
7075
this.AdditionalCharactersForConfigurationPath = additionalCharactersForConfigurationPath ?? Array.Empty<char>();
7176
this.Namespace = @namespace;
77+
this.AlwaysAddTrailingSlashToBasePath = alwaysAddTrailingSlashToBasePath;
7278
}
7379

7480
/// <summary>
@@ -121,5 +127,12 @@ public VaultOptions(
121127
/// Gets Vault namespace.
122128
/// </summary>
123129
public string? Namespace { get; }
130+
131+
/// <summary>
132+
/// Gets the value indicating whether to always add a trailing slash to the base path.
133+
/// If it is true, the base path is considered to be a "folder" with nested keys, otherwise the base path is considered to be a key itself.
134+
/// It is true by default. Set to false if you don't have permissions to list keys in the base path.
135+
/// </summary>
136+
public bool AlwaysAddTrailingSlashToBasePath { get; }
124137
}
125138
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
<ItemGroup>
4242
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
4343
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
44-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
44+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.3" />
4545
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="17.2.32" />
46-
<PackageReference Include="VaultSharp" Version="1.7.0.4" />
46+
<PackageReference Include="System.Text.Json" Version="7.0.2" />
47+
<PackageReference Include="VaultSharp" Version="1.13.0.1" />
4748
<PackageReference Include="MinVer" Version="4.1.0" />
4849
</ItemGroup>
4950

0 commit comments

Comments
 (0)