Skip to content

Commit 9070b33

Browse files
authored
Merge branch 'master' into 110-optional-acl
2 parents 12af530 + fe9d75b commit 9070b33

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func main() {
131131
Name: "env-file",
132132
Usage: "source env file",
133133
},
134+
cli.StringFlag{
135+
Name: "external-id",
136+
Usage: "external ID to use when assuming role",
137+
EnvVar: "PLUGIN_EXTERNAL_ID",
138+
},
134139
}
135140

136141
if err := app.Run(os.Args); err != nil {
@@ -164,6 +169,7 @@ func run(c *cli.Context) error {
164169
StorageClass: c.String("storage-class"),
165170
PathStyle: c.Bool("path-style"),
166171
DryRun: c.Bool("dry-run"),
172+
ExternalID: c.String("external-id"),
167173
}
168174

169175
return plugin.Exec()

plugin.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ type Plugin struct {
9090
PathStyle bool
9191
// Dry run without uploading/
9292
DryRun bool
93+
94+
// set externalID for assume role
95+
ExternalID string
9396
}
9497

9598
// Exec runs the plugin
@@ -108,7 +111,7 @@ func (p *Plugin) Exec() error {
108111
if p.Key != "" && p.Secret != "" {
109112
conf.Credentials = credentials.NewStaticCredentials(p.Key, p.Secret, "")
110113
} else if p.AssumeRole != "" {
111-
conf.Credentials = assumeRole(p.AssumeRole, p.AssumeRoleSessionName)
114+
conf.Credentials = assumeRole(p.AssumeRole, p.AssumeRoleSessionName, p.ExternalID)
112115
} else {
113116
log.Warn("AWS Key and/or Secret not provided (falling back to ec2 instance profile)")
114117
}
@@ -290,7 +293,7 @@ func matchExtension(match string, stringMap map[string]string) string {
290293
return ""
291294
}
292295

293-
func assumeRole(roleArn, roleSessionName string) *credentials.Credentials {
296+
func assumeRole(roleArn, roleSessionName, externalID string) *credentials.Credentials {
294297
sess, _ := session.NewSession()
295298
client := sts.New(sess)
296299
duration := time.Hour * 1
@@ -301,6 +304,10 @@ func assumeRole(roleArn, roleSessionName string) *credentials.Credentials {
301304
RoleSessionName: roleSessionName,
302305
}
303306

307+
if externalID != "" {
308+
stsProvider.ExternalID = &externalID
309+
}
310+
304311
return credentials.NewCredentials(stsProvider)
305312
}
306313

@@ -321,17 +328,17 @@ func isDir(source string, matches []string) bool {
321328
if err != nil {
322329
return true // should never happen
323330
}
324-
if (stat.IsDir()) {
331+
if stat.IsDir() {
325332
count := 0
326333
for _, match := range matches {
327334
if strings.HasPrefix(match, source) {
328-
count++;
335+
count++
329336
}
330337
}
331338
if count <= 1 {
332339
log.Warnf("Skipping '%s' since it is a directory. Please use correct glob expression if this is unexpected.", source)
333340
}
334-
return true;
341+
return true
335342
}
336343
return false
337344
}

0 commit comments

Comments
 (0)