-
Notifications
You must be signed in to change notification settings - Fork 928
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7ce08a1
fix: make template push a superset of template create
f0ssel 675feb0
add back work dir
f0ssel 06618d7
add groupacl
f0ssel 95d1a36
Add back workdir
f0ssel 7dd63a8
combine edit flags
f0ssel 4443322
fix edit
f0ssel 82b143b
unify edit and push
f0ssel 19a4dfc
make gen
f0ssel 5a2aa6a
fix test
f0ssel 4ce4ddb
make gen
f0ssel 39ed2cd
update golden
f0ssel 2ad127b
fix tests:
f0ssel f715efc
fix merge
f0ssel 6269898
add test
f0ssel d1cf919
remove test
f0ssel 6bcc688
add unset test
f0ssel a5ac9b7
Add deprecation warning
f0ssel 132efda
fix
f0ssel 9da9aed
rename functions
f0ssel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
isTemplateSchedulingOptionsSet := failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0 || maxTTL != 0 | ||
|
||
if isTemplateSchedulingOptionsSet || requireActiveVersion { | ||
if failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0 { | ||
// This call can be removed when workspace_actions is no longer experimental | ||
experiments, exErr := client.Experiments(inv.Context()) | ||
if exErr != nil { | ||
return xerrors.Errorf("get experiments: %w", exErr) | ||
} | ||
|
||
if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) { | ||
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 := client.Entitlements(inv.Context()) | ||
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 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") | ||
} | ||
} | ||
_, _ = 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) | ||
|
||
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.