0
0
mirror of https://github.com/thegeeklab/wp-s3-action.git synced 2024-11-22 01:00:40 +00:00

Merge pull request #38 from fbcbarbosa/master

Rm aws keys verification to allow for iam roles
This commit is contained in:
Thomas Boerger 2019-02-11 09:32:17 +01:00 committed by GitHub
commit 2942dd301f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

8
aws.go
View File

@ -28,8 +28,8 @@ type AWS struct {
} }
func NewAWS(p *Plugin) AWS { func NewAWS(p *Plugin) AWS {
sessCfg := &aws.Config{ sessCfg := &aws.Config{
Credentials: credentials.NewStaticCredentials(p.Key, p.Secret, ""),
S3ForcePathStyle: aws.Bool(p.PathStyle), S3ForcePathStyle: aws.Bool(p.PathStyle),
Region: aws.String(p.Region), Region: aws.String(p.Region),
} }
@ -38,6 +38,12 @@ func NewAWS(p *Plugin) AWS {
sessCfg.Endpoint = &p.Endpoint sessCfg.Endpoint = &p.Endpoint
sessCfg.DisableSSL = aws.Bool(strings.HasPrefix(p.Endpoint, "http://")) sessCfg.DisableSSL = aws.Bool(strings.HasPrefix(p.Endpoint, "http://"))
} }
// allowing to use the instance role or provide a key and secret
if p.Key != "" && p.Secret != "" {
sessCfg.Credentials = credentials.NewStaticCredentials(p.Key, p.Secret, "")
}
sess := session.New(sessCfg) sess := session.New(sessCfg)
c := s3.New(sess) c := s3.New(sess)

View File

@ -42,7 +42,7 @@ type result struct {
err error err error
} }
var MissingAwsValuesMessage = "Must set access_key, secret_key, and bucket" var MissingAwsValuesMessage = "Must set 'bucket'"
func (p *Plugin) Exec() error { func (p *Plugin) Exec() error {
err := p.sanitizeInputs() err := p.sanitizeInputs()
@ -61,7 +61,7 @@ func (p *Plugin) Exec() error {
} }
func (p *Plugin) sanitizeInputs() error { func (p *Plugin) sanitizeInputs() error {
if len(p.Key) == 0 || len(p.Secret) == 0 || len(p.Bucket) == 0 { if len(p.Bucket) == 0 {
return errors.New(MissingAwsValuesMessage) return errors.New(MissingAwsValuesMessage)
} }