Skip to content

Commit

Permalink
refactor: PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
danxmoran committed Dec 2, 2020
1 parent ee68712 commit 8465857
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ want to use the default.
1. [20149](https://github.com/influxdata/influxdb/pull/20149): Enforce max value of 2147483647 on query queue size to avoid startup panic.
1. [20168](https://github.com/influxdata/influxdb/pull/20168): Auto-migrate existing DBRP mappings from old schema to avoid panic.
1. [20201](https://github.com/influxdata/influxdb/pull/20201): Optimize shard lookup in groups containing only one shard. Thanks @StoneYunZhao!
1. [20155](https://github.com/influxdata/influxdb/pull/20155): Respect the `--name` option in `influx setup` whether configs already exist or not.
1. [20155](https://github.com/influxdata/influxdb/pull/20155): Allow for 0 (infinite) values for `--retention` in `influx setup`.

## v2.0.2 [2020-11-19]

Expand Down
41 changes: 24 additions & 17 deletions cmd/influx/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,27 +141,13 @@ func setupF(cmd *cobra.Command, args []string) error {
return fmt.Errorf("instance at %q has already been setup", activeConfig.Host)
}

if _, err := os.Stat(dPath); err == nil {
existingConfigs, _ := localConfigSVC.ListConfigs()
if len(existingConfigs) > 0 {
// If there are existing configs then require that a name be
// spcified in order to distinguish this new config from what's
// there already.
if setupFlags.name == "" {
return errors.New("flag name is required if you already have existing configs")
}
if _, ok := existingConfigs[setupFlags.name]; ok {
return &influxdb.Error{
Code: influxdb.EConflict,
Msg: fmt.Sprintf("config name %q already existed", setupFlags.name),
}
}
}
if err := validateNoNameCollision(localConfigSVC, setupFlags.name); err != nil {
return err
}

req, err := onboardingRequest()
if err != nil {
return fmt.Errorf("failed to retrieve data to setup instance: %v", err)
return fmt.Errorf("failed to setup instance: %v", err)
}

result, err := s.OnboardInitialUser(context.Background(), req)
Expand Down Expand Up @@ -209,6 +195,27 @@ func setupF(cmd *cobra.Command, args []string) error {
return nil
}

// validateNoNameCollision asserts that there isn't already a local config with a given name.
func validateNoNameCollision(localConfigSvc config.Service, configName string) error {
existingConfigs, err := localConfigSvc.ListConfigs()
if err != nil {
return fmt.Errorf("error checking existing configs: %v", err)
}
if len(existingConfigs) == 0 {
return nil
}

// If there are existing configs then require that a name be
// specified in order to distinguish this new config from what's
// there already.
if configName == "" {
return errors.New("flag name is required if you already have existing configs")
}
if _, ok := existingConfigs[configName]; ok {
return fmt.Errorf("config name %q already exists", configName)
}
}

func isInteractive() bool {
return !setupFlags.force ||
setupFlags.username == "" ||
Expand Down

0 comments on commit 8465857

Please sign in to comment.