fix: improve error message when onboarding requests are missing data (#21849)

pull/21839/head
Daniel Moran 2021-07-14 15:52:19 -04:00 committed by GitHub
parent b1aa943e1b
commit ba8f91f1d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 29 deletions

View File

@ -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]

View File

@ -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",

View File

@ -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{}

View File

@ -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,
},
},
{