Giter Site home page Giter Site logo

dotnet-libraries's Introduction

Libraries for dotnet based applications

Project Description
1 Configuration extension for Amazon Secrets Manager
projectnuget-packageusage
Amazon Secrets Manager service provides secure store for key/value pairs. Unlike parameter store, the data stored in Secrets Manager is encrypted by default.
You can use an extension to load config values in application's Configuration object. You must have saved config values in JSON format against keys in Secrets Manager.


Amazon Secrets Manager configuration extension

Usage:


1. Add secret in Amazon Secrets Manager, "PubSubInfra" as secret id and configuration key/value pairs as below.
key value
Kafka { "BootstrapServers": "localhost", "Producer": { "ClientId": "19", "StatisticsIntervalMs": 5000, "MessageTimeoutMs": 10000, "SocketTimeoutMs": 10000, "ApiVersionRequestTimeoutMs": 10000, "MetadataRequestTimeoutMs": 5000, "RequestTimeoutMs": 5000 }, "Consumer": { "GroupId": "49", "EnableAutoCommit": true, "StatisticsIntervalMs": 5000, "SessionTimeoutMs": 10000 } }
RabbitMQ { "Uri": "localhost", "UserName": "root@3", "Password": "SWAMI", "DispatchConsumersAsync": true }

2. Install Aksd.Extensions.Configuration.AmazonSecretsManager package. Add extesion in using following code in Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            config.AddAmazonSecretsManagerConfiguration("PubSubInfra");
        })
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });

3. Access configuration in code.

Startup.cs - Options pattern

services.Configure<KafkaConfig>(Configuration.GetSection("Kafka"));
services.Configure<RabbitMQConfig>(Configuration.GetSection("RabbitMQ"));
services.AddSingleton<IKafkaConnection>(sp =>
    {
        var kafkaConfigOption = sp.GetService<IOptions<KafkaConfig>>();
        var kafkaConfig = kafkaConfigOption.Value;
        return new DefaultKafkaConnection(
            bootstrapServers: kafkaConfig.BootstrapServers,
            clientId: kafkaConfig.Producer.ClientId,
            statisticsIntervalMs: 5000,
            messageTimeoutMs: 1000,
            socketTimeoutMs: 10000,
            apiVersionRequestTimeoutMs: 10000,
            metadataRequestTimeoutMs: 5000,
            requestTimeoutMs: 5000,
            groupId: "",
            enableAutoCommit: true,
            sessionTimeoutMs: 10000);
    });

services.AddSingleton<IRabbitMQConnection>(sp =>
    {
        var rabbitMQConfigOptions = sp.GetService<IOptions<RabbitMQConfig>>();
        var rabbitMQConfig = rabbitMQConfigOptions.Value;

        var connectionFactory = new ConnectionFactory()
        {
            Uri = new Uri(rabbitMQConfig.Uri),
            UserName = rabbitMQConfig.UserName,
            Password = rabbitMQConfig.Password,
            DispatchConsumersAsync = rabbitMQConfig.DispatchConsumersAsync,
        };

        var rabbitMQConnection = new DefaultRabbitMQConnection(connectionFactory);
        return rabbitMQConnection;
    });

dotnet-libraries's People

Contributors

iamdakshay avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.