public static void AddDynamoDbObjects(this IServiceCollection services, IConfiguration configuration) { var accessKey = configuration.GetValue <string>("DynamoDB:AccessKey"); var securityKey = configuration.GetValue <string>("DynamoDB:SecurityKey"); var credentials = new BasicAWSCredentials(accessKey, securityKey); var regionEndpoint = RegionEndpoint.GetBySystemName(configuration.GetValue <string>("DynamoDB:Region")); var client = new AmazonDynamoDBClient(credentials, regionEndpoint); var dynamoDbOptions = new DynamoDBOptions(); ConfigurationBinder.Bind(configuration.GetSection("DynamoDbTables"), dynamoDbOptions); services.AddScoped <IDynamoDbContext <CustomerModel> >(provider => new DynamoDbContext <CustomerModel>(client, dynamoDbOptions.Customer)); }
public static BeatPulseContext AddDynamoDb(this BeatPulseContext context, Action <DynamoDBOptions> setupOptions, string name = nameof(DynamoDbLiveness), string defaultPath = "dynamodb") { var options = new DynamoDBOptions(); setupOptions(options); return(context.AddLiveness(name, setup => { setup.UsePath(defaultPath); setup.UseFactory(sp => new DynamoDbLiveness(options, sp.GetService <ILogger <DynamoDbLiveness> >())); })); }
/// <summary> /// Add a health check for AWS DynamoDb database. /// </summary> /// <param name="builder">The <see cref="IHealthChecksBuilder"/>.</param> /// <param name="setup">The action to configure the DynamoDb connection parameters.</param> /// <param name="name">The health check name. Optional. If <c>null</c> the type name 'dynamodb' will be used for the name.</param> /// <param name="failureStatus"> /// The <see cref="HealthStatus"/> that should be reported when the health check fails. Optional. If <c>null</c> then /// the default status of <see cref="HealthStatus.Unhealthy"/> will be reported. /// </param> /// <param name="tags">A list of tags that can be used to filter sets of health checks. Optional.</param> /// <returns>The <see cref="IHealthChecksBuilder"/>.</returns></param> public static IHealthChecksBuilder AddDynamoDb(this IHealthChecksBuilder builder, Action <DynamoDBOptions> setup, string name = default, HealthStatus?failureStatus = default, IEnumerable <string> tags = default) { var options = new DynamoDBOptions(); setup?.Invoke(options); return(builder.Add(new HealthCheckRegistration( name ?? NAME, sp => new DynamoDbHealthCheck(options), failureStatus, tags))); }
/// <summary> /// Add DynamoDB Operational Store. /// </summary> /// <param name="builder"></param> /// <param name="optionsBuilder">DynamoDB Operational Store Options builder</param> /// <returns></returns> public static IIdentityServerBuilder AddOperationalStore(this IIdentityServerBuilder builder, Action <DynamoDBOptions> optionsBuilder = null) { var options = new DynamoDBOptions(); optionsBuilder?.Invoke(options); if (options.DynamoDBContextConfig is null) { options.DynamoDBContextConfig = new Amazon.DynamoDBv2.DataModel.DynamoDBContextConfig(); } builder.Services.AddSingleton <DynamoDBOptions>(options); builder.Services.AddTransient <IPersistedGrantStore, PersistedGrantStore>(); return(builder); }
public static IIdentityServerBuilder AddOperationalDynamoDBStore( this IIdentityServerBuilder builder, IConfiguration configuration, string dynamoDBOptionKey) { var dynamoDBOption = new DynamoDBOptions(); var section = configuration.GetSection(dynamoDBOptionKey); section.Bind(dynamoDBOption); builder.Services.Configure <DynamoDBOptions>(section); builder.Services.AddOperationalDynamoDBStore(configuration, dynamoDBOption); return(builder); }
public TestBase() { var services = new ServiceCollection(); var configurationBuilder = new ConfigurationBuilder(); configurationBuilder.AddJsonFile("settings.json", optional: false); var configurationRoot = configurationBuilder.Build(); services.AddSingleton((IConfiguration)configurationRoot); var dynamoDBOption = new DynamoDBOptions(); var section = configurationRoot.GetSection("DynamoDB"); section.Bind(dynamoDBOption); services.Configure <DynamoDBOptions>(section); services.AddOperationalDynamoDBStore(configurationRoot, dynamoDBOption); ServiceProvider = services.BuildServiceProvider(); PersistedGrantStore = ServiceProvider.GetService <IPersistedGrantStore>(); }
public static IServiceCollection AddOperationalDynamoDBStore(this IServiceCollection services, IConfiguration configuration, DynamoDBOptions options) { var awsOptions = configuration.GetAWSOptions(); awsOptions.DefaultClientConfig.ServiceURL = options.ServiceURL; services.AddDefaultAWSOptions(awsOptions); services.AddAWSService <IAmazonDynamoDB>(awsOptions); services.AddSingleton(x => new DynamoDBContextConfig { TableNamePrefix = options.TablePrefix }); services.AddTransient(x => { var client = x.GetService <IAmazonDynamoDB>(); var config = x.GetService <DynamoDBContextConfig>(); return(new DynamoDBContext(client, config)); }); services.AddTransient <IPersistedGrantStore, PersistedGrantStore>(); services.AddTransient <PersistedGrantTableBuilder>(); return(services); }
public async Task CreateTable(DynamoDBOptions options) { var tableName = options.PersistedGrantTableName; var tables = await _amazonDynamoDbClient.ListTablesAsync(); if (!tables.TableNames.Contains(tableName)) { var createRequest = new CreateTableRequest { TableName = tableName, AttributeDefinitions = new List <AttributeDefinition> { new AttributeDefinition { AttributeName = "Key", AttributeType = "S" }, new AttributeDefinition { AttributeName = "SubjectId", AttributeType = "S" }, new AttributeDefinition { AttributeName = "CreationTime", AttributeType = "S" }, new AttributeDefinition { AttributeName = "TTL", AttributeType = "N" } }, KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "Key", KeyType = "HASH" } }, GlobalSecondaryIndexes = new List <GlobalSecondaryIndex>() { new GlobalSecondaryIndex() { IndexName = "SubjectIdAndCreationTimeIndex", KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "SubjectId", KeyType = "HASH" }, new KeySchemaElement { AttributeName = "CreationTime", KeyType = "RANGE" } }, Projection = new Projection { ProjectionType = ProjectionType.KEYS_ONLY }, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 5, WriteCapacityUnits = 5 } } }, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 10 }, }; await _amazonDynamoDbClient.CreateTableAsync(createRequest); } }
public PersistedGrantStore(IAmazonDynamoDB dynamoDBClient, DynamoDBOptions dynamoDBOptions, ILogger <PersistedGrantStore> logger) { this.dynamoDBClient = dynamoDBClient ?? throw new ArgumentNullException(nameof(dynamoDBClient)); this.dynamoDBOptions = dynamoDBOptions ?? throw new ArgumentNullException(nameof(dynamoDBOptions)); this.logger = logger; }