Exemplo n.º 1
0
func AddCommand(app *kingpin.Application, input AddCommandInput) {
	var accessKeyId, secretKey string

	if input.FromEnv {
		if accessKeyId = os.Getenv("AWS_ACCESS_KEY_ID"); accessKeyId == "" {
			app.Fatalf("Missing value for AWS_ACCESS_KEY_ID")
			return
		}
		if secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY"); secretKey == "" {
			app.Fatalf("Missing value for AWS_SECRET_ACCESS_KEY")
			return
		}
	} else {
		var err error
		if accessKeyId, err = prompt.TerminalPrompt("Enter Access Key ID: "); err != nil {
			app.Fatalf(err.Error())
			return
		}
		if secretKey, err = prompt.TerminalPrompt("Enter Secret Access Key: "); err != nil {
			app.Fatalf(err.Error())
			return
		}
	}

	creds := credentials.Value{AccessKeyID: accessKeyId, SecretAccessKey: secretKey}
	provider := &KeyringProvider{Keyring: input.Keyring, Profile: input.Profile}

	if err := provider.Store(creds); err != nil {
		app.Fatalf(err.Error())
		return
	}

	fmt.Printf("Added credentials to profile %q in vault\n", input.Profile)

	profiles, err := awsConfigFile.Parse()
	if err != nil {
		app.Fatalf("%v", err)
		return
	}

	sessions, err := NewKeyringSessions(input.Keyring, profiles)
	if err != nil {
		app.Fatalf(err.Error())
		return
	}

	if n, _ := sessions.Delete(input.Profile); n > 0 {
		fmt.Printf("Deleted %d existing sessions.\n", n)
	}
}
Exemplo n.º 2
0
func AddCommand(ui Ui, input AddCommandInput) {
	var accessKeyId, secretKey string

	if input.FromEnv {
		if accessKeyId = os.Getenv("AWS_ACCESS_KEY_ID"); accessKeyId == "" {
			ui.Error.Fatal("Missing value for AWS_ACCESS_KEY_ID")
		}
		if secretKey = os.Getenv("AWS_SECRET_ACCESS_KEY"); secretKey == "" {
			ui.Error.Fatal("Missing value for AWS_SECRET_ACCESS_KEY")
		}
	} else {
		var err error
		if accessKeyId, err = prompt.TerminalPrompt("Enter Access Key ID: "); err != nil {
			ui.Error.Fatal(err)
		}
		if secretKey, err = prompt.TerminalPrompt("Enter Secret Access Key: "); err != nil {
			ui.Error.Fatal(err)
		}
	}

	creds := credentials.Value{AccessKeyID: accessKeyId, SecretAccessKey: secretKey}
	provider := &KeyringProvider{Keyring: input.Keyring, Profile: input.Profile}

	if err := provider.Store(creds); err != nil {
		ui.Error.Fatal(err)
	}

	ui.Printf("Added credentials to profile %q in vault", input.Profile)

	sessions, err := NewKeyringSessions(input.Keyring)
	if err != nil {
		ui.Error.Fatal(err)
	}

	if n, _ := sessions.Delete(input.Profile); n > 0 {
		ui.Printf("Deleted %d existing sessions.", n)
	}
}
Exemplo n.º 3
0
func RemoveCommand(app *kingpin.Application, input RemoveCommandInput) {
	if !input.SessionsOnly {
		provider := &KeyringProvider{Keyring: input.Keyring, Profile: input.Profile}
		r, err := prompt.TerminalPrompt(fmt.Sprintf("Delete credentials for profile %q? (Y|n)", input.Profile))
		if err != nil {
			app.Fatalf(err.Error())
			return
		} else if r == "N" || r == "n" {
			return
		}

		if err := provider.Delete(); err != nil {
			app.Fatalf(err.Error())
			return
		}
		fmt.Printf("Deleted credentials.\n")
	}

	profiles, err := awsConfigFile.Parse()
	if err != nil {
		app.Fatalf("%v", err)
		return
	}

	sessions, err := NewKeyringSessions(input.Keyring, profiles)
	if err != nil {
		app.Fatalf(err.Error())
		return
	}

	n, err := sessions.Delete(input.Profile)
	if err != nil {
		app.Fatalf(err.Error())
		return
	}
	fmt.Printf("Deleted %d sessions.\n", n)
}