()
| 15 | ) |
| 16 | |
| 17 | func (r *RootCmd) templateEdit() *serpent.Command { |
| 18 | const deprecatedFlagName = "deprecated" |
| 19 | var ( |
| 20 | name string |
| 21 | displayName string |
| 22 | description string |
| 23 | icon string |
| 24 | defaultTTL time.Duration |
| 25 | activityBump time.Duration |
| 26 | autostopRequirementDaysOfWeek []string |
| 27 | autostopRequirementWeeks int64 |
| 28 | autostartRequirementDaysOfWeek []string |
| 29 | failureTTL time.Duration |
| 30 | dormancyThreshold time.Duration |
| 31 | dormancyAutoDeletion time.Duration |
| 32 | allowUserCancelWorkspaceJobs bool |
| 33 | allowUserAutostart bool |
| 34 | allowUserAutostop bool |
| 35 | requireActiveVersion bool |
| 36 | deprecationMessage string |
| 37 | disableEveryone bool |
| 38 | orgContext = NewOrganizationContext() |
| 39 | ) |
| 40 | |
| 41 | cmd := &serpent.Command{ |
| 42 | Use: "edit <template>", |
| 43 | Middleware: serpent.Chain( |
| 44 | serpent.RequireNArgs(1), |
| 45 | ), |
| 46 | Short: "Edit the metadata of a template by name.", |
| 47 | Handler: func(inv *serpent.Invocation) error { |
| 48 | client, err := r.InitClient(inv) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | unsetAutostopRequirementDaysOfWeek := len(autostopRequirementDaysOfWeek) == 1 && autostopRequirementDaysOfWeek[0] == "none" |
| 53 | requiresScheduling := (len(autostopRequirementDaysOfWeek) > 0 && !unsetAutostopRequirementDaysOfWeek) || |
| 54 | autostopRequirementWeeks > 0 || |
| 55 | !allowUserAutostart || |
| 56 | !allowUserAutostop || |
| 57 | failureTTL != 0 || |
| 58 | dormancyThreshold != 0 || |
| 59 | dormancyAutoDeletion != 0 || |
| 60 | len(autostartRequirementDaysOfWeek) > 0 |
| 61 | |
| 62 | requiresEntitlement := requiresScheduling || requireActiveVersion |
| 63 | if requiresEntitlement { |
| 64 | entitlements, err := client.Entitlements(inv.Context()) |
| 65 | if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusNotFound { |
| 66 | return xerrors.Errorf("your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags") |
| 67 | } else if err != nil { |
| 68 | return xerrors.Errorf("get entitlements: %w", err) |
| 69 | } |
| 70 | |
| 71 | if requiresScheduling && !entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled { |
| 72 | return xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, --inactivityTTL, --allow-user-autostart=false or --allow-user-autostop=false") |
| 73 | } |
| 74 |
no test coverage detected