@@ -13,10 +13,10 @@ import (
1313 "strings"
1414 "time"
1515
16- "github.com/aws/aws-sdk-go/aws"
17- "github.com/aws/aws-sdk-go/aws/credentials "
18- "github.com/aws/aws-sdk-go/aws/session "
19- "github.com/aws/aws-sdk-go/service/s3"
16+ "github.com/aws/aws-sdk-go-v2 /aws"
17+ "github.com/aws/aws-sdk-go-v2/config "
18+ "github.com/aws/aws-sdk-go-v2/credentials "
19+ "github.com/aws/aws-sdk-go-v2 /service/s3"
2020 k0sv1beta1 "github.com/k0sproject/k0s/pkg/apis/k0s/v1beta1"
2121 apitypes "github.com/replicatedhq/embedded-cluster/api/types"
2222 "github.com/replicatedhq/embedded-cluster/cmd/installer/kotscli"
@@ -364,7 +364,7 @@ func runRestoreStepNew(ctx context.Context, appSlug, appTitle string, flags Inst
364364
365365 if ! skipStoreValidation {
366366 logrus .Debugf ("validating backup store configuration" )
367- if err := validateS3BackupStore (s3Store ); err != nil {
367+ if err := validateS3BackupStore (ctx , s3Store ); err != nil {
368368 return fmt .Errorf ("unable to validate backup store: %w" , err )
369369 }
370370 }
@@ -988,30 +988,35 @@ func promptForS3BackupStore(store *s3BackupStore) error {
988988
989989// validateS3BackupStore validates the S3 backup store configuration.
990990// It tries to list objects in the bucket and prefix to ensure that the bucket exists and has backups.
991- func validateS3BackupStore (s * s3BackupStore ) error {
991+ func validateS3BackupStore (ctx context. Context , s * s3BackupStore ) error {
992992 u , err := url .Parse (s .endpoint )
993993 if err != nil {
994994 return fmt .Errorf ("parse endpoint: %v" , err )
995995 }
996996
997997 isAWS := strings .HasSuffix (u .Hostname (), ".amazonaws.com" )
998- sess , err := session . NewSession ( & aws. Config {
999- Region : aws . String ( s . region ),
1000- Endpoint : aws . String ( s . endpoint ) ,
1001- Credentials : credentials . NewStaticCredentials (s .accessKeyID , s . secretAccessKey , "" ),
1002- S3ForcePathStyle : aws . Bool ( ! isAWS ),
1003- } )
998+ creds := credentials . NewStaticCredentialsProvider ( s . accessKeyID , s . secretAccessKey , "" )
999+
1000+ cfg , err := config . LoadDefaultConfig ( ctx ,
1001+ config . WithRegion (s .region ),
1002+ config . WithCredentialsProvider ( creds ),
1003+ )
10041004 if err != nil {
1005- return fmt .Errorf ("create s3 session : %v" , err )
1005+ return fmt .Errorf ("load aws config : %v" , err )
10061006 }
10071007
1008+ svc := s3 .NewFromConfig (cfg , func (o * s3.Options ) {
1009+ o .BaseEndpoint = aws .String (s .endpoint )
1010+ o .UsePathStyle = ! isAWS
1011+ })
1012+
10081013 input := & s3.ListObjectsV2Input {
10091014 Bucket : aws .String (s .bucket ),
10101015 Delimiter : aws .String ("/" ),
10111016 Prefix : aws .String (fmt .Sprintf ("%s/" , filepath .Join (s .prefix , "backups" ))),
10121017 }
1013- svc := s3 . New ( sess )
1014- result , err := svc .ListObjectsV2 (input )
1018+
1019+ result , err := svc .ListObjectsV2 (ctx , input )
10151020 if err != nil {
10161021 return fmt .Errorf ("list objects: %v" , err )
10171022 }
0 commit comments