-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
44d1b9f
commit 2e55f8d
Showing
20 changed files
with
599 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ | |
"SearchTimeout": 5000, | ||
"ManagementTimeout": 10000 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"ConnectorConfig": { | ||
"Instance": "DynamoDb", | ||
"AccessKey": "your-access-key-here", | ||
"SecretKey": "your-secret-key-here", | ||
"Region": "us-west-2", | ||
"ServiceUrl": "https://dynamodb.us-west-2.amazonaws.com", | ||
"UseHttp": false, | ||
"TableName": "MyTableName" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// (c) 2024 Francesco Del Re <[email protected]> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using Microsoft.Extensions.Configuration; | ||
using SharpConnector.Enums; | ||
using SharpConnector.Interfaces; | ||
using System.Linq; | ||
|
||
namespace SharpConnector.Configuration | ||
{ | ||
public class DynamoDbConfig : IConnectorConfig | ||
{ | ||
public string AccessKey { get; } | ||
public string SecretKey { get; } | ||
public string Region { get; } | ||
public string ServiceUrl { get; } | ||
public bool UseHttp { get; } | ||
public string TableName { get; } | ||
|
||
// Not used | ||
public string ConnectionString { get; private set; } | ||
public int DatabaseNumber { get; private set; } | ||
public string DatabaseName { get; private set; } | ||
public string CollectionName { get; private set; } | ||
public string Username { get; private set; } | ||
public string Password { get; private set; } | ||
public string BucketName { get; private set; } | ||
|
||
public DynamoDbConfig(IConfiguration section) | ||
{ | ||
var sectionChildren = section.GetChildren(); | ||
var configurationSections = sectionChildren.ToList(); | ||
|
||
var sectionChildrenAccessKey = configurationSections.FirstOrDefault(s => s.Key.ToLower() == AppConfigParameterEnums.accesskey.ToString()); | ||
AccessKey = sectionChildrenAccessKey?.Value; | ||
|
||
var sectionChildrenSecretKey = configurationSections.FirstOrDefault(s => s.Key.ToLower() == AppConfigParameterEnums.secretkey.ToString()); | ||
SecretKey = sectionChildrenSecretKey?.Value; | ||
|
||
var sectionChildrenRegion = configurationSections.FirstOrDefault(s => s.Key.ToLower() == AppConfigParameterEnums.region.ToString()); | ||
Region = sectionChildrenRegion?.Value; | ||
|
||
var sectionChildrenServiceUrl = configurationSections.FirstOrDefault(s => s.Key.ToLower() == AppConfigParameterEnums.serviceurl.ToString()); | ||
ServiceUrl = sectionChildrenServiceUrl?.Value; | ||
|
||
var sectionChildrenUseHttp = configurationSections.FirstOrDefault(s => s.Key.ToLower() == AppConfigParameterEnums.usehttp.ToString()); | ||
bool.TryParse(sectionChildrenUseHttp?.Value, out var useHttp); | ||
UseHttp = useHttp; | ||
|
||
var sectionChildrenTableName = configurationSections.FirstOrDefault(s => s.Key.ToLower() == AppConfigParameterEnums.tablename.ToString()); | ||
TableName = sectionChildrenTableName?.Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// (c) 2024 Francesco Del Re <[email protected]> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using Amazon.DynamoDBv2; | ||
using Amazon.Runtime; | ||
using SharpConnector.Configuration; | ||
using System; | ||
|
||
namespace SharpConnector.Connectors.DynamoDb | ||
{ | ||
internal class DynamoDbAccess : IDisposable | ||
{ | ||
private readonly Lazy<AmazonDynamoDBClient> _client; | ||
public AmazonDynamoDBClient GetClient() => _client.Value; | ||
|
||
/// <summary> | ||
/// Create a new DynamoDbAccess instance. | ||
/// </summary> | ||
/// <param name="connectorConfig">The DynamoDB configuration.</param> | ||
public DynamoDbAccess(DynamoDbConfig connectorConfig) | ||
{ | ||
var awsCredentials = new BasicAWSCredentials(connectorConfig.AccessKey, connectorConfig.SecretKey); | ||
var config = new AmazonDynamoDBConfig | ||
{ | ||
RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(connectorConfig.Region), | ||
ServiceURL = connectorConfig.ServiceUrl, | ||
UseHttp = connectorConfig.UseHttp | ||
}; | ||
|
||
_client = new Lazy<AmazonDynamoDBClient>(() => new AmazonDynamoDBClient(awsCredentials, config)); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (_client.IsValueCreated) | ||
{ | ||
_client.Value.Dispose(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.