Skip to content

Commit

Permalink
fix(aws*fs): Use BaseEndpoint for overriding endpoints (#686)
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <[email protected]>
  • Loading branch information
hairyhenderson authored Jun 8, 2024
1 parent 40d056f commit 14df5fa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
11 changes: 10 additions & 1 deletion awssmfs/awssm.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@ func (f *awssmFS) getClient(ctx context.Context) (SecretsManagerClient, error) {
return nil, err
}

f.smclient = secretsmanager.NewFromConfig(cfg)
optFns := []func(*secretsmanager.Options){}

// setting a host in the URL is only intended for test purposes
if f.base.Host != "" {
optFns = append(optFns, func(o *secretsmanager.Options) {
o.BaseEndpoint = aws.String("http://" + f.base.Host)
})
}

f.smclient = secretsmanager.NewFromConfig(cfg, optFns...)

return f.smclient, nil
}
Expand Down
24 changes: 10 additions & 14 deletions awssmpfs/awssmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,21 @@ func (f *awssmpFS) getClient(ctx context.Context) (SSMClient, error) {
opts = append(opts, config.WithHTTPClient(f.httpclient))
}

// setting a host in the URL is only intended for test purposes
if f.base.Host != "" {
customResolver := aws.EndpointResolverWithOptionsFunc(func(_, _ string, _ ...interface{}) (aws.Endpoint, error) {
return aws.Endpoint{
PartitionID: "aws",
URL: "http://" + f.base.Host,
SigningRegion: "us-east-1",
}, nil
})

opts = append(opts, config.WithEndpointResolverWithOptions(customResolver))
}

cfg, err := config.LoadDefaultConfig(ctx, opts...)
if err != nil {
return nil, err
}

f.ssmclient = ssm.NewFromConfig(cfg)
optFns := []func(*ssm.Options){}

// setting a host in the URL is only intended for test purposes
if f.base.Host != "" {
optFns = append(optFns, func(o *ssm.Options) {
o.BaseEndpoint = aws.String("http://" + f.base.Host)
})
}

f.ssmclient = ssm.NewFromConfig(cfg, optFns...)

return f.ssmclient, nil
}
Expand Down

0 comments on commit 14df5fa

Please sign in to comment.