HasFirstUser returns whether the first user has been created.
(ctx context.Context)
| 500 | |
| 501 | // HasFirstUser returns whether the first user has been created. |
| 502 | func (c *Client) HasFirstUser(ctx context.Context) (bool, error) { |
| 503 | res, err := c.Request(ctx, http.MethodGet, "/api/v2/users/first", nil) |
| 504 | if err != nil { |
| 505 | return false, err |
| 506 | } |
| 507 | defer res.Body.Close() |
| 508 | |
| 509 | if res.StatusCode == http.StatusNotFound { |
| 510 | // ensure we are talking to coder and not |
| 511 | // some other service that returns 404 |
| 512 | v := res.Header.Get(BuildVersionHeader) |
| 513 | if v == "" { |
| 514 | return false, xerrors.Errorf("missing build version header, not a coder instance") |
| 515 | } |
| 516 | |
| 517 | return false, nil |
| 518 | } |
| 519 | if res.StatusCode != http.StatusOK { |
| 520 | return false, ReadBodyAsError(res) |
| 521 | } |
| 522 | return true, nil |
| 523 | } |
| 524 | |
| 525 | // CreateFirstUser attempts to create the first user on a Coder deployment. |
| 526 | // This initial user has superadmin privileges. If >0 users exist, this request will fail. |