2023-07-18 12:27:26 -05:00
|
|
|
package dynamodb
|
2023-03-28 12:20:09 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/config"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/service/dynamodb"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DBDriverParameters struct {
|
2023-10-30 15:06:04 -05:00
|
|
|
Endpoint, Region, RepoMetaTablename, RepoBlobsInfoTablename, ImageMetaTablename,
|
2023-07-07 11:27:10 -05:00
|
|
|
UserDataTablename, APIKeyTablename, VersionTablename string
|
2023-03-28 12:20:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetDynamoClient(params DBDriverParameters) (*dynamodb.Client, error) {
|
|
|
|
customResolver := aws.EndpointResolverWithOptionsFunc(
|
|
|
|
func(service, region string, options ...interface{}) (aws.Endpoint, error) {
|
|
|
|
return aws.Endpoint{
|
|
|
|
PartitionID: "aws",
|
|
|
|
URL: params.Endpoint,
|
|
|
|
SigningRegion: region,
|
|
|
|
}, nil
|
|
|
|
})
|
|
|
|
|
|
|
|
// Using the SDK's default configuration, loading additional config
|
|
|
|
// and credentials values from the environment variables, shared
|
|
|
|
// credentials, and shared configuration files
|
|
|
|
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(params.Region),
|
|
|
|
config.WithEndpointResolverWithOptions(customResolver))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return dynamodb.NewFromConfig(cfg), nil
|
|
|
|
}
|