diff --git a/CHANGELOG.md b/CHANGELOG.md index 483112c2d7..8f8ac772e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ This release adds an embedded SQLite database for storing metadata required by t 1. [21800](https://github.com/influxdata/influxdb/pull/21800): Return an error instead of panicking when InfluxQL statement rewrites fail. 1. [21840](https://github.com/influxdata/influxdb/pull/21840): Run migrations on restored bolt & SQLite metadata databases as part of the restore process. 1. [21844](https://github.com/influxdata/influxdb/pull/21844): Upgrade to latest version of `influxdata/cron` so that tasks can be created with interval of `every: 1w`. +1. [21849](https://github.com/influxdata/influxdb/pull/21849): Specify which fields are missing when rejecting an incomplete onboarding request. ## v2.0.7 [2021-06-04] diff --git a/tenant/error.go b/tenant/error.go index ee9beb04f0..90ec96cb03 100644 --- a/tenant/error.go +++ b/tenant/error.go @@ -34,11 +34,6 @@ var ( Msg: "onboarding has already been completed", } - ErrOnboardInvalid = &errors.Error{ - Code: errors.EEmptyValue, - Msg: "onboard failed, missing value", - } - ErrNotFound = &errors.Error{ Code: errors.ENotFound, Msg: "not found", diff --git a/tenant/service_onboarding.go b/tenant/service_onboarding.go index 09acf1b806..18988c5015 100644 --- a/tenant/service_onboarding.go +++ b/tenant/service_onboarding.go @@ -3,8 +3,10 @@ package tenant import ( "context" "fmt" + "strings" "github.com/influxdata/influxdb/v2/kit/platform" + "github.com/influxdata/influxdb/v2/kit/platform/errors" "github.com/influxdata/influxdb/v2" icontext "github.com/influxdata/influxdb/v2/context" @@ -85,8 +87,28 @@ func (s *OnboardService) OnboardInitialUser(ctx context.Context, req *influxdb.O // onboardUser allows us to onboard new users. func (s *OnboardService) onboardUser(ctx context.Context, req *influxdb.OnboardingRequest, permFn func(orgID, userID platform.ID) []influxdb.Permission) (*influxdb.OnboardingResults, error) { - if req == nil || req.User == "" || req.Org == "" || req.Bucket == "" { - return nil, ErrOnboardInvalid + if req == nil { + return nil, &errors.Error{ + Code: errors.EEmptyValue, + Msg: "onboarding failed: no request body provided", + } + } + + var missingFields []string + if req.User == "" { + missingFields = append(missingFields, "username") + } + if req.Org == "" { + missingFields = append(missingFields, "org") + } + if req.Bucket == "" { + missingFields = append(missingFields, "bucket") + } + if len(missingFields) > 0 { + return nil, &errors.Error{ + Code: errors.EUnprocessableEntity, + Msg: fmt.Sprintf("onboarding failed: missing required fields [%s]", strings.Join(missingFields, ",")), + } } result := &influxdb.OnboardingResults{} diff --git a/testing/onboarding.go b/testing/onboarding.go index c91048d5bd..12bccce4ad 100644 --- a/testing/onboarding.go +++ b/testing/onboarding.go @@ -85,7 +85,7 @@ func OnboardInitialUser( }, }, wants: wants{ - errCode: errors.EEmptyValue, + errCode: errors.EUnprocessableEntity, }, }, { @@ -104,7 +104,7 @@ func OnboardInitialUser( }, }, wants: wants{ - errCode: errors.EEmptyValue, + errCode: errors.EUnprocessableEntity, }, }, { @@ -123,26 +123,7 @@ func OnboardInitialUser( }, }, wants: wants{ - errCode: errors.EEmptyValue, - }, - }, - { - name: "missing password should fail", - fields: OnboardingFields{ - IDGenerator: &loopIDGenerator{ - s: []string{oneID, twoID, threeID, fourID}, - }, - TokenGenerator: mock.NewTokenGenerator(oneToken, nil), - IsOnboarding: true, - }, - args: args{ - request: &platform.OnboardingRequest{ - User: "admin", - Org: "org1", - }, - }, - wants: wants{ - errCode: errors.EEmptyValue, + errCode: errors.EUnprocessableEntity, }, }, {