752fb2e2c0
Text Extraction Clean Up + Parallelization * merged_Call * directchildren * bitofimprovements * go * parallel * fixfullsuite * pondforconcurrency * comments * muchdone * bitsofclean * stabilisedtests * snappy * threadpooltests * childelements * testspassed
107 lines
2.4 KiB
Go
107 lines
2.4 KiB
Go
package aws
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/aws/aws-sdk-go-v2/aws"
|
|
"github.com/aws/aws-sdk-go-v2/config"
|
|
)
|
|
|
|
type Profile string
|
|
|
|
type AWSConfig struct {
|
|
AWSKeyID string `env:"AWS_ACCESS_KEY_ID,required,notEmpty"`
|
|
AWSSecretKey string `env:"AWS_SECRET_ACCESS_KEY,required,notEmpty"`
|
|
AWSRegion string `env:"AWS_REGION,required,notEmpty"`
|
|
AWSDefaultRegion string `env:"AWS_DEFAULT_REGION"`
|
|
AWSSessionToken string `env:"AWS_SESSION_TOKEN"`
|
|
AWSEndpointUrl string `env:"AWS_ENDPOINT_URL"`
|
|
AWSProfile Profile `env:"AWS_PROFILE"`
|
|
}
|
|
|
|
type ConfigProvider interface {
|
|
GetAWSKeyID() string
|
|
SetAWSKeyID(string)
|
|
GetAWSSecretKey() string
|
|
SetAWSSecretKey(string)
|
|
GetAWSRegion() string
|
|
SetAWSRegion(string)
|
|
GetAWSProfile() Profile
|
|
SetAWSProfile(Profile)
|
|
GetAWSSessionToken() string
|
|
SetAWSSessionToken(string)
|
|
GetAWSEndpoint() string
|
|
SetAWSEndpoint(string)
|
|
}
|
|
|
|
func (c *AWSConfig) SetAWSEndpoint(e string) {
|
|
c.AWSEndpointUrl = e
|
|
}
|
|
|
|
func (c *AWSConfig) GetAWSEndpoint() string {
|
|
return c.AWSEndpointUrl
|
|
}
|
|
|
|
func (c *AWSConfig) GetAWSKeyID() string {
|
|
return c.AWSKeyID
|
|
}
|
|
|
|
func (c *AWSConfig) SetAWSKeyID(val string) {
|
|
c.AWSKeyID = val
|
|
}
|
|
|
|
func (c *AWSConfig) GetAWSSecretKey() string {
|
|
return c.AWSSecretKey
|
|
}
|
|
|
|
func (c *AWSConfig) SetAWSSecretKey(val string) {
|
|
c.AWSSecretKey = val
|
|
}
|
|
|
|
func (c *AWSConfig) GetAWSSessionToken() string {
|
|
return c.AWSSessionToken
|
|
}
|
|
|
|
func (c *AWSConfig) SetAWSSessionToken(val string) {
|
|
c.AWSSessionToken = val
|
|
}
|
|
|
|
func (c *AWSConfig) GetAWSRegion() string {
|
|
return c.AWSRegion
|
|
}
|
|
|
|
func (c *AWSConfig) SetAWSRegion(val string) {
|
|
c.AWSRegion = val
|
|
}
|
|
|
|
func (c *AWSConfig) GetAWSProfile() Profile {
|
|
return c.AWSProfile
|
|
}
|
|
|
|
func (c *AWSConfig) SetAWSProfile(val Profile) {
|
|
c.AWSProfile = val
|
|
}
|
|
|
|
func GetAWSConfigWithOpts(ctx context.Context, opts ...func(*config.LoadOptions) error) (aws.Config, error) {
|
|
cfg, err := config.LoadDefaultConfig(ctx, opts...)
|
|
if err != nil {
|
|
return aws.Config{}, fmt.Errorf("unable to load SDK config: %v", err)
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
func GetAWSConfigWithProfile(ctx context.Context, profile Profile) (aws.Config, error) {
|
|
optFns := []func(*config.LoadOptions) error{}
|
|
if profile != "" {
|
|
optFns = append(optFns, config.WithSharedConfigProfile(string(profile)))
|
|
}
|
|
|
|
return GetAWSConfigWithOpts(ctx, optFns...)
|
|
}
|
|
|
|
func GetAWSConfig(ctx context.Context) (aws.Config, error) {
|
|
return GetAWSConfigWithOpts(ctx)
|
|
}
|