mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 17:08:53 +00:00
Fix admin setup (#701)
Fixes a null pointer issue and clarifies setup logic.
This commit is contained in:
parent
665345c334
commit
596e017d44
1 changed files with 19 additions and 15 deletions
|
|
@ -47,23 +47,27 @@ func makeSetupEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return setupResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
if req.Admin == nil {
|
||||
return setupResponse{Err: errors.New("setup request must provide admin")}, nil
|
||||
}
|
||||
|
||||
// creating the user should be the last action. If there's a user
|
||||
// present and other errors occur, the setup endpoint closes.
|
||||
if req.Admin != nil {
|
||||
if *req.Admin.Email == "" {
|
||||
err := errors.Errorf("admin email cannot be empty")
|
||||
return setupResponse{Err: err}, nil
|
||||
}
|
||||
if *req.Admin.Password == "" {
|
||||
err := errors.Errorf("admin password cannot be empty")
|
||||
return setupResponse{Err: err}, nil
|
||||
}
|
||||
// Make the user an admin
|
||||
req.Admin.GlobalRole = null.StringFrom("admin")
|
||||
admin, err = svc.CreateUser(ctx, *req.Admin)
|
||||
if err != nil {
|
||||
return setupResponse{Err: err}, nil
|
||||
}
|
||||
adminPayload := *req.Admin
|
||||
if adminPayload.Email == nil || *adminPayload.Email == "" {
|
||||
err := errors.Errorf("admin email cannot be empty")
|
||||
return setupResponse{Err: err}, nil
|
||||
}
|
||||
if adminPayload.Password == nil || *adminPayload.Password == "" {
|
||||
err := errors.Errorf("admin password cannot be empty")
|
||||
return setupResponse{Err: err}, nil
|
||||
}
|
||||
// Make the user an admin
|
||||
adminPayload.GlobalRole = null.StringFrom("admin")
|
||||
admin, err = svc.CreateUser(ctx, adminPayload)
|
||||
if err != nil {
|
||||
return setupResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
// If everything works to this point, log the user in and return token. If
|
||||
|
|
|
|||
Loading…
Reference in a new issue