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

Function RequireAdmin

cli/exp_scaletest.go:476–498  ·  view source on GitHub ↗
(ctx context.Context, client *codersdk.Client)

Source from the content-addressed store, hash-verified

474}
475
476func RequireAdmin(ctx context.Context, client *codersdk.Client) (codersdk.User, error) {
477 me, err := client.User(ctx, codersdk.Me)
478 if err != nil {
479 return codersdk.User{}, xerrors.Errorf("fetch current user: %w", err)
480 }
481
482 // Only owners can do scaletests. This isn't a very strong check but there's
483 // not much else we can do. Ratelimits are enforced for non-owners so
484 // hopefully that limits the damage if someone disables this check and runs
485 // it against a non-owner account on a production deployment.
486 ok := false
487 for _, role := range me.Roles {
488 if role.Name == "owner" {
489 ok = true
490 break
491 }
492 }
493 if !ok {
494 return me, xerrors.Errorf("Not logged in as a site owner. Scale testing is only available to site owners.")
495 }
496
497 return me, nil
498}
499
500// userCleanupRunner is a runner that deletes a user in the Run phase.
501type userCleanupRunner struct {

Callers 11

scaletestChatMethod · 0.85
scaletestTaskStatusMethod · 0.85
scaletestBridgeMethod · 0.85
scaletestPrebuildsMethod · 0.85
scaletestCleanupMethod · 0.85
scaletestAutostartMethod · 0.85

Calls 2

UserMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected