You've already forked img-proxy-url-generator
This commit is contained in:
@@ -6,30 +6,33 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/siteworxpro/img-proxy-url-generator/config"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
AwsKey string
|
||||
AwsSecret string
|
||||
AwsRole string
|
||||
Bucket string
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
s3 *s3.S3
|
||||
bucket string
|
||||
}
|
||||
|
||||
func NewClient(config *Config) *Service {
|
||||
func NewClient(config *config.Config) *Service {
|
||||
|
||||
var accessCredentials *credentials.Credentials
|
||||
|
||||
staticCredentials := credentials.NewStaticCredentials(config.Aws.AwsKey, config.Aws.AwsSecret, config.Aws.AwsToken)
|
||||
awsSession := session.Must(session.NewSession(&aws.Config{
|
||||
Credentials: credentials.NewStaticCredentials(config.AwsKey, config.AwsSecret, ""),
|
||||
Credentials: staticCredentials,
|
||||
Region: aws.String("us-east-1"),
|
||||
}))
|
||||
|
||||
assumeRoleCredentials := stscreds.NewCredentials(awsSession, config.AwsRole)
|
||||
if config.Aws.AwsRole != "" {
|
||||
assumeRoleCredentials := stscreds.NewCredentials(awsSession, config.Aws.AwsRole)
|
||||
accessCredentials = assumeRoleCredentials
|
||||
} else {
|
||||
accessCredentials = staticCredentials
|
||||
}
|
||||
|
||||
return &Service{
|
||||
s3: s3.New(awsSession, &aws.Config{Credentials: assumeRoleCredentials}),
|
||||
bucket: config.Bucket,
|
||||
s3: s3.New(awsSession, &aws.Config{Credentials: accessCredentials}),
|
||||
bucket: config.Aws.AwsBucket,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user