Skip to content

Commit aa3fd2d

Browse files
committed
Support the .vault-token file
1 parent 0c24de3 commit aa3fd2d

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/Configuration/Vault/src/ConfigurationManagerExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace ClickView.GoodStuff.Configuration.Vault;
22

3+
using System;
34
using Microsoft.Extensions.Configuration;
45

56
public static class ConfigurationManagerExtensions
@@ -16,6 +17,8 @@ public static IConfigurationManager AddVault(this IConfigurationManager configur
1617
{
1718
ArgumentNullException.ThrowIfNull(configurationManager);
1819

20+
configurationManager.Sources.Insert(0, new VaultTokenFileConfigurationSource());
21+
1922
var options = GetOptions(configurationManager);
2023

2124
configure?.Invoke(options);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace ClickView.GoodStuff.Configuration.Vault;
2+
3+
using Microsoft.Extensions.Configuration;
4+
5+
internal class VaultTokenFileConfigurationProvider : ConfigurationProvider
6+
{
7+
public override void Load()
8+
{
9+
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".vault-token");
10+
11+
if (!File.Exists(path))
12+
return;
13+
14+
var token = File.ReadAllText(path).Trim();
15+
16+
if (!string.IsNullOrEmpty(token))
17+
Data["Vault:Token"] = token;
18+
}
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace ClickView.GoodStuff.Configuration.Vault;
2+
3+
using Microsoft.Extensions.Configuration;
4+
5+
internal class VaultTokenFileConfigurationSource : IConfigurationSource
6+
{
7+
public IConfigurationProvider Build(IConfigurationBuilder builder) => new VaultTokenFileConfigurationProvider();
8+
}

0 commit comments

Comments
 (0)