Skip to content

Commit

Permalink
Merge pull request #74 from trussworks/cg_remove_profile_check
Browse files Browse the repository at this point in the history
Don't fault if aws-profile already exists
  • Loading branch information
Chris Gilmer committed Jul 10, 2020
2 parents 53dee1d + 9dda7d8 commit ef67a1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 52 deletions.
18 changes: 0 additions & 18 deletions cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,16 +551,6 @@ func openQrCode(tempFile *os.File) error {
return nil
}

func checkExistingAWSProfile(profileName string, config *vault.Config, logger *log.Logger) error {
logger.Printf("Checking whether profile %q exists in AWS config file\n", profileName)
_, exists := config.Profile(profileName)
if exists {
return fmt.Errorf("Profile already exists in AWS config file: %s", profileName)
}

return nil
}

func getPartition(region string) (string, error) {
partition, ok := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), region)
if !ok {
Expand Down Expand Up @@ -679,14 +669,6 @@ func setupUserFunction(cmd *cobra.Command, args []string) error {
Keyring: keyring,
NoMFA: noMFA,
}
err = checkExistingAWSProfile(baseProfile.Name, config, logger)
if err != nil {
logger.Fatal(err)
}
err = checkExistingAWSProfile(roleProfile.Name, config, logger)
if err != nil {
logger.Fatal(err)
}
setupConfig.Setup()

// If we got this far, we win
Expand Down
39 changes: 5 additions & 34 deletions cmd/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import (
// Test logger
var logger = log.New(os.Stdout, "", log.LstdFlags)

var defaultConfig = []byte(`[profile test]
region=us-west-2
output=json
`)

func newConfigFile(t *testing.T, b []byte) string {
f, err := ioutil.TempFile("", "aws-config")
if err != nil {
Expand All @@ -29,36 +24,12 @@ func newConfigFile(t *testing.T, b []byte) string {
return f.Name()
}

func TestExistingAWSProfile(t *testing.T) {
f := newConfigFile(t, defaultConfig)
defer func() {
errRemove := os.Remove(f)
assert.NoError(t, errRemove)
}()
config, _ := vault.LoadConfig(f)
baseProfile := vault.Profile{
Name: "test",
Region: "us-west-2",
}
keyring, err := getKeyring("test")
assert.NoError(t, err)
setupConfig := SetupConfig{
Logger: logger,
Name: "test",
BaseProfile: &baseProfile,
Output: "json",
Config: config,
QrTempFile: nil,
Keyring: keyring,
}

err = checkExistingAWSProfile(baseProfile.Name, setupConfig.Config, logger)
assert.Error(t, err)
err = checkExistingAWSProfile("missing", setupConfig.Config, logger)
assert.NoError(t, err)
}

func TestUpdateAWSConfigFile(t *testing.T) {

var defaultConfig = []byte(`[profile test]
region=us-west-2
output=json
`)
f := newConfigFile(t, defaultConfig)
defer func() {
errRemove := os.Remove(f)
Expand Down

0 comments on commit ef67a1b

Please sign in to comment.