mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
fix: remove usage of deprecated function aws.EndpointResolverWithOptionsFunc (#3700)
Signed-off-by: Andrei Aaron <andreifdaaron@gmail.com>
This commit is contained in:
@@ -90,25 +90,23 @@ func NewAWSImageTrustStore(region, endpoint string) (*ImageTrustStore, error) {
|
||||
}
|
||||
|
||||
func GetSecretsManagerClient(region, endpoint string) (*secretsmanager.Client, error) {
|
||||
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
|
||||
func(service, region string, options ...any) (aws.Endpoint, error) { //nolint: staticcheck
|
||||
return aws.Endpoint{ //nolint: staticcheck
|
||||
PartitionID: "aws",
|
||||
URL: 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(region),
|
||||
config.WithEndpointResolverWithOptions(customResolver)) //nolint: staticcheck
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return secretsmanager.NewFromConfig(cfg), nil
|
||||
// Create Secrets Manager client with custom base endpoint if provided
|
||||
var clientOptions []func(*secretsmanager.Options)
|
||||
if endpoint != "" {
|
||||
clientOptions = append(clientOptions, func(o *secretsmanager.Options) {
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
})
|
||||
}
|
||||
|
||||
return secretsmanager.NewFromConfig(cfg, clientOptions...), nil
|
||||
}
|
||||
|
||||
func GetSecretsManagerRetrieval(region, endpoint string) *secretcache.Cache {
|
||||
|
||||
@@ -39,22 +39,13 @@ func TestWrapperErrors(t *testing.T) {
|
||||
Convey("Create table errors", t, func() {
|
||||
badEndpoint := endpoint + "1"
|
||||
|
||||
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
|
||||
func(service, region string, options ...any) (aws.Endpoint, error) {
|
||||
return aws.Endpoint{ //nolint: staticcheck
|
||||
PartitionID: "aws",
|
||||
URL: badEndpoint,
|
||||
SigningRegion: region,
|
||||
}, nil
|
||||
},
|
||||
)
|
||||
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region),
|
||||
config.WithEndpointResolverWithOptions(customResolver)) //nolint: staticcheck
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
dynamoWrapper := DynamoDB{
|
||||
Client: dynamodb.NewFromConfig(cfg),
|
||||
Client: dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(badEndpoint)
|
||||
}),
|
||||
RepoMetaTablename: repoMetaTablename,
|
||||
VersionTablename: versionTablename,
|
||||
UserDataTablename: userDataTablename,
|
||||
@@ -75,22 +66,13 @@ func TestWrapperErrors(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Delete table errors", t, func() {
|
||||
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
|
||||
func(service, region string, options ...any) (aws.Endpoint, error) {
|
||||
return aws.Endpoint{ //nolint: staticcheck
|
||||
PartitionID: "aws",
|
||||
URL: endpoint,
|
||||
SigningRegion: region,
|
||||
}, nil
|
||||
},
|
||||
)
|
||||
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region),
|
||||
config.WithEndpointResolverWithOptions(customResolver)) //nolint: staticcheck
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
dynamoWrapper := DynamoDB{
|
||||
Client: dynamodb.NewFromConfig(cfg),
|
||||
Client: dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
}),
|
||||
RepoMetaTablename: repoMetaTablename,
|
||||
VersionTablename: versionTablename,
|
||||
UserDataTablename: userDataTablename,
|
||||
@@ -104,18 +86,7 @@ func TestWrapperErrors(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Create version table behavior", t, func() {
|
||||
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
|
||||
func(service, region string, options ...any) (aws.Endpoint, error) {
|
||||
return aws.Endpoint{ //nolint: staticcheck
|
||||
PartitionID: "aws",
|
||||
URL: endpoint,
|
||||
SigningRegion: region,
|
||||
}, nil
|
||||
},
|
||||
)
|
||||
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region),
|
||||
config.WithEndpointResolverWithOptions(customResolver)) //nolint: staticcheck
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("createVersionTable sets version for new table", func() {
|
||||
@@ -124,7 +95,9 @@ func TestWrapperErrors(t *testing.T) {
|
||||
versionTablename := "Version" + uuid.String()
|
||||
|
||||
dynamoWrapper := DynamoDB{
|
||||
Client: dynamodb.NewFromConfig(cfg),
|
||||
Client: dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
}),
|
||||
VersionTablename: versionTablename,
|
||||
Patches: version.GetDynamoDBPatches(),
|
||||
Log: log.NewTestLogger(),
|
||||
@@ -149,7 +122,9 @@ func TestWrapperErrors(t *testing.T) {
|
||||
versionTablename := "Version" + uuid.String()
|
||||
|
||||
dynamoWrapper := DynamoDB{
|
||||
Client: dynamodb.NewFromConfig(cfg),
|
||||
Client: dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
}),
|
||||
VersionTablename: versionTablename,
|
||||
Patches: version.GetDynamoDBPatches(),
|
||||
Log: log.NewTestLogger(),
|
||||
@@ -178,7 +153,9 @@ func TestWrapperErrors(t *testing.T) {
|
||||
versionTablename := "Version" + uuid.String()
|
||||
|
||||
dynamoWrapper := DynamoDB{
|
||||
Client: dynamodb.NewFromConfig(cfg),
|
||||
Client: dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
}),
|
||||
VersionTablename: versionTablename,
|
||||
Patches: version.GetDynamoDBPatches(),
|
||||
Log: log.NewTestLogger(),
|
||||
@@ -216,7 +193,9 @@ func TestWrapperErrors(t *testing.T) {
|
||||
versionTablename := "Version" + uuid.String()
|
||||
|
||||
dynamoWrapper := DynamoDB{
|
||||
Client: dynamodb.NewFromConfig(cfg),
|
||||
Client: dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(endpoint)
|
||||
}),
|
||||
VersionTablename: versionTablename,
|
||||
Patches: version.GetDynamoDBPatches(),
|
||||
Log: log.NewTestLogger(),
|
||||
|
||||
@@ -105,21 +105,14 @@ func TestIterator(t *testing.T) {
|
||||
|
||||
func TestIteratorErrors(t *testing.T) {
|
||||
Convey("errors", t, func() {
|
||||
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
|
||||
func(service, region string, options ...any) (aws.Endpoint, error) {
|
||||
return aws.Endpoint{ //nolint: staticcheck
|
||||
PartitionID: "aws",
|
||||
URL: "endpoint",
|
||||
SigningRegion: region,
|
||||
}, nil
|
||||
})
|
||||
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion("region"),
|
||||
config.WithEndpointResolverWithOptions(customResolver)) //nolint: staticcheck
|
||||
badEndpoint := "endpoint"
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion("region"))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
repoMetaAttributeIterator := mdynamodb.NewBaseDynamoAttributesIterator(
|
||||
dynamodb.NewFromConfig(cfg),
|
||||
dynamodb.NewFromConfig(cfg, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(badEndpoint)
|
||||
}),
|
||||
"RepoMetadataTable",
|
||||
"RepoMeta",
|
||||
1,
|
||||
|
||||
@@ -14,23 +14,21 @@ type DBDriverParameters struct {
|
||||
}
|
||||
|
||||
func GetDynamoClient(params DBDriverParameters) (*dynamodb.Client, error) {
|
||||
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
|
||||
func(service, region string, options ...any) (aws.Endpoint, error) {
|
||||
return aws.Endpoint{ //nolint: staticcheck
|
||||
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)) //nolint: staticcheck
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(params.Region))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return dynamodb.NewFromConfig(cfg), nil
|
||||
// Create DynamoDB client with custom base endpoint if provided
|
||||
var clientOptions []func(*dynamodb.Options)
|
||||
if params.Endpoint != "" {
|
||||
clientOptions = append(clientOptions, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(params.Endpoint)
|
||||
})
|
||||
}
|
||||
|
||||
return dynamodb.NewFromConfig(cfg, clientOptions...), nil
|
||||
}
|
||||
|
||||
Vendored
+14
-13
@@ -71,28 +71,29 @@ func NewDynamoDBCache(parameters any, log zlog.Logger) (*DynamoDBDriver, error)
|
||||
return nil, zerr.ErrTypeAssertionFailed
|
||||
}
|
||||
|
||||
// custom endpoint resolver to point to localhost
|
||||
customResolver := aws.EndpointResolverWithOptionsFunc( //nolint: staticcheck
|
||||
func(service, region string, options ...any) (aws.Endpoint, error) {
|
||||
return aws.Endpoint{ //nolint: staticcheck
|
||||
PartitionID: "aws",
|
||||
URL: properParameters.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(properParameters.Region),
|
||||
config.WithEndpointResolverWithOptions(customResolver)) //nolint: staticcheck
|
||||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(properParameters.Region))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to load AWS SDK config for dynamodb")
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
driver := &DynamoDBDriver{client: dynamodb.NewFromConfig(cfg), tableName: properParameters.TableName, log: log}
|
||||
// Create DynamoDB client with custom base endpoint if provided
|
||||
var clientOptions []func(*dynamodb.Options)
|
||||
if properParameters.Endpoint != "" {
|
||||
clientOptions = append(clientOptions, func(o *dynamodb.Options) {
|
||||
o.BaseEndpoint = aws.String(properParameters.Endpoint)
|
||||
})
|
||||
}
|
||||
|
||||
driver := &DynamoDBDriver{
|
||||
client: dynamodb.NewFromConfig(cfg, clientOptions...),
|
||||
tableName: properParameters.TableName,
|
||||
log: log,
|
||||
}
|
||||
|
||||
err = driver.NewTable(driver.tableName)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user