- Notifications
You must be signed in to change notification settings - Fork913
fix: make template push a superset of template create#11299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
7ce08a1
675feb0
06618d7
95d1a36
7dd63a8
4443322
82b143b
19a4dfc
5a2aa6a
4ce4ddb
39ed2cd
2ad127b
f715efc
6269898
d1cf919
6bcc688
a5ac9b7
132efda
9da9aed
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package cli | ||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io" | ||
@@ -46,39 +47,22 @@ func (r *RootCmd) templateCreate() *clibase.Cmd { | ||
r.InitClient(client), | ||
), | ||
Handler: func(inv *clibase.Invocation) error { | ||
_, _ = fmt.Fprintln(inv.Stdout, "\n"+pretty.Sprint(cliui.DefaultStyles.Wrap, | ||
pretty.Sprint( | ||
cliui.DefaultStyles.Warn, "DEPRECATION WARNING: The `coder templates push` command should be used instead. This command will be removed in a future release. ")+"\n")) | ||
time.Sleep(1 * time.Second) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Love the sleep-based incentive, but we should tell the user that it's sleeping for a moment in the deprecation message so that the user doesn't just think our CLI is slow. | ||
err := checkTemplateCreateEntitlements(inv.Context(), checkTemplateCreateEntitlementsArgs{ | ||
client: client, | ||
requireActiveVersion: requireActiveVersion, | ||
defaultTTL: defaultTTL, | ||
failureTTL: failureTTL, | ||
dormancyThreshold: dormancyThreshold, | ||
dormancyAutoDeletion: dormancyAutoDeletion, | ||
maxTTL: maxTTL, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
organization, err := CurrentOrganization(inv, client) | ||
@@ -357,3 +341,52 @@ func ParseProvisionerTags(rawTags []string) (map[string]string, error) { | ||
} | ||
return tags, nil | ||
} | ||
type checkTemplateCreateEntitlementsArgs struct { | ||
client *codersdk.Client | ||
requireActiveVersion bool | ||
defaultTTL time.Duration | ||
failureTTL time.Duration | ||
dormancyThreshold time.Duration | ||
dormancyAutoDeletion time.Duration | ||
maxTTL time.Duration | ||
} | ||
func checkTemplateCreateEntitlements(ctx context.Context, args checkTemplateCreateEntitlementsArgs) error { | ||
isTemplateSchedulingOptionsSet := args.failureTTL != 0 || args.dormancyThreshold != 0 || args.dormancyAutoDeletion != 0 || args.maxTTL != 0 | ||
if isTemplateSchedulingOptionsSet || args.requireActiveVersion { | ||
if args.failureTTL != 0 || args.dormancyThreshold != 0 || args.dormancyAutoDeletion != 0 { | ||
// This call can be removed when workspace_actions is no longer experimental | ||
experiments, exErr := args.client.Experiments(ctx) | ||
if exErr != nil { | ||
return xerrors.Errorf("get experiments: %w", exErr) | ||
} | ||
if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. | ||
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.") | ||
} | ||
} | ||
entitlements, err := args.client.Entitlements(ctx) | ||
if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusNotFound { | ||
return xerrors.Errorf("your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags") | ||
} else if err != nil { | ||
return xerrors.Errorf("get entitlements: %w", err) | ||
} | ||
if isTemplateSchedulingOptionsSet { | ||
if !entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled { | ||
return xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --failure-ttl, --inactivity-ttl, or --max-ttl") | ||
} | ||
} | ||
if args.requireActiveVersion { | ||
if !entitlements.Features[codersdk.FeatureAccessControl].Enabled { | ||
return xerrors.Errorf("your license is not entitled to use enterprise access control, so you cannot set --require-active-version") | ||
} | ||
} | ||
} | ||
return nil | ||
} |
Uh oh!
There was an error while loading.Please reload this page.