namespace IOL.GreatOffice.Api.Services; public class VaultService { private readonly HttpClient _client; public VaultService(HttpClient client, IConfiguration configuration) { var token = configuration.GetValue("VAULT_TOKEN"); var vaultUrl = configuration.GetValue("VAULT_URL"); if (token.IsNullOrWhiteSpace()) throw new ApplicationException("VAULT_TOKEN is empty"); if (vaultUrl.IsNullOrWhiteSpace()) throw new ApplicationException("VAULT_URL is empty"); client.DefaultRequestHeaders.Add("X-Vault-Token", token); client.BaseAddress = new Uri(vaultUrl); _client = client; } public async Task> GetSecretAsync(string path) { return await _client.GetFromJsonAsync>("/v1/kv/data/" + path); } public async Task RenewTokenAsync(string token) { var response = await _client.PostAsJsonAsync("v1/auth/token/renew", new { Token = token }); if (response.IsSuccessStatusCode) { return await response.Content.ReadFromJsonAsync(); } return default; } public class RenewTokenResponse { public Guid RequestId { get; set; } public string LeaseId { get; set; } public bool Renewable { get; set; } public long LeaseDuration { get; set; } public object Data { get; set; } public object WrapInfo { get; set; } public List Warnings { get; set; } public Auth Auth { get; set; } } public class Auth { public string ClientToken { get; set; } public string Accessor { get; set; } public List Policies { get; set; } public List TokenPolicies { get; set; } public object Metadata { get; set; } public long LeaseDuration { get; set; } public bool Renewable { get; set; } public string EntityId { get; set; } public string TokenType { get; set; } public bool Orphan { get; set; } public object MfaRequirement { get; set; } public long NumUses { get; set; } } public class GetSecretResponse { public VaultSecret Data { get; set; } } public class VaultSecret { public T Data { get; set; } public VaultSecretMetadata Metadata { get; set; } } public class VaultSecretMetadata { public DateTimeOffset CreatedTime { get; set; } public object CustomMetadata { get; set; } public string DeletionTime { get; set; } public bool Destroyed { get; set; } public long Version { get; set; } } }