42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using Azure.Security.KeyVault.Secrets;
|
|
using Core.Blueprint.DAL.Infrastructure.Contracts;
|
|
using Core.Blueprint.Domain.Entities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Core.Blueprint.DAL.Infrastructure.Repository
|
|
{
|
|
public class SecretRepository : ISecretRepository
|
|
{
|
|
private readonly SecretClient _client;
|
|
public SecretRepository(SecretClient client)
|
|
{
|
|
_client = client;
|
|
}
|
|
|
|
public async Task<Secret> GetSecret(string secretName, CancellationToken cancellationToken)
|
|
{
|
|
var ret = await _client.GetSecretAsync(secretName, cancellationToken: cancellationToken);
|
|
return new Secret() { Value = ret.Value?.Value };
|
|
}
|
|
|
|
public async Task SetSecret(string secretName, string secretValue, CancellationToken cancellationToken)
|
|
{
|
|
|
|
await _client.SetSecretAsync(new KeyVaultSecret(secretName, secretValue), cancellationToken: cancellationToken);
|
|
|
|
}
|
|
|
|
public async Task RemoveSecret(string secretName, CancellationToken cancellationToken)
|
|
{
|
|
|
|
await _client.StartDeleteSecretAsync(secretName, cancellationToken: cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
}
|