-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from AirHelp/upgrade-aws-sdk-go-to-v2-version
feat(treasury): upgrade to aws-sdk-go-v2
- Loading branch information
Showing
15 changed files
with
176 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,41 @@ | ||
package s3 | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/s3" | ||
"github.com/aws/aws-sdk-go/service/s3/s3iface" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/s3" | ||
) | ||
|
||
// Client with AWS services | ||
type S3ClientInterface interface { | ||
PutObject(context.Context, *s3.PutObjectInput, ...func(*s3.Options)) (*s3.PutObjectOutput, error) | ||
GetObject(context.Context, *s3.GetObjectInput, ...func(*s3.Options)) (*s3.GetObjectOutput, error) | ||
ListObjects(context.Context, *s3.ListObjectsInput, ...func(*s3.Options)) (*s3.ListObjectsOutput, error) | ||
DeleteObject(context.Context, *s3.DeleteObjectInput, ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) | ||
} | ||
|
||
type Client struct { | ||
sess *session.Session | ||
S3Svc s3iface.S3API | ||
S3Svc S3ClientInterface | ||
bucket string | ||
} | ||
|
||
// New returns clients for AWS services | ||
func New(region, bucket string) (*Client, error) { | ||
if bucket == "" { | ||
return nil, errors.New("S3 bucket name is missing") | ||
} | ||
sessionOpts := session.Options{ | ||
SharedConfigState: session.SharedConfigEnable, | ||
} | ||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region)) | ||
|
||
if region != "" { | ||
sessionOpts.Config = aws.Config{Region: aws.String(region)} | ||
} | ||
|
||
sess, err := session.NewSessionWithOptions(sessionOpts) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to create AWS session. Error: %s", err) | ||
return &Client{}, errors.Join( | ||
fmt.Errorf("unable to load SDK config with region %s", region), | ||
err, | ||
) | ||
} | ||
|
||
s3Svc := s3.New(sess) | ||
|
||
return &Client{ | ||
sess: sess, | ||
S3Svc: s3Svc, | ||
bucket: bucket, | ||
}, nil | ||
S3Svc: s3.NewFromConfig(cfg), | ||
}, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,33 @@ | ||
package ssm | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ssm" | ||
"github.com/aws/aws-sdk-go/service/ssm/ssmiface" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/ssm" | ||
) | ||
|
||
type SSMClientInterface interface { | ||
GetParameter(context.Context, *ssm.GetParameterInput, ...func(*ssm.Options)) (*ssm.GetParameterOutput, error) | ||
PutParameter(context.Context, *ssm.PutParameterInput, ...func(*ssm.Options)) (*ssm.PutParameterOutput, error) | ||
GetParametersByPath(context.Context, *ssm.GetParametersByPathInput, ...func(*ssm.Options)) (*ssm.GetParametersByPathOutput, error) | ||
DeleteParameter(context.Context, *ssm.DeleteParameterInput, ...func(*ssm.Options)) (*ssm.DeleteParameterOutput, error) | ||
} | ||
|
||
// Client with AWS services | ||
type Client struct { | ||
svc ssmiface.SSMAPI | ||
svc SSMClientInterface | ||
} | ||
|
||
// New returns clients for AWS services | ||
func New(region string, awsConfig aws.Config) (*Client, error) { | ||
if region != "" { | ||
awsConfig = *awsConfig.WithRegion(region) | ||
} | ||
|
||
sess, err := session.NewSessionWithOptions(session.Options{ | ||
Config: awsConfig, | ||
}) | ||
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithRegion(region)) | ||
if err != nil { | ||
return nil, fmt.Errorf("Failed to create AWS session. Error: %s", err) | ||
return nil, fmt.Errorf("failed to load AWS configuration. Error: %s", err) | ||
} | ||
|
||
// Create a SSM client with additional configuration | ||
svc := ssm.New(sess) | ||
|
||
return &Client{ | ||
svc: svc, | ||
svc: ssm.NewFromConfig(cfg), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.