Skip to content

OuterlimitsTech/olt-dotnet-configuration-infisical

Repository files navigation

.NET Configuration Extensions for Infisical

OLT.Extensions.Configuration.Infisical is a configuration provider for the .NET Core that allows developers to use Infisical as a configuration source in their applications.

Nuget

CI

Install the package:

dotnet add package OLT.Extensions.Configuration.Infisical

Simple

using OLT.Extensions.Configuration.Infisical;

var builder = WebApplication.CreateBuilder(args);

builder.Configuration
    .SetBasePath(builder.Environment.ContentRootPath)
    .AddInfisical(options, "e2bcf5b2-0000-0000-0000-000000009876", "---ClientSecret---", "47c230b4-0000-0000-0000-000000001234", "prod", false, TimeSpan.FromMinutes(10));

Load all secrets and all subfolders

using OLT.Extensions.Configuration.Infisical;

var options = new InfisicalOptions
{
    ClientId = "e2bcf5b2-0000-0000-0000-000000009876",
    ClientSecret = "---ClientSecret---",
    ProjectId = "47c230b4-0000-0000-0000-000000001234",
    Environment = "dev",
    Recursive = true
};

var builder = WebApplication.CreateBuilder(args);

builder.Configuration
    .SetBasePath(builder.Environment.ContentRootPath)
    .AddInfisical(options, false, TimeSpan.FromMinutes(10));

Using Paths

using OLT.Extensions.Configuration.Infisical;

var sharedOptions = new InfisicalOptions
{
    ClientId = "e2bcf5b2-0000-0000-0000-000000009876",
    ClientSecret = "---ClientSecret---",
    ProjectId = "47c230b4-0000-0000-0000-000000001234",
    Environment = "staging",
    Path = "/Shared"
    Recursive = true
};

builder.AddInfisical(sharedOptions, true, TimeSpan.FromMinutes(10));

var appOptions = new InfisicalOptions
{
    ClientId = "e2bcf5b2-0000-0000-0000-000000009876",
    ClientSecret = "---ClientSecret---",
    ProjectId = "47c230b4-0000-0000-0000-000000001234",
    Environment = "staging",
    Path = "/App1"
};

builder.Configuration
    .SetBasePath(builder.Environment.ContentRootPath)
    .AddInfisical(appOptions, false, TimeSpan.FromMinutes(10));

Build Infisical Options from Connection String

using OLT.Extensions.Configuration.Infisical;

var sharedOptions = new InfisicalOptions
{
    ClientId = "e2bcf5b2-0000-0000-0000-000000009876",
    ClientSecret = "---ClientSecret---",
    ProjectId = "47c230b4-0000-0000-0000-000000001234",
    Environment = "staging",
    Path = "/Shared"
    Recursive = true
};

builder.AddInfisical(sharedOptions, true, TimeSpan.FromMinutes(10));

var appOptions = new InfisicalOptions
{
    ClientId = "e2bcf5b2-0000-0000-0000-000000009876",
    ClientSecret = "---ClientSecret---",
    ProjectId = "47c230b4-0000-0000-0000-000000001234",
    Environment = "staging",
    Path = "/App1"
};

builder.Configuration
    .SetBasePath(builder.Environment.ContentRootPath)
    .AddInfisical(appOptions, false, TimeSpan.FromMinutes(10));

To use JSON namespacing, the keys of the secrets need to include ":" to represent nested keys and uncheck the Auto Capitalization under project settings.

image

image

About

Infisical .Net Core Configuration Provider

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages