Skip to content

Commit a3fdb76

Browse files
committed
test removing flags
1 parent 4abf179 commit a3fdb76

File tree

3 files changed

+107
-544
lines changed

3 files changed

+107
-544
lines changed

cli/templatecreate.go

Lines changed: 2 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package cli
22

33
import (
4-
"context"
54
"errors"
65
"fmt"
76
"io"
8-
"net/http"
97
"strings"
108
"time"
119
"unicode/utf8"
@@ -17,7 +15,6 @@ import (
1715

1816
"github.com/coder/coder/v2/cli/clibase"
1917
"github.com/coder/coder/v2/cli/cliui"
20-
"github.com/coder/coder/v2/coderd/util/ptr"
2118
"github.com/coder/coder/v2/codersdk"
2219
)
2320

@@ -27,14 +24,6 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
2724
provisionerTags []string
2825
variablesFile string
2926
commandLineVariables []string
30-
disableEveryone bool
31-
requireActiveVersion bool
32-
33-
defaultTTL time.Duration
34-
failureTTL time.Duration
35-
dormancyThreshold time.Duration
36-
dormancyAutoDeletion time.Duration
37-
maxTTL time.Duration
3827

3928
uploadFlags templateUploadFlags
4029
)
@@ -52,19 +41,6 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
5241
cliui.DefaultStyles.Warn, "DEPRECATION WARNING: The `coder templates push` command should be used instead. This command will be removed in a future release. ")+"\n"))
5342
time.Sleep(1 * time.Second)
5443

55-
err := checkTemplateCreateEntitlements(inv.Context(), checkTemplateCreateEntitlementsArgs{
56-
client: client,
57-
requireActiveVersion: requireActiveVersion,
58-
defaultTTL: defaultTTL,
59-
failureTTL: failureTTL,
60-
dormancyThreshold: dormancyThreshold,
61-
dormancyAutoDeletion: dormancyAutoDeletion,
62-
maxTTL: maxTTL,
63-
})
64-
if err != nil {
65-
return err
66-
}
67-
6844
organization, err := CurrentOrganization(inv, client)
6945
if err != nil {
7046
return err
@@ -133,15 +109,8 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
133109
}
134110

135111
createReq := codersdk.CreateTemplateRequest{
136-
Name: templateName,
137-
VersionID: job.ID,
138-
DefaultTTLMillis: ptr.Ref(defaultTTL.Milliseconds()),
139-
FailureTTLMillis: ptr.Ref(failureTTL.Milliseconds()),
140-
MaxTTLMillis: ptr.Ref(maxTTL.Milliseconds()),
141-
TimeTilDormantMillis: ptr.Ref(dormancyThreshold.Milliseconds()),
142-
TimeTilDormantAutoDeleteMillis: ptr.Ref(dormancyAutoDeletion.Milliseconds()),
143-
DisableEveryoneGroupAccess: disableEveryone,
144-
RequireActiveVersion: requireActiveVersion,
112+
Name: templateName,
113+
VersionID: job.ID,
145114
}
146115

147116
_, err = client.CreateTemplate(inv.Context(), organization.ID, createReq)
@@ -162,12 +131,6 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
162131
},
163132
}
164133
cmd.Options = clibase.OptionSet{
165-
{
166-
Flag: "private",
167-
Description: "Disable the default behavior of granting template access to the 'everyone' group. " +
168-
"The template permissions must be updated to allow non-admin users to use this template.",
169-
Value: clibase.BoolOf(&disableEveryone),
170-
},
171134
{
172135
Flag: "variables-file",
173136
Description: "Specify a file path with values for Terraform-managed variables.",
@@ -188,49 +151,13 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
188151
Description: "Specify a set of tags to target provisioner daemons.",
189152
Value: clibase.StringArrayOf(&provisionerTags),
190153
},
191-
{
192-
Flag: "default-ttl",
193-
Description: "Specify a default TTL for workspaces created from this template. It is the default time before shutdown - workspaces created from this template default to this value. Maps to \"Default autostop\" in the UI.",
194-
Default: "24h",
195-
Value: clibase.DurationOf(&defaultTTL),
196-
},
197-
{
198-
Flag: "failure-ttl",
199-
Description: "Specify a failure TTL for workspaces created from this template. It is the amount of time after a failed \"start\" build before coder automatically schedules a \"stop\" build to cleanup.This licensed feature's default is 0h (off). Maps to \"Failure cleanup\"in the UI.",
200-
Default: "0h",
201-
Value: clibase.DurationOf(&failureTTL),
202-
},
203-
{
204-
Flag: "dormancy-threshold",
205-
Description: "Specify a duration workspaces may be inactive prior to being moved to the dormant state. This licensed feature's default is 0h (off). Maps to \"Dormancy threshold\" in the UI.",
206-
Default: "0h",
207-
Value: clibase.DurationOf(&dormancyThreshold),
208-
},
209-
{
210-
Flag: "dormancy-auto-deletion",
211-
Description: "Specify a duration workspaces may be in the dormant state prior to being deleted. This licensed feature's default is 0h (off). Maps to \"Dormancy Auto-Deletion\" in the UI.",
212-
Default: "0h",
213-
Value: clibase.DurationOf(&dormancyAutoDeletion),
214-
},
215-
216-
{
217-
Flag: "max-ttl",
218-
Description: "Edit the template maximum time before shutdown - workspaces created from this template must shutdown within the given duration after starting. This is an enterprise-only feature.",
219-
Value: clibase.DurationOf(&maxTTL),
220-
},
221154
{
222155
Flag: "test.provisioner",
223156
Description: "Customize the provisioner backend.",
224157
Default: "terraform",
225158
Value: clibase.StringOf(&provisioner),
226159
Hidden: true,
227160
},
228-
{
229-
Flag: "require-active-version",
230-
Description: "Requires workspace builds to use the active template version. This setting does not apply to template admins. This is an enterprise-only feature.",
231-
Value: clibase.BoolOf(&requireActiveVersion),
232-
Default: "false",
233-
},
234161

235162
cliui.SkipPromptOption(),
236163
}
@@ -341,52 +268,3 @@ func ParseProvisionerTags(rawTags []string) (map[string]string, error) {
341268
}
342269
return tags, nil
343270
}
344-
345-
type checkTemplateCreateEntitlementsArgs struct {
346-
client *codersdk.Client
347-
requireActiveVersion bool
348-
defaultTTL time.Duration
349-
failureTTL time.Duration
350-
dormancyThreshold time.Duration
351-
dormancyAutoDeletion time.Duration
352-
maxTTL time.Duration
353-
}
354-
355-
func checkTemplateCreateEntitlements(ctx context.Context, args checkTemplateCreateEntitlementsArgs) error {
356-
isTemplateSchedulingOptionsSet := args.failureTTL != 0 || args.dormancyThreshold != 0 || args.dormancyAutoDeletion != 0 || args.maxTTL != 0
357-
358-
if isTemplateSchedulingOptionsSet || args.requireActiveVersion {
359-
if args.failureTTL != 0 || args.dormancyThreshold != 0 || args.dormancyAutoDeletion != 0 {
360-
// This call can be removed when workspace_actions is no longer experimental
361-
experiments, exErr := args.client.Experiments(ctx)
362-
if exErr != nil {
363-
return xerrors.Errorf("get experiments: %w", exErr)
364-
}
365-
366-
if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) {
367-
return xerrors.Errorf("--failure-ttl, --dormancy-threshold, and --dormancy-auto-deletion are experimental features. Use the workspace_actions CODER_EXPERIMENTS flag to set these configuration values.")
368-
}
369-
}
370-
371-
entitlements, err := args.client.Entitlements(ctx)
372-
if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusNotFound {
373-
return xerrors.Errorf("your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags")
374-
} else if err != nil {
375-
return xerrors.Errorf("get entitlements: %w", err)
376-
}
377-
378-
if isTemplateSchedulingOptionsSet {
379-
if !entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled {
380-
return xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, --inactivity-ttl, or --max-ttl")
381-
}
382-
}
383-
384-
if args.requireActiveVersion {
385-
if !entitlements.Features[codersdk.FeatureAccessControl].Enabled {
386-
return xerrors.Errorf("your license is not entitled to use enterprise access control, so you cannot set --require-active-version")
387-
}
388-
}
389-
}
390-
391-
return nil
392-
}

0 commit comments

Comments
 (0)