StackSpot.Secrets
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package StackSpot.Secrets --version 1.0.0
NuGet\Install-Package StackSpot.Secrets -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StackSpot.Secrets" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StackSpot.Secrets --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: StackSpot.Secrets, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StackSpot.Secrets as a Cake Addin #addin nuget:?package=StackSpot.Secrets&version=1.0.0 // Install StackSpot.Secrets as a Cake Tool #tool nuget:?package=StackSpot.Secrets&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
StackSpot secrets
Este componente foi projetado para padronizar a comunicação com a possibilidade de cacheamento de segredos da AWS Secrets Manager para aplicações .NET.
Versões suportadas
- net5.0
- net6.0
Uso
1. Adicione o pacote NuGet StackSpot.Secrets
ao seu projeto.
dotnet add package StackSpot.Secrets
2. Configure as variáveis.
- CacheItemTTL - TTL do cache em milliseconds - Valor default: 3600000.
- MaxCacheSize - Quantidade máxima de items a serem cacheados antes de executar o LRU - Valor default: 1024.
- VersionStage - Versão que o cache irá requisitar ao recuperar o segredo do Secrets Manager - Valor default: AWSCURRENT.
- RegionEndpoint - Endpoint regional que será utilizado para requisitar o Secrets Manager - Campo Obrigatório.
Você pode sobrescrever a configuração padrão do cache adicionando a seção SecretsCache
em seu appsettings.json
.
"SecretsCache": {
"CacheItemTTL": 3700000,
"MaxCacheSize": 1024,
"VersionStage": "AWSCURRENT",
"RegionEndpoint": "sa-east-1"
}
3. Adicione ao seu IServiceCollection
via services.AddSecretsManager()
no Startup
da aplicação ou Program
tendo como parametro de entrada IConfiguration
e IWebHostEnvironment
.
services.AddSecretsManager(Configuration, Env);
Implementação
[ApiController]
[Route("[controller]")]
public class SampleController : ControllerBase
{
private readonly ISecretsManagerCache _cache;
public SampleController(ISecretsManagerCache cache)
{
_cache = cache;
}
[HttpGet]
public async Task<IActionResult> Get()
{
var someEntity = await _cache.GetSecretString("Poc");
return Ok(someEntity);
}
}
Sobrecargas disponíveis.
- Em recuperações bem sucedidas, o cache irá retornar uma cópia cacheada do seu segredo.
var secret = await ISecretsRepository.GetSecret<T>(secretKey);
- É possível utilizar a interface ISecretsRepository com tratamento de erros e API para deserializar o seu segredo.
Exceptions
- SecretsRepositoryException, acontece quando:
- Secret não encontrada, retorna a mensagem
No secret was found for key {secretKey}.
- Erro inesperado, retorna a mensagem
An error occurred while getting the secret for key {secretKey}.
, contendo a exception do erro.
- Secret não encontrada, retorna a mensagem
4. Ambiente local
- Esta etapa não é obrigatória.
- Variável
ASPNETCORE_ENVIRONMENT
deverá ter o valor igual àDevelopment
. - Você pode customizar o endpoint do localstack adicionando a chave
LOCALSTACK_CUSTOM_SERVICE_URL
. O valor padrão éhttp://localhost:4566
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- AWSSDK.SecretsManager (>= 3.7.1.65)
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Hosting (>= 6.0.0)
-
net6.0
- AWSSDK.SecretsManager (>= 3.7.1.65)
- Microsoft.Extensions.Caching.Memory (>= 6.0.0)
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Hosting (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.