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

Method newCreateAdminUserCommand

cli/server_createadminuser.go:26–297  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24)
25
26func (r *RootCmd) newCreateAdminUserCommand() *serpent.Command {
27 var (
28 newUserDBURL string
29 newUserPgAuth string
30 newUserSSHKeygenAlgorithm string
31 newUserUsername string
32 newUserEmail string
33 newUserPassword string
34 )
35 createAdminUserCommand := &serpent.Command{
36 Use: "create-admin-user",
37 Short: "Create a new admin user with the given username, email and password and adds it to every organization.",
38 Handler: func(inv *serpent.Invocation) error {
39 ctx := inv.Context()
40
41 sshKeygenAlgorithm, err := gitsshkey.ParseAlgorithm(newUserSSHKeygenAlgorithm)
42 if err != nil {
43 return xerrors.Errorf("parse ssh keygen algorithm %q: %w", newUserSSHKeygenAlgorithm, err)
44 }
45
46 cfg := r.createConfig()
47 logger := inv.Logger.AppendSinks(sloghuman.Sink(inv.Stderr))
48 if r.verbose {
49 logger = logger.Leveled(slog.LevelDebug)
50 }
51
52 ctx, cancel := inv.SignalNotifyContext(ctx, StopSignals...)
53 defer cancel()
54
55 if newUserDBURL == "" {
56 cliui.Infof(inv.Stdout, "Using built-in PostgreSQL (%s)", cfg.PostgresPath())
57 url, closePg, err := startBuiltinPostgres(ctx, cfg, logger, "")
58 if err != nil {
59 return err
60 }
61 defer func() {
62 _ = closePg()
63 }()
64 newUserDBURL = url
65 }
66
67 sqlDriver := "postgres"
68 if codersdk.PostgresAuth(newUserPgAuth) == codersdk.PostgresAuthAWSIAMRDS {
69 sqlDriver, err = awsiamrds.Register(inv.Context(), sqlDriver)
70 if err != nil {
71 return xerrors.Errorf("register aws rds iam auth: %w", err)
72 }
73 }
74
75 sqlDB, err := ConnectToPostgres(ctx, logger, sqlDriver, newUserDBURL, nil)
76 if err != nil {
77 return xerrors.Errorf("connect to postgres: %w", err)
78 }
79 defer func() {
80 _ = sqlDB.Close()
81 }()
82 db := database.New(sqlDB)
83

Callers 1

ServerMethod · 0.95

Calls 15

createConfigMethod · 0.95
ParseAlgorithmFunction · 0.92
InfofFunction · 0.92
PostgresAuthTypeAlias · 0.92
RegisterFunction · 0.92
NewFunction · 0.92
PromptFunction · 0.92
HashFunction · 0.92
NowFunction · 0.92
RoleOwnerFunction · 0.92
GenerateFunction · 0.92
RoleOrgAdminFunction · 0.92

Tested by

no test coverage detected