Merge pull request #12443 from influxdata/check_token_existance

fix(influx): return the error when token file already exists
pull/12456/head
kelwang 2019-03-07 20:37:15 -05:00 committed by GitHub
commit 81e15b7141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 4 deletions

View File

@ -62,6 +62,18 @@ func setupF(cmd *cobra.Command, args []string) error {
return fmt.Errorf("instance at %q has already been setup", flags.host)
}
dPath, dir, err := defaultTokenPath()
if err != nil {
return err
}
if _, err := os.Stat(dPath); err == nil {
return &platform.Error{
Code: platform.EConflict,
Msg: fmt.Sprintf("token already exists at %s", dPath),
}
}
req, err := onboardingRequest()
if err != nil {
return fmt.Errorf("failed to retrieve data to setup instance: %v", err)
@ -71,10 +83,7 @@ func setupF(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("failed to setup instance: %v", err)
}
dPath, dir, err := defaultTokenPath()
if err != nil {
return err
}
err = writeTokenToPath(result.Auth.Token, dPath, dir)
if err != nil {
return fmt.Errorf("failed to write token to path %q: %v", dPath, err)