Skip to content

Commit ef67a1b

Browse files
author
Chris Gilmer
authored
Merge pull request #74 from trussworks/cg_remove_profile_check
Don't fault if aws-profile already exists
2 parents 53dee1d + 9dda7d8 commit ef67a1b

File tree

2 files changed

+5
-52
lines changed

2 files changed

+5
-52
lines changed

cmd/setup.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -551,16 +551,6 @@ func openQrCode(tempFile *os.File) error {
551551
return nil
552552
}
553553

554-
func checkExistingAWSProfile(profileName string, config *vault.Config, logger *log.Logger) error {
555-
logger.Printf("Checking whether profile %q exists in AWS config file\n", profileName)
556-
_, exists := config.Profile(profileName)
557-
if exists {
558-
return fmt.Errorf("Profile already exists in AWS config file: %s", profileName)
559-
}
560-
561-
return nil
562-
}
563-
564554
func getPartition(region string) (string, error) {
565555
partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), region)
566556
if !ok {
@@ -679,14 +669,6 @@ func setupUserFunction(cmd *cobra.Command, args []string) error {
679669
Keyring: keyring,
680670
NoMFA: noMFA,
681671
}
682-
err = checkExistingAWSProfile(baseProfile.Name, config, logger)
683-
if err != nil {
684-
logger.Fatal(err)
685-
}
686-
err = checkExistingAWSProfile(roleProfile.Name, config, logger)
687-
if err != nil {
688-
logger.Fatal(err)
689-
}
690672
setupConfig.Setup()
691673

692674
// If we got this far, we win

cmd/setup_test.go

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ import (
1313
// Test logger
1414
var logger = log.New(os.Stdout, "", log.LstdFlags)
1515

16-
var defaultConfig = []byte(`[profile test]
17-
region=us-west-2
18-
output=json
19-
`)
20-
2116
func newConfigFile(t *testing.T, b []byte) string {
2217
f, err := ioutil.TempFile("", "aws-config")
2318
if err != nil {
@@ -29,36 +24,12 @@ func newConfigFile(t *testing.T, b []byte) string {
2924
return f.Name()
3025
}
3126

32-
func TestExistingAWSProfile(t *testing.T) {
33-
f := newConfigFile(t, defaultConfig)
34-
defer func() {
35-
errRemove := os.Remove(f)
36-
assert.NoError(t, errRemove)
37-
}()
38-
config, _ := vault.LoadConfig(f)
39-
baseProfile := vault.Profile{
40-
Name: "test",
41-
Region: "us-west-2",
42-
}
43-
keyring, err := getKeyring("test")
44-
assert.NoError(t, err)
45-
setupConfig := SetupConfig{
46-
Logger: logger,
47-
Name: "test",
48-
BaseProfile: &baseProfile,
49-
Output: "json",
50-
Config: config,
51-
QrTempFile: nil,
52-
Keyring: keyring,
53-
}
54-
55-
err = checkExistingAWSProfile(baseProfile.Name, setupConfig.Config, logger)
56-
assert.Error(t, err)
57-
err = checkExistingAWSProfile("missing", setupConfig.Config, logger)
58-
assert.NoError(t, err)
59-
}
60-
6127
func TestUpdateAWSConfigFile(t *testing.T) {
28+
29+
var defaultConfig = []byte(`[profile test]
30+
region=us-west-2
31+
output=json
32+
`)
6233
f := newConfigFile(t, defaultConfig)
6334
defer func() {
6435
errRemove := os.Remove(f)

0 commit comments

Comments
 (0)