Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's a good way to read config values and secrets? #713

Open
intrasight opened this issue Apr 3, 2023 · 3 comments
Open

What's a good way to read config values and secrets? #713

intrasight opened this issue Apr 3, 2023 · 3 comments

Comments

@intrasight
Copy link

I am planning on sharing some dotnet script samples on Github and need to put secrets in a file outside of the repo folder. What are my options?

@MostHated
Copy link

Since you can source standalone script files, I just made a separate .csx file that contains a class with member variables and I use it like a .env file.

@seesharper
Copy link
Collaborator

Would environment variables be an option?

@fakhrulhilal
Copy link

You can leverage other library like ConsoleAppFramework which supports many configuration provider in .NET ecosystem. Below is the example:

#r "nuget: ConsoleAppFramework, 4.2.4"
#nullable enable

using ConsoleAppFramework;
using Microsoft.Extensions.Configuration;

string IfSet(string? word, string @default = "") => !string.IsNullOrWhiteSpace(word) ? word : @default;
ConsoleApp.Create(Args.ToArray())
    .AddRootCommand("config", (IConfiguration config, string key) =>
        Console.WriteLine($"The config: {IfSet(config.GetValue<string>(key), "-none-")}"))
    .Run();

PS: by default, it inherits from Host.CreateDefaultBuilder(). As you might guess, it can read from environment variable, json, user secrets by default. You can add more provider if that's your prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants