Skip to content

Commit

Permalink
fixing the ignored --zone flag bug, when the user define the zone of …
Browse files Browse the repository at this point in the history
…the sos to list it's buckets.
  • Loading branch information
elkezza committed Nov 15, 2024
1 parent b62c36e commit 3cb44f5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/storage_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Supported output template annotations:

storage, err := sos.NewStorageClient(
gContext,
sos.ClientOptZoneFromBucket(gContext, bucket),
sos.ClientOptZoneFromBucketWithZone(gContext, bucket, zone),
)
if err != nil {
return fmt.Errorf("unable to initialize storage client: %w", err)
Expand Down
33 changes: 33 additions & 0 deletions pkg/storage/sos/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,39 @@ func ClientOptZoneFromBucket(ctx context.Context, bucket string) ClientOpt {
}
}


func ClientOptZoneFromBucketWithZone(ctx context.Context, bucket string, zone string) ClientOpt {
return func(c *Client) error {
cfg, err := awsconfig.LoadDefaultConfig(
ctx,
append(CommonConfigOptFns,
awsconfig.WithEndpointResolver(aws.EndpointResolverFunc(
func(service, region string) (aws.Endpoint, error) {
sosURL := strings.Replace(
account.CurrentAccount.SosEndpoint,
"{zone}",
zone,
1,
)
return aws.Endpoint{URL: sosURL}, nil
})),
)...)
if err != nil {
return err
}

region, err := s3manager.GetBucketRegion(ctx, s3.NewFromConfig(cfg), bucket, func(o *s3.Options) {
o.UsePathStyle = true
})
if err != nil {
return err
}

c.Zone = region
return nil
}
}

func NewStorageClient(ctx context.Context, opts ...ClientOpt) (*Client, error) {
var (
client = Client{
Expand Down

0 comments on commit 3cb44f5

Please sign in to comment.