()
| 36 | ) |
| 37 | |
| 38 | func (r *RootCmd) provisionerDaemonStart() *serpent.Command { |
| 39 | var ( |
| 40 | cacheDir string |
| 41 | logHuman string |
| 42 | logJSON string |
| 43 | logStackdriver string |
| 44 | logFilter []string |
| 45 | name string |
| 46 | rawTags []string |
| 47 | pollInterval time.Duration |
| 48 | pollJitter time.Duration |
| 49 | preSharedKey string |
| 50 | provisionerKey string |
| 51 | verbose bool |
| 52 | experiments []string |
| 53 | |
| 54 | prometheusEnable bool |
| 55 | prometheusAddress string |
| 56 | ) |
| 57 | orgContext := agpl.NewOrganizationContext() |
| 58 | cmd := &serpent.Command{ |
| 59 | Use: "start", |
| 60 | Short: "Run a provisioner daemon", |
| 61 | Handler: func(inv *serpent.Invocation) error { |
| 62 | ctx, cancel := context.WithCancel(inv.Context()) |
| 63 | defer cancel() |
| 64 | client, err := r.InitClient(inv) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | stopCtx, stopCancel := inv.SignalNotifyContext(ctx, agpl.StopSignalsNoInterrupt...) |
| 70 | defer stopCancel() |
| 71 | interruptCtx, interruptCancel := inv.SignalNotifyContext(ctx, agpl.InterruptSignals...) |
| 72 | defer interruptCancel() |
| 73 | |
| 74 | orgID := uuid.Nil |
| 75 | if preSharedKey == "" && provisionerKey == "" { |
| 76 | // We can only select an organization if using user auth |
| 77 | org, err := orgContext.Selected(inv, client) |
| 78 | if err != nil { |
| 79 | var cErr *codersdk.Error |
| 80 | if !errors.As(err, &cErr) || cErr.StatusCode() != http.StatusUnauthorized { |
| 81 | return xerrors.Errorf("current organization: %w", err) |
| 82 | } |
| 83 | |
| 84 | return xerrors.New("must provide a pre-shared key or provisioner key when not authenticated as a user") |
| 85 | } |
| 86 | |
| 87 | orgID = org.ID |
| 88 | } else if orgContext.FlagSelect != "" { |
| 89 | return xerrors.New("cannot provide --org value with --psk or --key flags") |
| 90 | } |
| 91 | |
| 92 | if provisionerKey != "" { |
| 93 | if preSharedKey != "" { |
| 94 | return xerrors.New("cannot provide both provisioner key --key and pre-shared key --psk") |
| 95 | } |
no test coverage detected