Bump to sdk aws go v2 at release v0.26.0...

Bump dependancies
Refactor / Fix aws to work with sdk-aws-go-v2 at release v0.26.0...
This commit is contained in:
Nicolas JUHEL
2020-09-30 13:04:47 +02:00
parent 47dc7f34ae
commit 94f90d7e22
38 changed files with 706 additions and 749 deletions

View File

@@ -5,9 +5,10 @@ import (
"net/http"
"net/url"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/iam"
"github.com/aws/aws-sdk-go-v2/service/s3"
sdkaws "github.com/aws/aws-sdk-go-v2/aws"
sdksv4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
sdkiam "github.com/aws/aws-sdk-go-v2/service/iam"
sdksss "github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/nabbar/golib/aws/bucket"
"github.com/nabbar/golib/aws/group"
"github.com/nabbar/golib/aws/helper"
@@ -16,7 +17,6 @@ import (
"github.com/nabbar/golib/aws/role"
"github.com/nabbar/golib/aws/user"
"github.com/nabbar/golib/errors"
"github.com/nabbar/golib/logger"
)
type Config interface {
@@ -31,13 +31,11 @@ type Config interface {
SetEndpoint(endpoint *url.URL)
GetEndpoint() *url.URL
ResolveEndpoint(service, region string) (aws.Endpoint, error)
IsHTTPs() bool
ResolveEndpoint(service, region string) (sdkaws.Endpoint, error)
SetRetryer(retryer sdkaws.Retryer)
SetLogLevel(lvl logger.Level)
SetAWSLogLevel(lvl aws.LogLevel)
SetRetryer(retryer aws.Retryer)
GetConfig(cli *http.Client) (aws.Config, errors.Error)
GetConfig(cli *http.Client) (*sdkaws.Config, errors.Error)
JSON() ([]byte, error)
Clone() Config
@@ -53,9 +51,9 @@ type AWS interface {
Role() role.Role
User() user.User
Clone() AWS
Clone() (AWS, errors.Error)
Config() Config
ForcePathStyle(enabled bool)
ForcePathStyle(enabled bool) errors.Error
GetBucketName() string
SetBucketName(bucket string)
@@ -65,8 +63,9 @@ type client struct {
p bool
x context.Context
c Config
i *iam.Client
s *s3.Client
i *sdkiam.Client
s *sdksss.Client
h *http.Client
}
func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, errors.Error) {
@@ -74,57 +73,118 @@ func New(ctx context.Context, cfg Config, httpClient *http.Client) (AWS, errors.
return nil, helper.ErrorConfigEmpty.Error(nil)
}
var (
c aws.Config
i *iam.Client
s *s3.Client
e errors.Error
)
if c, e = cfg.GetConfig(httpClient); e != nil {
return nil, e
}
i = iam.New(c)
s = s3.New(c)
if httpClient != nil {
i.HTTPClient = httpClient
s.HTTPClient = httpClient
}
if ctx == nil {
ctx = context.Background()
}
return &client{
cli := &client{
p: false,
x: ctx,
c: cfg,
i: i,
s: s,
}, nil
}
func (c *client) getCliIAM() *iam.Client {
i := iam.New(c.i.Config)
i.HTTPClient = c.i.HTTPClient
return i
}
func (c *client) getCliS3() *s3.Client {
s := s3.New(c.s.Config)
s.HTTPClient = c.s.HTTPClient
s.ForcePathStyle = c.p
return s
}
func (c *client) Clone() AWS {
return &client{
p: c.p,
x: c.x,
c: c.c.Clone(),
i: c.getCliIAM(),
s: c.getCliS3(),
i: nil,
s: nil,
h: httpClient,
}
if i, e := cli.newClientIAM(httpClient); e != nil {
return nil, e
} else {
cli.i = i
}
if s, e := cli.newClientS3(httpClient); e != nil {
return nil, e
} else {
cli.s = s
}
return cli, nil
}
func (cli *client) newClientIAM(httpClient *http.Client) (*sdkiam.Client, errors.Error) {
var (
c *sdkaws.Config
i *sdkiam.Client
e errors.Error
)
if httpClient == nil {
httpClient = cli.h
}
if c, e = cli.c.GetConfig(httpClient); e != nil {
return nil, e
}
i = sdkiam.New(sdkiam.Options{
APIOptions: c.APIOptions,
Credentials: c.Credentials,
EndpointOptions: sdkiam.ResolverOptions{
DisableHTTPS: cli.c.IsHTTPs(),
},
EndpointResolver: sdkiam.WithEndpointResolver(c.EndpointResolver, nil),
HTTPSignerV4: sdksv4.NewSigner(),
Region: c.Region,
Retryer: c.Retryer,
HTTPClient: httpClient,
})
return i, nil
}
func (cli *client) newClientS3(httpClient *http.Client) (*sdksss.Client, errors.Error) {
var (
c *sdkaws.Config
s *sdksss.Client
e errors.Error
)
if httpClient == nil {
httpClient = cli.h
}
if c, e = cli.c.GetConfig(httpClient); e != nil {
return nil, e
}
s = sdksss.New(sdksss.Options{
APIOptions: c.APIOptions,
Credentials: c.Credentials,
EndpointOptions: sdksss.ResolverOptions{
DisableHTTPS: cli.c.IsHTTPs(),
},
EndpointResolver: sdksss.WithEndpointResolver(c.EndpointResolver, nil),
HTTPSignerV4: sdksv4.NewSigner(),
Region: c.Region,
Retryer: c.Retryer,
HTTPClient: httpClient,
UsePathStyle: cli.p,
})
return s, nil
}
func (c *client) Clone() (AWS, errors.Error) {
cli := &client{
p: false,
x: c.x,
c: c.c,
i: nil,
s: nil,
h: c.h,
}
if i, e := cli.newClientIAM(c.h); e != nil {
return nil, e
} else {
cli.i = i
}
if s, e := cli.newClientS3(c.h); e != nil {
return nil, e
} else {
cli.s = s
}
return cli, nil
}