-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathVault.cs
More file actions
37 lines (32 loc) · 1.52 KB
/
Copy pathVault.cs
File metadata and controls
37 lines (32 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using VaultSharp;
using VaultSharp.V1.AuthMethods;
using VaultSharp.V1.AuthMethods.AppRole;
using VaultSharp.V1.Commons;
using Microsoft.Extensions.Configuration;
namespace OneSTools.EventLog.Exporter.Core.ClickHouse
{
public class Vault
{
public string[] GetSecretWithAppRole(IConfiguration configuration)
{
string vaultAddr = configuration.GetValue("Vault:VaultAddr","");
string path = configuration.GetValue("Vault:Path","");
string mountPoint = configuration.GetValue("Vault:MountPoint","");
string roleId = configuration.GetValue("Vault:RoleId","");
string secretId = configuration.GetValue("Vault:SecreteId","");
string login = configuration.GetValue("Vault:Login","");
string password = configuration.GetValue("Vault:Password","");
IAuthMethodInfo authMethod = new AppRoleAuthMethodInfo(roleId, secretId.ToString());
var vaultClientSettings = new VaultClientSettings(vaultAddr, authMethod);
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
Secret<SecretData> kv2Secret = null;
kv2Secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(path:path , mountPoint: mountPoint).Result;
var arr = new string[2];
string username = kv2Secret.Data.Data[login].ToString();
string pass = kv2Secret.Data.Data[password].ToString();
arr[0] = username;
arr[1] = pass;
return arr;
}
}
}