Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: deprecate template create command in favor of template push#11390

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

Merged
f0ssel merged 43 commits intomainfromf0ssel/templatepush-2
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
43 commits
Select commitHold shift + click to select a range
0cc46c8
fix: make template push a superset of template create
f0sselDec 20, 2023
93da7d0
add back work dir
f0sselDec 20, 2023
3c409f6
add groupacl
f0sselDec 20, 2023
4b763d7
Add back workdir
f0sselDec 20, 2023
d178cc7
combine edit flags
f0sselDec 20, 2023
5474942
fix edit
f0sselDec 20, 2023
2b9bcf6
unify edit and push
f0sselDec 20, 2023
44f264b
make gen
f0sselDec 20, 2023
d58cf18
fix test
f0sselDec 21, 2023
9b32922
make gen
f0sselDec 21, 2023
c6ef6f4
update golden
f0sselDec 21, 2023
e1e1653
fix tests:
f0sselDec 21, 2023
0cdefbc
fix merge
f0sselDec 21, 2023
d2a7866
add test
f0sselDec 22, 2023
63d57fd
remove test
f0sselDec 22, 2023
ca65869
add unset test
f0sselDec 22, 2023
9866235
Add deprecation warning
f0sselDec 22, 2023
35c7adf
fix
f0sselDec 22, 2023
4abf179
rename functions
f0sselJan 2, 2024
a3fdb76
test removing flags
f0sselJan 3, 2024
7599090
revert
f0sselJan 3, 2024
e958e1a
cleanup
f0sselJan 3, 2024
c8cae6c
add back flag
f0sselJan 3, 2024
1b03e89
remove create command
f0sselJan 4, 2024
8918cda
make gen
f0sselJan 4, 2024
7d2a7ac
fix gen
f0sselJan 4, 2024
5b2792d
add private flag to template edit
f0sselJan 4, 2024
b85a73c
fix test
f0sselJan 4, 2024
7655bc9
fix golden
f0sselJan 4, 2024
2f2911a
update mentions of templates create command
f0sselJan 4, 2024
5334e8e
update golden
f0sselJan 4, 2024
79c0c02
add removal comment
f0sselJan 4, 2024
2dfb98e
Add back create
f0sselJan 4, 2024
cb0aec4
fix formatting
f0sselJan 4, 2024
d1f13d1
add disableeveryonegroupaccess test
f0sselJan 4, 2024
5792279
update test
f0sselJan 5, 2024
2e54259
fix test lint
f0sselJan 5, 2024
de78f4b
pr comments
f0sselJan 5, 2024
0c859bc
fix text formatting
f0sselJan 5, 2024
b65ab81
Add deprecation to help text
f0sselJan 5, 2024
77c9edf
fix template push wording
f0sselJan 5, 2024
13794fd
golden
f0sselJan 5, 2024
8355850
fix gen again
f0sselJan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
combine edit flags
  • Loading branch information
@f0ssel
f0ssel committedJan 5, 2024
commitd178cc7435004fb3e5a948713a9f2fb8e2898002
6 changes: 5 additions & 1 deletioncli/templatecreate.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,6 +47,7 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
r.InitClient(client),
),
Handler: func(inv *clibase.Invocation) error {
<<<<<<< HEAD
<<<<<<< HEAD
isTemplateSchedulingOptionsSet := failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0 || maxTTL != 0

Expand DownExpand Up@@ -83,6 +84,9 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
}
=======
err := handleEntitlements(inv.Context(), handleEntitlementsArgs{
=======
err := createEntitlementsCheck(inv.Context(), handleEntitlementsArgs{
>>>>>>> 3c377e5d3 (combine edit flags)
client: client,
requireActiveVersion: requireActiveVersion,
defaultTTL: defaultTTL,
Expand DownExpand Up@@ -383,7 +387,7 @@ type handleEntitlementsArgs struct {
maxTTL time.Duration
}

funchandleEntitlements(ctx context.Context, args handleEntitlementsArgs) error {
funccreateEntitlementsCheck(ctx context.Context, args handleEntitlementsArgs) error {
isTemplateSchedulingOptionsSet := args.failureTTL != 0 || args.dormancyThreshold != 0 || args.dormancyAutoDeletion != 0 || args.maxTTL != 0

if isTemplateSchedulingOptionsSet || args.requireActiveVersion {
Expand Down
280 changes: 218 additions & 62 deletionscli/templateedit.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
package cli

import (
"context"
"fmt"
"net/http"
"strings"
Expand DownExpand Up@@ -46,6 +47,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
),
Short: "Edit the metadata of a template by name.",
Handler: func(inv *clibase.Invocation) error {
<<<<<<< HEAD
// This clause can be removed when workspace_actions is no longer experimental
if failureTTL != 0 || dormancyThreshold != 0 || dormancyAutoDeletion != 0 {
experiments, exErr := client.Experiments(inv.Context())
Expand DownExpand Up@@ -89,6 +91,8 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
}
}

=======
>>>>>>> 3c377e5d3 (combine edit flags)
organization, err := CurrentOrganization(inv, client)
if err != nil {
return xerrors.Errorf("get current organization: %w", err)
Expand All@@ -98,71 +102,55 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
return xerrors.Errorf("get workspace template: %w", err)
}

// Copy the default value if the list is empty, or if the user
// specified the "none" value clear the list.
if len(autostopRequirementDaysOfWeek) == 0 {
autostopRequirementDaysOfWeek = template.AutostopRequirement.DaysOfWeek
}
if len(autostartRequirementDaysOfWeek) == 1 && autostartRequirementDaysOfWeek[0] == "all" {
// Set it to every day of the week
autostartRequirementDaysOfWeek = []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}
} else if len(autostartRequirementDaysOfWeek) == 0 {
autostartRequirementDaysOfWeek = template.AutostartRequirement.DaysOfWeek
}
if unsetAutostopRequirementDaysOfWeek {
autostopRequirementDaysOfWeek = []string{}
}
if failureTTL == 0 {
failureTTL = time.Duration(template.FailureTTLMillis) * time.Millisecond
}
if dormancyThreshold == 0 {
dormancyThreshold = time.Duration(template.TimeTilDormantMillis) * time.Millisecond
}
if dormancyAutoDeletion == 0 {
dormancyAutoDeletion = time.Duration(template.TimeTilDormantAutoDeleteMillis) * time.Millisecond
}

// Default values
if !userSetOption(inv, "description") {
description = template.Description
}
unsetAutostopRequirementDaysOfWeek, err := editTemplateEntitlementsCheck(inv.Context(), editTemplateEntitlementsArgs{
client: client,
inv: inv,
template: template,

if !userSetOption(inv, "icon") {
icon = template.Icon
}
name: name,
displayName: displayName,
description: description,
icon: icon,
defaultTTL: defaultTTL,
maxTTL: maxTTL,
autostopRequirementDaysOfWeek: autostopRequirementDaysOfWeek,
autostopRequirementWeeks: autostopRequirementWeeks,
autostartRequirementDaysOfWeek: autostartRequirementDaysOfWeek,
failureTTL: failureTTL,
dormancyThreshold: dormancyThreshold,
dormancyAutoDeletion: dormancyAutoDeletion,
allowUserCancelWorkspaceJobs: allowUserCancelWorkspaceJobs,
allowUserAutostart: allowUserAutostart,
allowUserAutostop: allowUserAutostop,
requireActiveVersion: requireActiveVersion,
deprecationMessage: deprecationMessage,
disableEveryone: false, // TODO: Add new flag
})

if !userSetOption(inv, "display-name") {
displayName = template.DisplayName
}
req := updateTemplateMetaRequest(updateTemplateMetaArgs{
client: client,
inv: inv,
template: template,
unsetAutostopRequirementDaysOfWeek: unsetAutostopRequirementDaysOfWeek,

var deprecated *string
if !userSetOption(inv, "deprecated") {
deprecated = &deprecationMessage
}

req := codersdk.UpdateTemplateMeta{
Name: name,
DisplayName: displayName,
Description: description,
Icon: icon,
DefaultTTLMillis: defaultTTL.Milliseconds(),
MaxTTLMillis: maxTTL.Milliseconds(),
AutostopRequirement: &codersdk.TemplateAutostopRequirement{
DaysOfWeek: autostopRequirementDaysOfWeek,
Weeks: autostopRequirementWeeks,
},
AutostartRequirement: &codersdk.TemplateAutostartRequirement{
DaysOfWeek: autostartRequirementDaysOfWeek,
},
FailureTTLMillis: failureTTL.Milliseconds(),
TimeTilDormantMillis: dormancyThreshold.Milliseconds(),
TimeTilDormantAutoDeleteMillis: dormancyAutoDeletion.Milliseconds(),
AllowUserCancelWorkspaceJobs: allowUserCancelWorkspaceJobs,
AllowUserAutostart: allowUserAutostart,
AllowUserAutostop: allowUserAutostop,
RequireActiveVersion: requireActiveVersion,
DeprecationMessage: deprecated,
}
name: name,
displayName: displayName,
description: description,
icon: icon,
defaultTTL: defaultTTL,
maxTTL: maxTTL,
autostopRequirementDaysOfWeek: autostopRequirementDaysOfWeek,
autostopRequirementWeeks: autostopRequirementWeeks,
autostartRequirementDaysOfWeek: autostartRequirementDaysOfWeek,
failureTTL: failureTTL,
dormancyThreshold: dormancyThreshold,
dormancyAutoDeletion: dormancyAutoDeletion,
allowUserCancelWorkspaceJobs: allowUserCancelWorkspaceJobs,
allowUserAutostart: allowUserAutostart,
allowUserAutostop: allowUserAutostop,
requireActiveVersion: requireActiveVersion,
deprecationMessage: deprecationMessage,
})

_, err = client.UpdateTemplateMeta(inv.Context(), template.ID, req)
if err != nil {
Expand DownExpand Up@@ -297,3 +285,171 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {

return cmd
}

type editTemplateEntitlementsArgs struct {
client *codersdk.Client
inv *clibase.Invocation

defaultTTL time.Duration
maxTTL time.Duration
autostopRequirementDaysOfWeek []string
autostopRequirementWeeks int64
autostartRequirementDaysOfWeek []string
failureTTL time.Duration
dormancyThreshold time.Duration
dormancyAutoDeletion time.Duration
allowUserCancelWorkspaceJobs bool
allowUserAutostart bool
allowUserAutostop bool
requireActiveVersion bool
}

func editTemplateEntitlementsCheck(ctx context.Context, args editTemplateEntitlementsArgs) (bool, error) {
// This clause can be removed when workspace_actions is no longer experimental
if args.failureTTL != 0 || args.dormancyThreshold != 0 || args.dormancyAutoDeletion != 0 {
experiments, exErr := args.client.Experiments(ctx)
if exErr != nil {
return false, xerrors.Errorf("get experiments: %w", exErr)
}

if !experiments.Enabled(codersdk.ExperimentWorkspaceActions) {
return false, 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.")
}
}

unsetAutostopRequirementDaysOfWeek := len(args.autostopRequirementDaysOfWeek) == 1 && args.autostopRequirementDaysOfWeek[0] == "none"
requiresScheduling := (len(args.autostopRequirementDaysOfWeek) > 0 && !unsetAutostopRequirementDaysOfWeek) ||
args.autostopRequirementWeeks > 0 ||
!args.allowUserAutostart ||
!args.allowUserAutostop ||
args.maxTTL != 0 ||
args.failureTTL != 0 ||
args.dormancyThreshold != 0 ||
args.dormancyAutoDeletion != 0 ||
len(args.autostartRequirementDaysOfWeek) > 0

requiresEntitlement := requiresScheduling || args.requireActiveVersion
if requiresEntitlement {
entitlements, err := args.client.Entitlements(ctx)
if cerr, ok := codersdk.AsError(err); ok && cerr.StatusCode() == http.StatusNotFound {
return false, xerrors.Errorf("your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags")
} else if err != nil {
return false, xerrors.Errorf("get entitlements: %w", err)
}

if requiresScheduling && !entitlements.Features[codersdk.FeatureAdvancedTemplateScheduling].Enabled {
return false, xerrors.Errorf("your license is not entitled to use advanced template scheduling, so you cannot set --max-ttl, --failure-ttl, --inactivityTTL, --allow-user-autostart=false or --allow-user-autostop=false")
}

if args.requireActiveVersion {
if !entitlements.Features[codersdk.FeatureAccessControl].Enabled {
return false, xerrors.Errorf("your license is not entitled to use enterprise access control, so you cannot set --require-active-version")
}

experiments, exErr := args.client.Experiments(ctx)
if exErr != nil {
return false, xerrors.Errorf("get experiments: %w", exErr)
}

if !experiments.Enabled(codersdk.ExperimentTemplateUpdatePolicies) {
return false, xerrors.Errorf("--require-active-version is an experimental feature, contact an administrator to enable the 'template_update_policies' experiment on your Coder server")
}
}
}

return unsetAutostopRequirementDaysOfWeek, nil
}

type updateTemplateMetaArgs struct {
client *codersdk.Client
inv *clibase.Invocation
template codersdk.Template
unsetAutostopRequirementDaysOfWeek bool

name string
displayName string
description string
icon string
defaultTTL time.Duration
maxTTL time.Duration
autostopRequirementDaysOfWeek []string
autostopRequirementWeeks int64
autostartRequirementDaysOfWeek []string
failureTTL time.Duration
dormancyThreshold time.Duration
dormancyAutoDeletion time.Duration
allowUserCancelWorkspaceJobs bool
allowUserAutostart bool
allowUserAutostop bool
requireActiveVersion bool
deprecationMessage string
disableEveryone bool
}

func updateTemplateMetaRequest(args updateTemplateMetaArgs) codersdk.UpdateTemplateMeta {
// Copy the default value if the list is empty, or if the user
// specified the "none" value clear the list.
if len(args.autostopRequirementDaysOfWeek) == 0 {
args.autostopRequirementDaysOfWeek = args.template.AutostopRequirement.DaysOfWeek
}
if len(args.autostartRequirementDaysOfWeek) == 1 && args.autostartRequirementDaysOfWeek[0] == "all" {
// Set it to every day of the week
args.autostartRequirementDaysOfWeek = []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}
} else if len(args.autostartRequirementDaysOfWeek) == 0 {
args.autostartRequirementDaysOfWeek = args.template.AutostartRequirement.DaysOfWeek
}
if args.unsetAutostopRequirementDaysOfWeek {
args.autostopRequirementDaysOfWeek = []string{}
}
if args.failureTTL == 0 {
args.failureTTL = time.Duration(args.template.FailureTTLMillis) * time.Millisecond
}
if args.dormancyThreshold == 0 {
args.dormancyThreshold = time.Duration(args.template.TimeTilDormantMillis) * time.Millisecond
}
if args.dormancyAutoDeletion == 0 {
args.dormancyAutoDeletion = time.Duration(args.template.TimeTilDormantAutoDeleteMillis) * time.Millisecond
}

// Default values
if !userSetOption(args.inv, "description") {
args.description = args.template.Description
}

if !userSetOption(args.inv, "icon") {
args.icon = args.template.Icon
}

if !userSetOption(args.inv, "display-name") {
args.displayName = args.template.DisplayName
}

var deprecated *string
if !userSetOption(args.inv, "deprecated") {
deprecated = &args.deprecationMessage
}

return codersdk.UpdateTemplateMeta{
Name: args.name,
DisplayName: args.displayName,
Description: args.description,
Icon: args.icon,
DefaultTTLMillis: args.defaultTTL.Milliseconds(),
MaxTTLMillis: args.maxTTL.Milliseconds(),
AutostopRequirement: &codersdk.TemplateAutostopRequirement{
DaysOfWeek: args.autostopRequirementDaysOfWeek,
Weeks: args.autostopRequirementWeeks,
},
AutostartRequirement: &codersdk.TemplateAutostartRequirement{
DaysOfWeek: args.autostartRequirementDaysOfWeek,
},
FailureTTLMillis: args.failureTTL.Milliseconds(),
TimeTilDormantMillis: args.dormancyThreshold.Milliseconds(),
TimeTilDormantAutoDeleteMillis: args.dormancyAutoDeletion.Milliseconds(),
AllowUserCancelWorkspaceJobs: args.allowUserCancelWorkspaceJobs,
AllowUserAutostart: args.allowUserAutostart,
AllowUserAutostop: args.allowUserAutostop,
RequireActiveVersion: args.requireActiveVersion,
DeprecationMessage: deprecated,
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp