### EtcdConfigurationProvider Constructor Example Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdConfigurationProvider.md Demonstrates how to initialize the EtcdConfigurationProvider with an IEtcdKeyValueClient, an optional key prefix, and a custom separator. ```csharp var clientFactory = new EtcdClientFactory(new EtcdSettings("http://localhost:2379")); var credentials = new Credentials("user", "pass"); var client = new EtcdKeyValueClient(clientFactory, credentials); var provider = new EtcdConfigurationProvider(client, "App", ":"); ``` -------------------------------- ### Development Configuration with Local etcd Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Example for setting up configuration with a local etcd instance during development. ```csharp var config = new ConfigurationBuilder() .AddEtcd( new Credentials("dev_user", "dev_password"), new EtcdSettings("http://localhost:2379")) .Build(); ``` -------------------------------- ### EtcdClientFactory Constructor Examples Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdClientFactory.md Demonstrates initializing EtcdClientFactory with explicit settings or by relying on environment variables. ```csharp var settings = new EtcdSettings("http://localhost:2379"); var factory = new EtcdClientFactory(settings); ``` ```csharp var factory = new EtcdClientFactory(); ``` -------------------------------- ### Install etcd-server and etcd-client on Ubuntu Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/README.md This command installs the etcd server and client tools on Ubuntu systems, which is a prerequisite for setting up a local etcd instance for testing. ```bash sudo apt-get install etcd-server etcd-client ``` -------------------------------- ### Use CredentialsSource Enum Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/types.md Example demonstrating how to instantiate Credentials with different sources for username and password, and how to access these sources. ```csharp var creds = new Credentials("user", "pass", CredentialsSource.Code, CredentialsSource.EnvironmentVariables); Console.WriteLine($"Username from: {creds.UserNameSource}"); // "Code" Console.WriteLine($"Password from: {creds.PasswordSource}"); // "EnvironmentVariables" ``` -------------------------------- ### Constructor-Based Initialization Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/INDEX.md Demonstrates direct initialization of etcd configuration components using their constructors, offering fine-grained control over setup. ```APIDOC ## Constructors ### `new Credentials(username, password, ...)` Directly creates `Credentials` instances by providing username, password, and other authentication details. ### `new EtcdSettings(connectionString)` Initializes `EtcdSettings` with a direct connection string. ### `new ConfigurationBasedEtcdSettings(config, ...)` Loads etcd settings from an existing `IConfiguration` object, typically from a JSON file. ### `new EtcdClientFactory(settings)` Creates an `EtcdClientFactory` instance, which is responsible for producing etcd clients based on provided settings. ### `new EtcdKeyValueClient(factory, credentials, ...)` Initializes an `EtcdKeyValueClient` using a factory, credentials, and other optional parameters. ### `new EtcdConfigurationSource(client, ...)` Creates an `EtcdConfigurationSource` which acts as a source for configuration values from etcd. ### `new EtcdConfigurationProvider(client, ...)` Instantiates an `EtcdConfigurationProvider` responsible for fetching and managing configuration values from etcd. ``` -------------------------------- ### Minimal Etcd Configuration Setup Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Demonstrates the basic steps to add Etcd configuration to a .NET application. Requires explicit creation of credentials and settings. ```csharp using Etcd.Microsoft.Extensions.Configuration; using Etcd.Microsoft.Extensions.Configuration.Auth; using Etcd.Microsoft.Extensions.Configuration.Settings; using Microsoft.Extensions.Configuration; // Create credentials var credentials = new Credentials("username", "password"); // Create settings var settings = new EtcdSettings("http://localhost:2379"); // Build configuration var config = new ConfigurationBuilder() .AddEtcd(credentials, settings) .Build(); // Use configuration var value = config["myKey"]; ``` -------------------------------- ### Initialize Terraform for etcd setup Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/README.md Run this command in the tests/terraform directory to initialize Terraform, downloading necessary providers and modules for setting up the etcd environment. ```bash terraform init ``` -------------------------------- ### HTTPS with System Certificate Store Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Demonstrates automatic SSL validation for HTTPS URLs and manual setup steps for system certificate store. ```csharp var settings = new EtcdSettings("https://etcd.example.com:2379"); // SSL validation automatic ``` -------------------------------- ### Integrate Etcd Configuration with IConfigurationBuilder Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBasedEtcdSettings.md Shows a complete example of loading etcd settings from a JSON file and then using them to add etcd as a configuration source to an IConfigurationBuilder. ```csharp // appsettings.json { "EtcdSettings": { "ConnectionString": "http://localhost:2379" } } // C# code var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var etcdSettings = new ConfigurationBasedEtcdSettings(jsonConfig); var credentials = new Credentials("user", "password"); var config = new ConfigurationBuilder() .AddEtcd(credentials, etcdSettings) .Build(); var value = config["MyKey"]; ``` -------------------------------- ### Configure Etcd Settings from Local JSON Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/README.md This example demonstrates how to load etcd connection settings from a local appsettings.json file. This is useful for managing sensitive information or environment-specific configurations. ```json { "EtcdSettings": { "ConnectionString": "https://serveraddress:2379" } } ``` ```csharp var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var config = new ConfigurationBuilder() .AddEtcd( new Credentials("MyEtcdUserName", "passw"), new ConfigurationBasedEtcdSettings(jsonConfig)) .Build(); var mySection = config.GetSection("MySection"); var myKeyValue = mySection["MyKeyName"]; ``` -------------------------------- ### Plan Terraform changes for etcd setup Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/README.md Execute this command to preview the infrastructure changes Terraform will make, such as creating etcd keys, without applying them. ```bash terraform plan ``` -------------------------------- ### HTTP Connection String Formats Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Provides examples of valid HTTP connection string formats for etcd. ```plaintext http://localhost:2379 http://etcd-server:2379 http://192.168.1.100:2379 ``` -------------------------------- ### AddEtcd with Credentials, Settings, and Multiple Key Prefixes Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBuilderExtensions.md This overload allows adding etcd configuration with credentials, custom etcd settings, multiple key prefixes, and a custom key prefix separator. It's useful for more complex setups or when connecting to a non-default etcd instance. ```csharp var credentials = new Credentials("username", "password"); var settings = new EtcdSettings("https://etcd-server:2379"); var config = new ConfigurationBuilder() .AddEtcd(credentials, settings, new List { "Common", "Production" }, "|") .Build(); // Multiple layers with custom separator "|" var value = config.GetSection("Production")["Database:Host"]; ``` -------------------------------- ### HTTPS Connection String Formats Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Provides examples of valid HTTPS connection string formats for etcd. ```plaintext https://etcd.example.com:2379 https://etcd-server.internal:2379 https://192.168.1.100:2379 ``` -------------------------------- ### Setting Up Watch Callbacks for Real-Time Events Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Configures a client to receive real-time notifications for changes in etcd. It sets up a callback to process incoming events and then loads initial keys, which also starts the watching process. ```csharp var factory = new EtcdClientFactory(settings); var client = new EtcdKeyValueClient(factory, credentials); client.WatchCallback += (events) => { foreach (var evt in events) { Console.WriteLine($"{evt.Type}: {evt.Key} = {evt.Value}"); } }; // Load keys (starts watching) var keys = client.GetAllKeys(); ``` -------------------------------- ### Get Credentials String Representation Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/Credentials.md Returns a string representation of the credentials. It prioritizes the 'Information' property if set, otherwise provides a default description. ```csharp var creds = new Credentials("user", "pass"); Console.WriteLine(creds.ToString()); // "etcd code based credentials" ``` -------------------------------- ### EtcdKeyValueClient.GetAllKeys Method Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdKeyValueClient.md Gets all keys and values accessible to the authenticated user. This method retrieves all keys the user has permission to read and automatically sets up watches if enabled. ```APIDOC ## GetAllKeys Method Gets all keys and values accessible to the authenticated user. ```csharp public IDictionary GetAllKeys() ``` #### Return Type `IDictionary` — Dictionary mapping key names to values. Values may be null. #### Description Retrieves all keys the user has permission to read by querying the user's roles and their associated permissions. If watch is enabled, it automatically sets up watches on all returned keys. #### Exceptions | Exception | Condition | |-----------|-----------| | InvalidOperationException | If client is not authenticated. | | EtcdException | If an RPC error occurs while reading keys. | #### Example ```csharp var client = new EtcdKeyValueClient(factory, credentials); var allKeys = client.GetAllKeys(); foreach (var kvp in allKeys) { Console.WriteLine($"{kvp.Key} = {kvp.Value}"); } ``` ``` -------------------------------- ### Subscribe to Watch Events Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/types.md Example of subscribing to watch events using the WatchHandler delegate. This code sets up a callback to process incoming etcd key change events. ```csharp var client = new EtcdKeyValueClient(factory, credentials); client.WatchCallback += (events) => { foreach (var evt in events) { Console.WriteLine($"{evt.Type}: {evt.Key}"); } }; ``` -------------------------------- ### ConnectionString Property Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdSettings.md Gets the etcd server connection string stored in the EtcdSettings instance. ```APIDOC ## ConnectionString Property ### Description Gets the etcd server connection string. ### Parameters None ### Example ```csharp var settings = new EtcdSettings("https://etcd-cluster.example.com:2379"); Console.WriteLine(settings.ConnectionString); // "https://etcd-cluster.example.com:2379" ``` ``` -------------------------------- ### Initialize EtcdSettings Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdSettings.md Demonstrates how to create a new instance of EtcdSettings with a connection string. ```csharp var settings = new EtcdSettings("http://localhost:2379"); ``` -------------------------------- ### Production Configuration with Environment Variables and JSON Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Demonstrates setting up production configuration by combining JSON appsettings and environment variables for credentials. ```json { "EtcdSettings": { "ConnectionString": "https://etcd.production.internal:2379" } } ``` ```csharp var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var credentials = Credentials.FromEnvironmentVariables(); var settings = new ConfigurationBasedEtcdSettings(jsonConfig); var config = new ConfigurationBuilder() .AddEtcd(credentials, settings, "Production") .Build(); ``` -------------------------------- ### EtcdKeyValueClient.Settings Property Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdKeyValueClient.md Gets the etcd connection settings. This property provides access to the connection settings derived from the underlying client factory. ```APIDOC ## Settings Property Gets the etcd connection settings. ```csharp public IEtcdSettings Settings { get; } ``` **Type:** `IEtcdSettings` **Description:** The connection settings from the underlying client factory. ### Example ```csharp var connectionString = client.Settings.ConnectionString; ``` ``` -------------------------------- ### Multi-Layered Configuration with JSON and Environment Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Shows how to layer configuration from JSON files and etcd, including environment-specific settings. ```csharp var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddJsonFile("appsettings.local.json", optional: true) .AddEtcd( Credentials.FromEnvironmentVariables(), new ConfigurationBasedEtcdSettings(jsonConfig), new[] { "Common", Environment.GetEnvironmentVariable("APP_ENV") ?? "Development" }) .Build(); ``` -------------------------------- ### Get EtcdConfigurationSource String Representation Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdConfigurationSource.md Returns a string representation of the EtcdConfigurationSource, useful for debugging. The format includes the key prefix and connection string. ```csharp var source = new EtcdConfigurationSource(client, "Production"); Console.WriteLine(source.ToString()); // Output: "Etcd - Production - http://localhost:2379" ``` -------------------------------- ### Initialize EtcdKeyValueClient Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdKeyValueClient.md Instantiate the EtcdKeyValueClient with a factory and credentials. Ensure the factory and credentials are not null. ```csharp var factory = new EtcdClientFactory(new EtcdSettings("http://localhost:2379")); var credentials = new Credentials("user", "password"); var client = new EtcdKeyValueClient(factory, credentials); ``` -------------------------------- ### Use EventType Enum Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/types.md Example showing how to create a WatchEvent and check its type. This is useful for reacting to specific etcd changes like updates. ```csharp var evt = new WatchEvent(EventType.Put, "config:version", "1.0"); if (evt.Type == EventType.Put) { Console.WriteLine($"Updated: {evt.Key} = {evt.Value}"); } ``` -------------------------------- ### Build Method Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdConfigurationSource.md Builds the IConfigurationProvider for this source, creating a new instance of EtcdConfigurationProvider. ```APIDOC ## Build Method ### Description Builds the `IConfigurationProvider` for this source. This method is called by the configuration framework to create a provider instance. Each call returns a new provider that uses the client and prefix settings from this source. ### Parameters #### Parameters - **builder** (IConfigurationBuilder) - Required - The configuration builder requesting the provider. ### Return Type `IConfigurationProvider` — A new instance of `EtcdConfigurationProvider`. ### Example ```csharp var source = new EtcdConfigurationSource(client, "Settings"); var configBuilder = new ConfigurationBuilder(); var provider = source.Build(configBuilder); // provider is an EtcdConfigurationProvider instance ``` ``` -------------------------------- ### Create Credentials Directly Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Demonstrates how to create Etcd credentials by directly instantiating the Credentials class with a username and password. ```csharp var creds = new Credentials("username", "password"); ``` -------------------------------- ### EtcdKeyValueClient.GetValue Method Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdKeyValueClient.md Gets a specific value by key. This method retrieves a single key-value pair, requiring the user to have permission to read the specified key. ```APIDOC ## GetValue Method Gets a specific value by key. ```csharp public string? GetValue(string key) ``` #### Parameters | Parameter | Type | Description | |-----------|------|-------------| | key | string | The key to retrieve. | #### Return Type `string?` — The value associated with the key, or null if not found. #### Description Retrieves a single key-value pair. Requires the user to have permission to read this key. #### Exceptions | Exception | Condition | |-----------|-----------| | InvalidOperationException | If client is not authenticated. | | EtcdException | If an RPC error occurs while reading the value. | #### Example ```csharp var value = client.GetValue("database:host"); Console.WriteLine(value); ``` ``` -------------------------------- ### Create Etcd Settings from Configuration Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Shows how to create Etcd settings from an existing .NET configuration object, typically loaded from a JSON file. ```csharp var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var settings = new ConfigurationBasedEtcdSettings(jsonConfig); // Reads from config["EtcdSettings"]["ConnectionString"] ``` -------------------------------- ### Retrieve Specific Value by Key Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdKeyValueClient.md Get the value associated with a specific key. Returns null if the key is not found. Requires read permission for the key. ```csharp var value = client.GetValue("database:host"); Console.WriteLine(value); ``` -------------------------------- ### Handle Watch Events Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdKeyValueClient.md Subscribe to the WatchCallback event to receive notifications about changes to watched keys. This example iterates through events and prints key-value pairs. ```csharp var client = new EtcdKeyValueClient(factory, credentials); client.WatchCallback += (events) => { foreach (var evt in events) { Console.WriteLine($"{evt.Type}: {evt.Key} = {evt.Value}"); } }; var keys = client.GetAllKeys(); ``` -------------------------------- ### Creating an EtcdClient Instance Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdClientFactory.md Illustrates creating a new EtcdClient instance using the EtcdClientFactory. The client is configured with appropriate SSL or insecure credentials based on the URL protocol. ```csharp var factory = new EtcdClientFactory(new EtcdSettings("http://localhost:2379")); var client = factory.Create(); // client is ready for key-value operations ``` -------------------------------- ### Programmatic Configuration with Code Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Use this method to provide connection string and credentials directly in code. It's suitable for development but not recommended for production due to credentials being in code. ```csharp var credentials = new Credentials("etcd_user", "etcd_password"); var settings = new EtcdSettings("http://etcd-server:2379"); var config = new ConfigurationBuilder() .AddEtcd(credentials, settings) .Build(); ``` -------------------------------- ### Initialize EtcdConfigurationSource Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdConfigurationSource.md Initializes a new EtcdConfigurationSource with an etcd client, an optional key prefix, and a key prefix separator. This is used to set up the configuration source before building the provider. ```csharp var clientFactory = new EtcdClientFactory(new EtcdSettings("http://localhost:2379")); var credentials = new Credentials("username", "password"); var client = new EtcdKeyValueClient(clientFactory, credentials); var source = new EtcdConfigurationSource(client, "MyApp", ":"); var provider = source.Build(builder); ``` -------------------------------- ### Provide Etcd Connection String Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/errors.md Demonstrates different ways to provide the Etcd connection string when adding Etcd configuration. This includes explicit settings, environment variables, and configuration files. ```csharp // Option 1: Explicit settings var settings = new EtcdSettings("http://localhost:2379"); builder.AddEtcd(credentials, settings); // Option 2: Environment variable Environment.SetEnvironmentVariable("ETCD_CLIENT_CONNECTION_STRING", "http://localhost:2379"); builder.AddEtcd(credentials); // Option 3: Configuration file // appsettings.json: { "EtcdSettings": { "ConnectionString": "http://localhost:2379" } } ``` -------------------------------- ### Using Key Prefix Filtering with Etcd Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Explains how to use key prefixes to scope Etcd configuration, loading only keys that match a specific prefix and mapping them to shorter configuration keys. ```csharp .AddEtcd(credentials, settings, "Production") // Only loads keys like "Production:*" // Accessed as config["Database:Host"] -> etcd key "Production:Database:Host" ``` -------------------------------- ### Create Credentials from Environment Variables Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Shows how to obtain Etcd credentials by reading ETCD_CLIENT_USER_NAME and ETCD_CLIENT_PASSWORD from environment variables. ```csharp var creds = Credentials.FromEnvironmentVariables(); // Reads: ETCD_CLIENT_USER_NAME, ETCD_CLIENT_PASSWORD ``` -------------------------------- ### EtcdApplicationEnvironment.ConnectionString Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdApplicationEnvironment.md Provides access to the etcd connection string. It supports getting the connection string, which will read from the environment variable if not already cached, and setting the connection string for the application's lifetime. Setting to null is not permitted. ```APIDOC ## EtcdApplicationEnvironment.ConnectionString ### Description Gets or sets the etcd connection string. This property caches the value after the first read from the environment variable. ### Method - Get: Reads the cached connection string or the value from the `ETCD_CLIENT_CONNECTION_STRING` environment variable. - Set: Caches the provided connection string for the application's lifetime. Throws `ArgumentNullException` if null is provided. ### Parameters #### Set Behavior - **value** (string?) - Required - The etcd server connection URL to set. ### Response #### Get Behavior - Returns the cached value if previously set. - Reads from `ETCD_CLIENT_CONNECTION_STRING` environment variable if cache is empty. - Returns null if not set and environment variable is not defined. ### Example (Get) ```csharp var connStr = EtcdApplicationEnvironment.ConnectionString; // "http://etcd-server:2379" ``` ### Example (Set) ```csharp EtcdApplicationEnvironment.ConnectionString = "https://etcd.example.com:2379"; // All subsequent accesses will return this value. ``` ``` -------------------------------- ### Layered Configuration with Prefixes Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Support multiple configuration layers (e.g., development, staging, production) by using key prefixes. This allows for distinct settings across different environments, with keys scoped by their respective prefixes. ```json { "EtcdSettings": { "ConnectionString": "https://etcd.example.com:2379" } } ``` ```csharp var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddJsonFile("appsettings.production.json", optional: true) .Build(); var credentials = Credentials.FromEnvironmentVariables(); var settings = new ConfigurationBasedEtcdSettings(jsonConfig); var config = new ConfigurationBuilder() .AddEtcd(credentials, settings, new[] { "Common", "Production" }) .Build(); // Keys are scoped by prefix: // "Common:Database:Host" and "Production:Database:Host" both loaded ``` -------------------------------- ### Use Key Prefixes for Multi-Tenancy Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Illustrates using key prefixes in etcd for multi-tenancy scenarios, allowing isolation of tenant-specific configurations. ```csharp var tenantId = GetCurrentTenant(); var config = new ConfigurationBuilder() .AddEtcd( credentials, settings, $"tenant:{tenantId}") .Build(); ``` -------------------------------- ### Get Etcd Connection String Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdApplicationEnvironment.md Retrieves the etcd connection string. The first access reads from the ETCD_CLIENT_CONNECTION_STRING environment variable if the value has not been previously set or cached. Returns null if not set and the environment variable is undefined. ```csharp // First access reads from environment variable var connStr = EtcdApplicationEnvironment.ConnectionString; // "http://etcd-server:2379" ``` -------------------------------- ### Multi-Environment Etcd Configuration Pattern Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Illustrates a pattern for managing configuration across multiple environments by layering JSON files and using Etcd with environment-specific key prefixes. ```csharp var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{environment}.json", optional: true) .AddEtcd( Credentials.FromEnvironmentVariables(), new ConfigurationBasedEtcdSettings(jsonConfig), environment) // Use environment as key prefix .Build(); ``` -------------------------------- ### Initialize Credentials Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/Credentials.md Initializes a new instance of the Credentials class with provided username and password. Defaults to using code as the source for both. ```csharp var creds = new Credentials("etcd_user", "my_password"); ``` -------------------------------- ### EtcdSettings Constructor Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdSettings.md Initializes a new instance of the EtcdSettings class with a specified etcd server connection string. ```APIDOC ## EtcdSettings Constructor ### Description Initializes a new instance of the `EtcdSettings` class with a specified etcd server connection string. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Example ```csharp var settings = new EtcdSettings("http://localhost:2379"); ``` ``` -------------------------------- ### Multi-Environment Configuration with JSON and etcd Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/INDEX.md Loads application settings from appsettings.json and then overlays etcd configuration, using environment variables for credentials and the environment name. ```csharp var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var config = new ConfigurationBuilder() .AddEtcd( Credentials.FromEnvironmentVariables(), new ConfigurationBasedEtcdSettings(jsonConfig), Environment.GetEnvironmentVariable("ENVIRONMENT")) .Build(); ``` -------------------------------- ### EtcdConfigurationProvider Constructor Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdConfigurationProvider.md Initializes a new instance of the EtcdConfigurationProvider class. It allows specifying an etcd client, an optional key prefix, and an optional separator for key hierarchy. ```APIDOC ## EtcdConfigurationProvider Constructor Initializes a new instance of the `EtcdConfigurationProvider` class. ```csharp public EtcdConfigurationProvider( IEtcdKeyValueClient client, string? keyPrefix = null, string? keyPrefixSeparator = DefaultKeyPrefixSeparator) ``` ### Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | client | IEtcdKeyValueClient | — | The etcd client for fetching and watching keys. | | keyPrefix | string? | null | Optional prefix to filter keys from etcd. | | keyPrefixSeparator | string? | `:` | Separator between prefix and key name. | ### Example ```csharp var clientFactory = new EtcdClientFactory(new EtcdSettings("http://localhost:2379")); var credentials = new Credentials("user", "pass"); var client = new EtcdKeyValueClient(clientFactory, credentials); var provider = new EtcdConfigurationProvider(client, "App", ":"); ``` ``` -------------------------------- ### Validate Configuration on Startup Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Provides a robust way to validate etcd configuration and credentials at application startup, exiting if validation fails. ```csharp try { var settings = new ConfigurationBasedEtcdSettings(jsonConfig); var credentials = Credentials.FromEnvironmentVariables(); var client = new EtcdKeyValueClient( new EtcdClientFactory(settings), credentials); client.Dispose(); Console.WriteLine("Configuration validated successfully"); } catch (EtcdException ex) { Console.WriteLine($"Configuration error: {ex.Message}"); Environment.Exit(1); } ``` -------------------------------- ### Use Key Prefixes for Etcd Configuration Loading Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Specify key prefixes to load only the necessary configuration keys, improving initial load and watch operation performance. ```csharp .AddEtcd( credentials, settings, new[] { "MyApp:Production" }) // Only loads keys under this prefix ``` -------------------------------- ### EtcdConfigurationSource Constructor Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdConfigurationSource.md Initializes a new instance of the EtcdConfigurationSource class with an etcd client, an optional key prefix, and an optional key prefix separator. ```APIDOC ## EtcdConfigurationSource Constructor ### Description Initializes a new instance of the `EtcdConfigurationSource` class. ### Parameters #### Parameters - **client** (IEtcdKeyValueClient) - Required - The etcd key-value client instance. - **keyPrefix** (string?) - Optional - Optional key prefix for filtering etcd keys. - **keyPrefixSeparator** (string) - Optional - Separator used between prefix and key name. Default: ":" ### Example ```csharp var clientFactory = new EtcdClientFactory(new EtcdSettings("http://localhost:2379")); var credentials = new Credentials("username", "password"); var client = new EtcdKeyValueClient(clientFactory, credentials); var source = new EtcdConfigurationSource(client, "MyApp", ":"); var provider = source.Build(builder); ``` ``` -------------------------------- ### AddEtcd with Credentials and Multiple Key Prefixes Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBuilderExtensions.md Use this overload to add etcd configuration with specified credentials and multiple key prefixes. This allows loading configuration from different layers within etcd. ```csharp var credentials = new Credentials("username", "password"); var config = new ConfigurationBuilder() .AddEtcd(credentials, new List { "Common", "Production" }) .Build(); // Keys from both "Common" and "Production" prefixes are loaded ``` -------------------------------- ### Create Credentials with Environment Variable Override Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/Credentials.md Creates credentials that prioritize values from environment variables but fall back to provided parameters if the environment variables are not set. If neither is available, an exception is raised. ```csharp // Prefers env var ETCD_CLIENT_USER_NAME but uses "fallback_user" if not set var creds = Credentials.WithOverrideFromEnvironmentVariables( "fallback_user", "fallback_pass"); ``` -------------------------------- ### Create Etcd Credentials Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/INDEX.md Instantiates Etcd credentials with a username and password. This is the first step in integrating Etcd configuration. ```csharp var credentials = new Credentials("user", "password"); ``` -------------------------------- ### EtcdKeyValueClient Constructor Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdKeyValueClient.md Initializes a new instance of the EtcdKeyValueClient class. This client handles authentication, retrieval of keys based on user permissions, and real-time watch notifications for configuration changes. ```APIDOC ## EtcdKeyValueClient Constructor Initializes a new instance of the `EtcdKeyValueClient` class. ```csharp public EtcdKeyValueClient( IEtcdClientFactory clientFactory, ICredentials credentials, bool enableWatch = true, bool unwatchOnDispose = true) ``` ### Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | clientFactory | IEtcdClientFactory | — | Factory for creating the underlying etcd client. | | credentials | ICredentials | — | User credentials for authentication. | | enableWatch | bool | true | Whether to enable watching keys for real-time updates. | | unwatchOnDispose | bool | true | Whether to unwatch all keys when the client is disposed. | ### Exceptions | Exception | Condition | |-----------|-----------| | ArgumentNullException | If clientFactory is null. | | ArgumentNullException | If credentials is null. | | EtcdException | If authentication fails. | ### Example ```csharp var factory = new EtcdClientFactory(new EtcdSettings("http://localhost:2379")); var credentials = new Credentials("user", "password"); var client = new EtcdKeyValueClient(factory, credentials); ``` ``` -------------------------------- ### Initialize ConfigurationBasedEtcdSettings Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBasedEtcdSettings.md Initializes ConfigurationBasedEtcdSettings with a configuration root and an optional section name. Reads connection string from the specified section. ```csharp var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var settings = new ConfigurationBasedEtcdSettings(config); // Reads from config["EtcdSettings"]["ConnectionString"] ``` -------------------------------- ### Development Configuration with Etcd Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/INDEX.md Sets up Etcd configuration for a development environment using specific credentials and a local Etcd endpoint. ```csharp var config = new ConfigurationBuilder() .AddEtcd( new Credentials("dev", "dev"), new EtcdSettings("http://localhost:2379")) .Build(); ``` -------------------------------- ### Etcd Configuration with JSON File Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Integrates Etcd configuration by reading settings from a JSON file (appsettings.json) and credentials from environment variables. ```json { "EtcdSettings": { "ConnectionString": "https://etcd.example.com:2379" } } ``` ```csharp var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var credentials = Credentials.FromEnvironmentVariables(); var settings = new ConfigurationBasedEtcdSettings(jsonConfig); var config = new ConfigurationBuilder() .AddEtcd(credentials, settings) .Build(); var value = config["myKey"]; ``` -------------------------------- ### Production Configuration with Etcd via Environment Variables Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/INDEX.md Configures Etcd integration for production by loading credentials from environment variables, utilizing the ETCD_CLIENT_CONNECTION_STRING. ```csharp var creds = Credentials.FromEnvironmentVariables(); var config = new ConfigurationBuilder() .AddEtcd(creds) // Uses ETCD_CLIENT_CONNECTION_STRING env var .Build(); ``` -------------------------------- ### Mixed Configuration (JSON and Environment Variables) Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Combine settings from a JSON file with credentials from environment variables. This approach offers a balance between file-based configuration and secure credential management. ```json { "EtcdSettings": { "ConnectionString": "https://etcd.example.com:2379" } } ``` ```bash export ETCD_CLIENT_PASSWORD=secure_password ``` ```csharp var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var credentials = new Credentials( "etcd_user", "default_password" ).WithOverrideFromEnvironmentVariables(); var settings = new ConfigurationBasedEtcdSettings(jsonConfig); var config = new ConfigurationBuilder() .AddEtcd(credentials, settings) .Build(); ``` -------------------------------- ### AddEtcd with Credentials, Settings, and Key Prefix Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBuilderExtensions.md Adds the etcd provider with connection settings and a single key prefix. This overload is useful when you need to explicitly define etcd connection settings, such as the server address, in addition to credentials and a key prefix. ```csharp public static IConfigurationBuilder AddEtcd( this IConfigurationBuilder configurationBuilder, ICredentials credentials, IEtcdSettings? settings, string? keyPrefix, string keyPrefixSeparator = EtcdConfigurationProvider.DefaultKeyPrefixSeparator, bool enableWatch = true, bool unwatchOnDispose = true) ``` ```csharp var credentials = new Credentials("username", "password"); var settings = new EtcdSettings("http://etcd-server:2379"); var config = new ConfigurationBuilder() .AddEtcd(credentials, settings, "Production") .Build(); ``` -------------------------------- ### Retrieve All Keys Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdKeyValueClient.md Fetch all keys and their values accessible to the authenticated user. This method automatically sets up watches if enabled. ```csharp var client = new EtcdKeyValueClient(factory, credentials); var allKeys = client.GetAllKeys(); foreach (var kvp in allKeys) { Console.WriteLine($"{kvp.Key} = {kvp.Value}"); } ``` -------------------------------- ### Add Etcd with Multiple Prefixes Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Load configuration keys from multiple specified prefixes. Values from later prefixes override those from earlier ones. ```csharp .AddEtcd(credentials, settings, new[] { "Common", "Production" }) // Loads keys from both prefixes // Production values override Common values ``` -------------------------------- ### Username from Code, Password from Environment Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Use this when the username is fixed and the password should be sourced from an environment variable. ```csharp var creds = Credentials.WithOverrideFromEnvironmentVariables( "app_user", "default_pass", passwordEnvironmentVariableName: "ETCD_PASSWORD"); ``` -------------------------------- ### AddEtcd with Credentials and Key Prefix Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBuilderExtensions.md Adds the etcd provider to the configuration builder with a single key prefix. Use this overload when you need to specify authentication credentials and a single prefix for your configuration keys. ```csharp public static IConfigurationBuilder AddEtcd( this IConfigurationBuilder configurationBuilder, ICredentials credentials, string? keyPrefix, string keyPrefixSeparator = EtcdConfigurationProvider.DefaultKeyPrefixSeparator, bool enableWatch = true, bool unwatchOnDispose = true) ``` ```csharp var credentials = new Credentials("username", "password"); var config = new ConfigurationBuilder() .AddEtcd(credentials, "MyApp") .Build(); var appSection = config.GetSection("MyApp"); var value = appSection["SettingName"]; ``` -------------------------------- ### Accessing Configuration Values Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Demonstrates various ways to access configuration values, including single keys, sections, using null-coalescing operators for fallbacks, and enumerating section children. ```csharp // Single value var host = config["Database:Host"]; // Section var dbSection = config.GetSection("Database"); var port = dbSection["Port"]; // With fallback var timeout = config["Timeout"] ?? "30"; // Enumerate all keys in section var dbKeys = dbSection.GetChildren(); foreach (var child in dbKeys) { Console.WriteLine($"{child.Key} = {child.Value}"); } ``` -------------------------------- ### Configure Etcd Settings Section Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/errors.md Shows how to add the missing EtcdSettings section to appsettings.json or specify a custom section name when initializing ConfigurationBasedEtcdSettings. ```csharp // Add missing section to appsettings.json { "EtcdSettings": { "ConnectionString": "http://localhost:2379" } } // Or specify custom section name var settings = new ConfigurationBasedEtcdSettings(config, "MyEtcdConfig"); ``` -------------------------------- ### Access Etcd Connection String Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EtcdSettings.md Shows how to retrieve the connection string from an EtcdSettings instance. ```csharp var settings = new EtcdSettings("https://etcd-cluster.example.com:2379"); Console.WriteLine(settings.ConnectionString); // "https://etcd-cluster.example.com:2379" ``` -------------------------------- ### Use Custom Section Name for Etcd Settings Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBasedEtcdSettings.md Demonstrates how to initialize ConfigurationBasedEtcdSettings using a custom configuration section name other than the default 'EtcdSettings'. ```csharp var settings = new ConfigurationBasedEtcdSettings(config, "MyEtcdConfig"); // Reads from config["MyEtcdConfig"]["ConnectionString"] ``` -------------------------------- ### AddEtcd (Overload 3: with credentials and multiple key prefixes) Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBuilderExtensions.md Adds the etcd provider to the configuration builder with multiple key prefixes, enabling the separation of configuration into different layers. ```APIDOC ## AddEtcd (Overload 3: with credentials and multiple key prefixes) ### Description Adds the etcd provider to the configuration builder with multiple key prefixes, enabling the separation of configuration into different layers. ### Method `AddEtcd` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **configurationBuilder** (IConfigurationBuilder) - Required - The configuration builder to extend. - **credentials** (ICredentials) - Required - Authentication credentials for etcd server. - **keyPrefixes** (IList) - Required - A list of key prefixes for different configuration layers. - **keyPrefixSeparator** (string) - Optional - Default value: ":". Separator between key prefix and the rest of the key. - **enableWatch** (bool) - Optional - Default value: `true`. Whether to enable automatic watching of etcd keys for changes. - **unwatchOnDispose** (bool) - Optional - Default value: `true`. Whether to unwatch keys when the provider is disposed. ### Return Type `IConfigurationBuilder` - The configuration builder for method chaining. ### Exceptions - **ArgumentNullException**: If configurationBuilder is null. ``` -------------------------------- ### Fixing ArgumentNullException in Etcd Configuration Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/errors.md Demonstrates how to correctly initialize EtcdSettings and EtcdClientFactory to avoid ArgumentNullException. ```csharp // Wrong IEtcdSettings settings = null; var factory = new EtcdClientFactory(settings); // throws ArgumentNullException // Correct var settings = new EtcdSettings("http://localhost:2379"); var factory = new EtcdClientFactory(settings); ``` -------------------------------- ### AddEtcd (Overload 1: with credentials and multiple key prefixes) Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBuilderExtensions.md Adds the etcd provider to the configuration builder with specified credentials and multiple key prefixes. This overload allows for loading configuration from different sections of etcd based on the provided prefixes. ```APIDOC ## AddEtcd (Overload 1: with credentials and multiple key prefixes) ### Description Adds the etcd provider to the configuration builder with credentials and multiple key prefixes. This overload allows for loading configuration from different sections of etcd based on the provided prefixes. ### Method `IConfigurationBuilder.AddEtcd` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **configurationBuilder** (IConfigurationBuilder) - Required - The configuration builder to extend. - **credentials** (ICredentials) - Required - Authentication credentials for etcd server. - **keyPrefixes** (IList) - Required - List of key prefixes for multiple configuration layers. - **keyPrefixSeparator** (string) - Optional - Separator between key prefix and the rest of the key. Defaults to ":". - **enableWatch** (bool) - Optional - Whether to enable automatic watching of etcd keys for changes. Defaults to `true`. - **unwatchOnDispose** (bool) - Optional - Whether to unwatch keys when the provider is disposed. Defaults to `true`. ### Request Example ```csharp var credentials = new Credentials("username", "password"); var config = new ConfigurationBuilder() .AddEtcd(credentials, new List { "Common", "Production" }) .Build(); // Keys from both "Common" and "Production" prefixes are loaded ``` ### Response #### Success Response `IConfigurationBuilder` - The configuration builder for method chaining. #### Response Example (Method chaining, no direct response body) #### Exceptions - **ArgumentNullException**: If configurationBuilder is null. ``` -------------------------------- ### Dependency Injection for Etcd Configuration (ASP.NET Core) Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Shows how to integrate Etcd configuration into an ASP.NET Core application's dependency injection system, reading settings from the application's existing configuration. ```csharp var builder = WebApplication.CreateBuilder(args); var credentials = Credentials.FromEnvironmentVariables(); var settings = new ConfigurationBasedEtcdSettings(builder.Configuration); builder.Configuration .AddEtcd(credentials, settings); var app = builder.Build(); ``` -------------------------------- ### Accessing Configuration Values Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/QuickStart.md Demonstrates how to access configuration values stored in Etcd using standard .NET configuration key syntax. ```csharp var value = config["Database:Connection:Host"]; // Looks for key "Database:Connection:Host" in etcd ``` -------------------------------- ### Provide Etcd Connection Settings Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Use explicit settings, environment variables, or JSON files to provide the Etcd connection string. ```csharp // Option 1: Explicit settings var settings = new EtcdSettings("http://localhost:2379"); builder.AddEtcd(credentials, settings); // Option 2: Environment variable Environment.SetEnvironmentVariable("ETCD_CLIENT_CONNECTION_STRING", "http://localhost:2379"); // Option 3: JSON file // Add EtcdSettings section to appsettings.json ``` -------------------------------- ### EnvironmentSettingsFactory.Create Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/EnvironmentSettingsFactory.md Creates an IEtcdSettings instance by reading the etcd connection string from the ETCD_CLIENT_CONNECTION_STRING environment variable. ```APIDOC ## Create (Static) Creates etcd settings from environment variables. ### Method Signature ```csharp public static IEtcdSettings Create() ``` ### Description This method creates an `IEtcdSettings` instance. It reads the etcd connection string from the `ETCD_CLIENT_CONNECTION_STRING` environment variable via `EtcdApplicationEnvironment.ConnectionString`. If the environment variable is not set, the connection string in the returned settings may be null. ### Return Type `IEtcdSettings` - An instance of `EtcdSettings` populated with connection details from the environment. ### Example ```csharp // Assuming ETCD_CLIENT_CONNECTION_STRING is set to "http://localhost:2379" var settings = EnvironmentSettingsFactory.Create(); Console.WriteLine(settings.ConnectionString); // Output: "http://localhost:2379" ``` ``` -------------------------------- ### Handling Etcd Configuration Errors Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/errors.md Demonstrates catching EtcdConfigurationException when loading settings from JSON and falling back to environment variables. ```csharp try { var jsonConfig = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); var settings = new ConfigurationBasedEtcdSettings(jsonConfig); } catch (EtcdConfigurationException ex) { Console.WriteLine("Invalid configuration: " + ex.Message); // Fall back to environment variables var settings = new EtcdSettings(EtcdApplicationEnvironment.ConnectionString); } ``` -------------------------------- ### Credentials Constructor Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/Credentials.md Initializes a new instance of the Credentials class with specified username, password, and optional source information. ```APIDOC ## Credentials Constructor ### Description Initializes a new instance of the `Credentials` class. ### Parameters | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | userName | string | — | The etcd user name. Must not be empty. | | password | string | — | The etcd password. Must not be empty. | | userNameSource | CredentialsSource | Code | Source of the username (Code or EnvironmentVariables). | | passwordSource | CredentialsSource | Code | Source of the password (Code or EnvironmentVariables). | | information | string? | null | Optional description of the credentials source. | ### Exceptions | Exception | Condition | |-----------|-----------| | ArgumentException | If userName is null or empty. | | ArgumentException | If password is null or empty. | ### Example ```csharp var creds = new Credentials("etcd_user", "my_password"); ``` ``` -------------------------------- ### Settings Factory Methods Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/INDEX.md Offers factory methods for creating `EtcdSettings` objects, allowing configuration to be loaded from various sources like JSON files or environment variables. ```APIDOC ## Factory Methods ### `EnvironmentSettingsFactory.Create()` Creates etcd settings by automatically detecting and loading configuration from the environment. ``` -------------------------------- ### AddEtcd with Credentials and Multiple Key Prefixes Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBuilderExtensions.md Adds the etcd provider with multiple key prefixes for different configuration layers. Use this overload when you need to load configuration from distinct sections of etcd, each identified by a unique prefix. ```csharp public static IConfigurationBuilder AddEtcd( this IConfigurationBuilder configurationBuilder, ICredentials credentials, IList keyPrefixes, string keyPrefixSeparator = EtcdConfigurationProvider.DefaultKeyPrefixSeparator, bool enableWatch = true, bool unwatchOnDispose = true) ``` -------------------------------- ### Create Credentials with Password Override from Environment Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/Credentials.md Use this method to hardcode the username while allowing the password to be set via an environment variable. The initial password parameter serves as a fallback if the environment variable is not found. ```csharp public static ICredentials WithOverrideFromEnvironmentVariables( string userName, string password, string passwordEnvironmentVariableName = DefaultPasswordEnvironmentVariableName) ``` ```csharp var creds = Credentials.WithOverrideFromEnvironmentVariables( "hardcoded_user", "default_pass"); // Uses "hardcoded_user" and password from ETCD_CLIENT_PASSWORD env var if available ``` -------------------------------- ### AddEtcd with Multiple Key Prefixes Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/configuration.md Configure etcd integration using a list of key prefixes to filter keys. This allows for loading configuration from multiple hierarchical scopes, such as common settings and environment-specific settings. ```csharp .AddEtcd(credentials, settings, new[] { "Common", "Production", "Local" }) ``` -------------------------------- ### AddEtcd (Overload 2: with credentials, settings, and key prefix string) Source: https://github.com/simplifynet/etcd.microsoft.extensions.configuration/blob/master/_autodocs/api-reference/ConfigurationBuilderExtensions.md Adds the etcd provider to the configuration builder with specific etcd settings and a single key prefix. This overload allows for more control over the etcd connection. ```APIDOC ## AddEtcd (Overload 2: with credentials, settings, and key prefix string) ### Description Adds the etcd provider to the configuration builder with specific etcd settings and a single key prefix. This overload allows for more control over the etcd connection. ### Method `AddEtcd` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **configurationBuilder** (IConfigurationBuilder) - Required - The configuration builder to extend. - **credentials** (ICredentials) - Required - Authentication credentials for etcd server. - **settings** (IEtcdSettings?) - Optional - Default value: `null`. Connection settings; if null, environment variables are used. - **keyPrefix** (string?) - Optional - Optional key prefix for filtering configuration keys. - **keyPrefixSeparator** (string) - Optional - Default value: ":". Separator between key prefix and the rest of the key. - **enableWatch** (bool) - Optional - Default value: `true`. Whether to enable automatic watching of etcd keys for changes. - **unwatchOnDispose** (bool) - Optional - Default value: `true`. Whether to unwatch keys when the provider is disposed. ### Return Type `IConfigurationBuilder` - The configuration builder for method chaining. ### Example ```csharp var credentials = new Credentials("username", "password"); var settings = new EtcdSettings("http://etcd-server:2379"); var config = new ConfigurationBuilder() .AddEtcd(credentials, settings, "Production") .Build(); ``` ### Exceptions - **ArgumentNullException**: If configurationBuilder is null. ```