MCPcopy Index your code
hub / github.com/coder/coder / HasFirstUser

Method HasFirstUser

codersdk/users.go:502–523  ·  view source on GitHub ↗

HasFirstUser returns whether the first user has been created.

(ctx context.Context)

Source from the content-addressed store, hash-verified

500
501// HasFirstUser returns whether the first user has been created.
502func (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.

Callers 4

TestServerFunction · 0.95
TestFirstUserFunction · 0.80
loginMethod · 0.80
setupFirstUserFunction · 0.80

Calls 5

RequestMethod · 0.95
ReadBodyAsErrorFunction · 0.85
CloseMethod · 0.65
GetMethod · 0.65
ErrorfMethod · 0.45

Tested by 2

TestServerFunction · 0.76
TestFirstUserFunction · 0.64