{"id":24083440,"url":"https://github.com/a-postx/delobytes.extensions.configuration","last_synced_at":"2025-04-30T18:23:47.779Z","repository":{"id":58359408,"uuid":"467857254","full_name":"a-postx/Delobytes.Extensions.Configuration","owner":"a-postx","description":"Расширения конфигурации .Net для различных поставщиков параметров/секретов: Яндекс Локбокс, AWS AppConfig.","archived":false,"fork":false,"pushed_at":"2022-09-02T02:17:34.000Z","size":136,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-02T03:24:21.377Z","etag":null,"topics":["appconfig","aws","lockbox","yandex","yandex-cloud"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a-postx.png","metadata":{"files":{"readme":"README.en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-03-09T09:20:38.000Z","updated_at":"2024-04-28T13:04:39.000Z","dependencies_parsed_at":"2023-01-17T18:00:14.755Z","dependency_job_id":null,"html_url":"https://github.com/a-postx/Delobytes.Extensions.Configuration","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-postx%2FDelobytes.Extensions.Configuration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-postx%2FDelobytes.Extensions.Configuration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-postx%2FDelobytes.Extensions.Configuration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a-postx%2FDelobytes.Extensions.Configuration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a-postx","download_url":"https://codeload.github.com/a-postx/Delobytes.Extensions.Configuration/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233275519,"owners_count":18651573,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appconfig","aws","lockbox","yandex","yandex-cloud"],"created_at":"2025-01-09T23:56:44.505Z","updated_at":"2025-01-09T23:56:45.188Z","avatar_url":"https://github.com/a-postx.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Delobytes.Extensions.Configuration\n\n[RU](README.md), [EN](README.en.md)\n\n.Net configuration extensions for configuration/secrets providers. Package allows to use the following third-party provider clients as a configuration source for your .NetCore application (via Microsoft.Extensions.Configuration):\n- Yandex.Cloud Lockbox\n- AWS AppConfig\n\nGuide with usage details: https://habr.com/ru/post/660449/\n\n## Installation\n\nThe fastest way to add package to your app is via [NuGet](https://www.nuget.org/packages/Delobytes.Extensions.Configuration):\n\n    dotnet add package Delobytes.Extensions.Configuration\n\n## Usage\n\n### Yandex Cloud Lockbox\nAdd configuration/secrets from Yandex Cloud Lockbox service.\n\n1. Go to Yandex.Cloud console and create new service account with role \"lockbox.payloadViewer\" to get service account ID.\n\n2. Create new authorized key for this service account to get key identifier and private key.\n\n3. Go to Lockbox and add a secret. Use some allowed delimiter to create your hierarchy:\n\n```\nyc lockbox secret create --name Production --payload \"[{\"key\": \"MyPath-AppSecrets-SecretServiceToken\", \"text_value\": \"supersecret\"}]\"\n```\n\n![adding a secret to Lockbox](https://github.com/a-postx/Delobytes.Extensions.Configuration/blob/main/add-lockbox-secret-en.png)\n\n4. Once you created a secret you will get secret identifier. Add identifiers to the application settings (appsettings.json):\n\n```json\n{\n  \"YC\": {\n    \"ConfigurationSecretId\": \"e6q9a81c6m2bolpjaqjq\",\n    \"ServiceAccountId\": \"ajm2bdb9qq3mk4umqq23\",\n    \"ServiceAccountAuthorizedKeyId\": \"aje25rj0oacm5o10ib43\"\n  }\n}\n```\n\n5. Add confguration source using extension method. Get identifiers from the application settings file and private key using some environment variable. Configure all other settings as needed:  \n\n```csharp\nIHostBuilder hostBuilder = new HostBuilder().UseContentRoot(Directory.GetCurrentDirectory());\n\nhostBuilder.ConfigureAppConfiguration(configBuilder =\u003e\n{\n    IConfigurationRoot tempConfig = new ConfigurationBuilder()\n            .AddJsonFile(\"appsettings.json\")\n            .Build();\n\t\t\t\n    configBuilder.AddYandexCloudLockboxConfiguration(config =\u003e\n        {\n            config.PrivateKey = Environment.GetEnvironmentVariable(\"YC_PRIVATE_KEY\");\n            config.ServiceAccountId = tempConfig.GetValue\u003cstring\u003e(\"YC:ServiceAccountId\");\n            config.ServiceAccountAuthorizedKeyId = tempConfig.GetValue\u003cstring\u003e(\"YC:ServiceAccountAuthorizedKeyId\");\n            config.SecretId = tempConfig.GetValue\u003cstring\u003e(\"YC:ConfigurationSecretId\");\n            config.Path = \"MyPath\";\n            config.PathSeparator = '-';\n            config.Optional = false;\n            config.ReloadPeriod = TimeSpan.FromDays(7);\n            config.LoadTimeout = TimeSpan.FromSeconds(20);\n            config.OnLoadException += exceptionContext =\u003e\n            {\n                //log\n            };\n        });\n});\n```\n\n6. Now you can get your secrets using standard methods. For example, by creating an object representing your secrets and binding configuration to this object:\n\n```csharp\npublic class AppSecrets\n{\n    public string SecretServiceToken { get; set; }\n}\n```\n\n```csharp\n[Route(\"/\")]\n[ApiController]\npublic class HomeController : ControllerBase\n{\n    public HomeController(IConfiguration config)\n    {\n        _config = config;\n    }\n\n    private readonly IConfiguration _config;\n\n    [HttpGet(\"\")]\n    public IActionResult Get()\n    {\n        AppSecrets secrets = _config.GetSection(nameof(AppSecrets)).Get\u003cAppSecrets\u003e();\n\n        return Ok();\n    }\n}\n```\n\n### AWS App Config\nAdd configuration/secrets from AWS AppConfig service.\n\n1. Create AccessKey and SecretAccessKey in AWS for your service account and provide this data to your application (for example, using environment variables). Make sure that service account has rights to read AppConfig configurations.\n\n2. Add region where the configuration should be picked up from. You can add it using application settings (appsettings.json):\n\n```json\n{\n  \"AWS\": {\n    \"Region\": \"us-east-1\"\n  }\n}\n```\n\n3. Add application, environment and configuration profile with parameters in AppConfig.\n\n4. Add confguration source using extension method. Apply your RegionEndpoint and other settings:   \n\n```csharp\nIHostBuilder hostBuilder = new HostBuilder().UseContentRoot(Directory.GetCurrentDirectory());\n\nhostBuilder.ConfigureAppConfiguration((hostingContext, configBuilder) =\u003e\n{\n    IHostEnvironment hostEnvironment = hostingContext.HostingEnvironment;\n\tIConfigurationRoot tempConfig = new ConfigurationBuilder()\n            .AddJsonFile(\"appsettings.json\")\n            .Build();\n\n    configBuilder.AddAwsAppConfigConfiguration(config =\u003e\n        {\n            config.RegionEndpoint = RegionEndpoint.GetBySystemName(tempConfig.GetValue\u003cstring\u003e(\"AWS:Region\"));\n            config.EnvironmentName = hostEnvironment.EnvironmentName;\n            config.ApplicationName = hostEnvironment.ApplicationName;\n            config.ConfigurationName = $\"{hostEnvironment.EnvironmentName}-{hostEnvironment.ApplicationName}-profile\";\n            config.ClientId = $\"{hostEnvironment.ApplicationName}-{Node.Id}\";\n            config.Optional = false;\n            config.ReloadPeriod = TimeSpan.FromDays(1);\n            config.LoadTimeout = TimeSpan.FromSeconds(20);\n            config.OnLoadException += exceptionContext =\u003e\n            {\n                //log\n            };\n        });\n});\n```\n\n5. Now you can get your secrets using standard methods. For example, by creating an object representing your secrets and binding configuration to this object:\n\n```csharp\n[Route(\"/\")]\n[ApiController]\npublic class HomeController : ControllerBase\n{\n    public HomeController(IConfiguration config)\n    {\n        _config = config;\n    }\n\n    private readonly IConfiguration _config;\n\n    [HttpGet(\"\")]\n    public IActionResult Get()\n    {\n        AppSecrets secrets = _config.GetSection(nameof(AppSecrets)).Get\u003cAppSecrets\u003e();\n\n        return Ok();\n    }\n}\n```\n\n## License\n[MIT](https://github.com/a-postx/Delobytes.Extensions.Configuration/blob/main/LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-postx%2Fdelobytes.extensions.configuration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa-postx%2Fdelobytes.extensions.configuration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa-postx%2Fdelobytes.extensions.configuration/lists"}