mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-01 04:43:13 +00:00
24 lines
898 B
C#
24 lines
898 B
C#
|
|
using System.Text.Json;
|
||
|
|
using Amazon.SecretsManager;
|
||
|
|
using Amazon.SecretsManager.Model;
|
||
|
|
|
||
|
|
namespace ProposalSystem.Infrastructure.Services;
|
||
|
|
|
||
|
|
public static class SecretsManagerConnectionString
|
||
|
|
{
|
||
|
|
public static async Task<string> ResolveAsync(IAmazonSecretsManager client, string secretArn)
|
||
|
|
{
|
||
|
|
var response = await client.GetSecretValueAsync(new GetSecretValueRequest
|
||
|
|
{
|
||
|
|
SecretId = secretArn,
|
||
|
|
});
|
||
|
|
|
||
|
|
var secret = JsonSerializer.Deserialize<DbSecret>(response.SecretString)
|
||
|
|
?? throw new InvalidOperationException("Failed to deserialize DB secret");
|
||
|
|
|
||
|
|
return $"Host={secret.host};Port={secret.port};Database={secret.dbname};Username={secret.username};Password={secret.password};SSL Mode=Require;Trust Server Certificate=true";
|
||
|
|
}
|
||
|
|
|
||
|
|
private record DbSecret(string host, int port, string dbname, string username, string password);
|
||
|
|
}
|