Skip to content

Commit c9636fd

Browse files
author
Michael Kania
committed
support GovCloud IAM role ARN
1 parent e89b01d commit c9636fd

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: 2.1
22

33
references:
4-
circleci-docker-primary: &circleci-docker-primary trussworks/circleci-docker-primary:d7f27acdab24f86297220a43f704f23f2bab667d
4+
circleci-docker-primary: &circleci-docker-primary trussworks/circleci-docker-primary:c542b22c7fb95db0a1bbe043928a457ae6fbeaca
55

66
jobs:
77
test:

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: git://github.com/golangci/golangci-lint
3-
rev: v1.24.0
3+
rev: v1.26.0
44
hooks:
55
- id: golangci-lint
66

@@ -17,6 +17,6 @@ repos:
1717
- id: trailing-whitespace
1818

1919
- repo: git://github.com/igorshubovych/markdownlint-cli
20-
rev: v0.22.0
20+
rev: v0.23.0
2121
hooks:
2222
- id: markdownlint

cmd/main.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"fmt"
55
"io/ioutil"
6-
76
"log"
87
"os"
98

@@ -12,6 +11,7 @@ import (
1211
"github.com/99designs/keyring"
1312
"github.com/aws/aws-sdk-go/aws"
1413
"github.com/aws/aws-sdk-go/aws/credentials"
14+
"github.com/aws/aws-sdk-go/aws/endpoints"
1515
"github.com/aws/aws-sdk-go/aws/session"
1616
"github.com/aws/aws-sdk-go/service/iam"
1717
"github.com/aws/aws-sdk-go/service/sts"
@@ -453,6 +453,13 @@ func checkExistingAWSProfile(profileName string, config *vault.Config) error {
453453
return nil
454454
}
455455

456+
func getPartition(region string) string {
457+
if partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), region); ok {
458+
return partition.ID()
459+
}
460+
return "aws"
461+
}
462+
456463
func main() {
457464
// parse command line flags
458465
var options cliOptions
@@ -468,8 +475,10 @@ func main() {
468475
// initialize things
469476
profile := vault.Profile{
470477
Name: options.AwsProfile,
471-
RoleARN: fmt.Sprintf("arn:aws:iam::%v:role/%v",
472-
options.AwsAccountID, options.Role),
478+
RoleARN: fmt.Sprintf("arn:%s:iam::%d:role/%s",
479+
getPartition(options.AwsRegion),
480+
options.AwsAccountID,
481+
options.Role),
473482
Region: options.AwsRegion,
474483
}
475484

cmd/main_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,12 @@ func TestGenerateQrCode(t *testing.T) {
6161
err = generateQrCode("otpauth://totp/super@top?secret=secret", tempFile)
6262
assert.NoError(t, err)
6363
}
64+
65+
func TestGetPartition(t *testing.T) {
66+
commPartition := getPartition("us-west-2")
67+
assert.Equal(t, commPartition, "aws")
68+
govPartition := getPartition("us-gov-west-1")
69+
assert.Equal(t, govPartition, "aws-us-gov")
70+
unknownPartition := getPartition("aws-under-the-sea")
71+
assert.Equal(t, unknownPartition, "aws")
72+
}

0 commit comments

Comments
 (0)