Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0cc46c8
fix: make template push a superset of template create
f0ssel Dec 20, 2023
93da7d0
add back work dir
f0ssel Dec 20, 2023
3c409f6
add groupacl
f0ssel Dec 20, 2023
4b763d7
Add back workdir
f0ssel Dec 20, 2023
d178cc7
combine edit flags
f0ssel Dec 20, 2023
5474942
fix edit
f0ssel Dec 20, 2023
2b9bcf6
unify edit and push
f0ssel Dec 20, 2023
44f264b
make gen
f0ssel Dec 20, 2023
d58cf18
fix test
f0ssel Dec 21, 2023
9b32922
make gen
f0ssel Dec 21, 2023
c6ef6f4
update golden
f0ssel Dec 21, 2023
e1e1653
fix tests:
f0ssel Dec 21, 2023
0cdefbc
fix merge
f0ssel Dec 21, 2023
d2a7866
add test
f0ssel Dec 22, 2023
63d57fd
remove test
f0ssel Dec 22, 2023
ca65869
add unset test
f0ssel Dec 22, 2023
9866235
Add deprecation warning
f0ssel Dec 22, 2023
35c7adf
fix
f0ssel Dec 22, 2023
4abf179
rename functions
f0ssel Jan 2, 2024
a3fdb76
test removing flags
f0ssel Jan 3, 2024
7599090
revert
f0ssel Jan 3, 2024
e958e1a
cleanup
f0ssel Jan 3, 2024
c8cae6c
add back flag
f0ssel Jan 3, 2024
1b03e89
remove create command
f0ssel Jan 4, 2024
8918cda
make gen
f0ssel Jan 4, 2024
7d2a7ac
fix gen
f0ssel Jan 4, 2024
5b2792d
add private flag to template edit
f0ssel Jan 4, 2024
b85a73c
fix test
f0ssel Jan 4, 2024
7655bc9
fix golden
f0ssel Jan 4, 2024
2f2911a
update mentions of templates create command
f0ssel Jan 4, 2024
5334e8e
update golden
f0ssel Jan 4, 2024
79c0c02
add removal comment
f0ssel Jan 4, 2024
2dfb98e
Add back create
f0ssel Jan 4, 2024
cb0aec4
fix formatting
f0ssel Jan 4, 2024
d1f13d1
add disableeveryonegroupaccess test
f0ssel Jan 4, 2024
5792279
update test
f0ssel Jan 5, 2024
2e54259
fix test lint
f0ssel Jan 5, 2024
de78f4b
pr comments
f0ssel Jan 5, 2024
0c859bc
fix text formatting
f0ssel Jan 5, 2024
b65ab81
Add deprecation to help text
f0ssel Jan 5, 2024
77c9edf
fix template push wording
f0ssel Jan 5, 2024
13794fd
golden
f0ssel Jan 5, 2024
8355850
fix gen again
f0ssel Jan 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
Prev Previous commit
Next Next commit
revert
  • Loading branch information
f0ssel committed Jan 5, 2024
commit 7599090a59bcacef513eb424945fef1e2a8bd8ab
11 changes: 0 additions & 11 deletions cli/templatepush.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,6 @@ func (r *RootCmd) templatePush() *clibase.Cmd {

_, _ = fmt.Fprintf(inv.Stdout, "Updated version at %s!\n", pretty.Sprint(cliui.DefaultStyles.DateTimeStamp, time.Now().Format(time.Stamp)))

// refresh template data for edit api call
template, err = client.TemplateByName(inv.Context(), organization.ID, name)
if err != nil {
return err
}

if err != nil {
return err
}
_, _ = fmt.Fprintf(inv.Stdout, "Updated template metadata at %s!\n", pretty.Sprint(cliui.DefaultStyles.DateTimeStamp, time.Now().Format(time.Stamp)))

return nil
},
}
Expand Down
149 changes: 0 additions & 149 deletions cli/templatepush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -710,153 +708,6 @@ func TestTemplatePush(t *testing.T) {
require.NotEqual(t, uuid.Nil, template.ActiveVersionID)
})
})

t.Run("EditMetadata", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
owner := coderdtest.CreateFirstUser(t, client)
templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)

template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)

// Test the cli command.
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ApplyComplete,
})

name := "new-template-name"
displayName := "New Display Name 789"
desc := "lorem ipsum dolor sit amet et cetera"
icon := "/icon/new-icon.png"
defaultTTL := 12 * time.Hour
allowUserCancelWorkspaceJobs := false

inv, root := clitest.New(t,
"templates",
"push",
template.Name,
"--directory", source,
"--test.provisioner", string(database.ProvisionerTypeEcho),
"--name", name,
"--display-name", displayName,
"--description", desc,
"--icon", icon,
"--default-ttl", defaultTTL.String(),
"--allow-user-cancel-workspace-jobs="+strconv.FormatBool(allowUserCancelWorkspaceJobs),
)
clitest.SetupConfig(t, templateAdmin, root)
pty := ptytest.New(t).Attach(inv)

execDone := make(chan error)
go func() {
execDone <- inv.Run()
}()

matches := []struct {
match string
write string
}{
{match: "Upload", write: "yes"},
}
for _, m := range matches {
pty.ExpectMatch(m.match)
pty.WriteLine(m.write)
}

require.NoError(t, <-execDone)

// Assert that the template version changed.
templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{
TemplateID: template.ID,
})
require.NoError(t, err)
assert.Len(t, templateVersions, 2)
assert.NotEqual(t, template.ActiveVersionID, templateVersions[1].ID)
require.Equal(t, name, templateVersions[1].Name)

// Assert that the template metadata changed.
updated, err := client.Template(context.Background(), template.ID)
require.NoError(t, err)
assert.Equal(t, template.Name, updated.Name)
assert.Equal(t, displayName, updated.DisplayName)
assert.Equal(t, desc, updated.Description)
assert.Equal(t, icon, updated.Icon)
assert.Equal(t, defaultTTL.Milliseconds(), updated.DefaultTTLMillis)
assert.Equal(t, allowUserCancelWorkspaceJobs, updated.AllowUserCancelWorkspaceJobs)
})

t.Run("EditMetadataKeepUnsetUnchanged", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
owner := coderdtest.CreateFirstUser(t, client)
templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)

template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)

// Test the cli command.
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ApplyComplete,
})

desc := "lorem ipsum dolor sit amet et cetera"

inv, root := clitest.New(t,
"templates",
"push",
template.Name,
"--directory", source,
"--test.provisioner", string(database.ProvisionerTypeEcho),
"--description", desc,
)
clitest.SetupConfig(t, templateAdmin, root)
pty := ptytest.New(t).Attach(inv)

execDone := make(chan error)
go func() {
execDone <- inv.Run()
}()

matches := []struct {
match string
write string
}{
{match: "Upload", write: "yes"},
}
for _, m := range matches {
pty.ExpectMatch(m.match)
pty.WriteLine(m.write)
}

require.NoError(t, <-execDone)

// Assert that the template version changed.
templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{
TemplateID: template.ID,
})
require.NoError(t, err)
assert.Len(t, templateVersions, 2)
assert.NotEqual(t, template.ActiveVersionID, templateVersions[1].ID)

// Assert that the template metadata changed.
updated, err := client.Template(context.Background(), template.ID)
require.NoError(t, err)
assert.Equal(t, template.Name, updated.Name)
assert.Equal(t, template.DisplayName, updated.DisplayName)
assert.Equal(t, desc, updated.Description)
assert.Equal(t, template.Icon, updated.Icon)
assert.Equal(t, template.DefaultTTLMillis, updated.DefaultTTLMillis)
assert.Equal(t, template.FailureTTLMillis, updated.FailureTTLMillis)
assert.Equal(t, template.TimeTilDormantAutoDeleteMillis, updated.TimeTilDormantAutoDeleteMillis)
assert.Equal(t, template.AutostartRequirement.DaysOfWeek, updated.AutostartRequirement.DaysOfWeek)
assert.Equal(t, template.AutostopRequirement.DaysOfWeek, updated.AutostopRequirement.DaysOfWeek)
assert.Equal(t, template.RequireActiveVersion, updated.RequireActiveVersion)
})
}

func createEchoResponsesWithTemplateVariables(templateVariables []*proto.TemplateVariable) *echo.Responses {
Expand Down
67 changes: 2 additions & 65 deletions cli/testdata/coder_templates_push_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,23 @@ USAGE:
Push a new template version from the current directory or as specified by flag

OPTIONS:
--deprecated string
Sets the template as deprecated. Must be a message explaining why the
template is deprecated.

--activate bool (default: true)
Whether the new template will be marked active.

--allow-user-autostart bool (default: true)
Allow users to configure autostart for workspaces on this template.
This can only be disabled in enterprise.

--allow-user-autostop bool (default: true)
Allow users to customize the autostop TTL for workspaces on this
template. This can only be disabled in enterprise.

--allow-user-cancel-workspace-jobs bool (default: true)
Allow users to cancel in-progress workspace jobs.

--always-prompt bool
Always prompt all parameters. Does not pull parameter values from
active template version.

--autostart-requirement-weekdays string-array
Edit the template autostart requirement weekdays - workspaces created
from this template can only autostart on the given weekdays. To unset
this value for the template (and allow autostart on all days), pass
'all'.

--default-ttl duration (default: 24h)
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.

--description string
Edit the template description.
--create bool (default: false)
Create the template if it does not exist.

-d, --directory string (default: .)
Specify the directory to create from, use '-' to read tar from stdin.

--display-name string
Edit the template display name.

--dormancy-auto-deletion duration (default: 0h)
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.

--dormancy-threshold duration (default: 0h)
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.

--failure-ttl duration (default: 0h)
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.

--icon string
Edit the template icon path.

--ignore-lockfile bool (default: false)
Ignore warnings about not having a .terraform.lock.hcl file present in
the template.

--max-ttl duration
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.

-m, --message string
Specify a message describing the changes in this version of the
template. Messages longer than 72 characters will be displayed as
Expand All @@ -85,19 +32,9 @@ OPTIONS:
Specify a name for the new template version. It will be automatically
generated if not provided.

--private bool
Disable the default behavior of granting template access to the
'everyone' group. The template permissions must be updated to allow
non-admin users to use this template.

--provisioner-tag string-array
Specify a set of tags to target provisioner daemons.

--require-active-version bool (default: false)
Requires workspace builds to use the active template version. This
setting does not apply to template admins. This is an enterprise-only
feature.

--var string-array
Alias of --variable.

Expand Down
19 changes: 8 additions & 11 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions coderd/database/queries/templates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ SET
name = $4,
icon = $5,
display_name = $6,
allow_user_cancel_workspace_jobs = $7,
group_acl = $8
allow_user_cancel_workspace_jobs = $7
WHERE
id = $1
;
Expand Down
6 changes: 0 additions & 6 deletions coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
name = template.Name
}

groupACL := template.GroupACL
if req.DisableEveryoneGroupAccess {
groupACL = database.TemplateACL{}
}

var err error
err = tx.UpdateTemplateMetaByID(ctx, database.UpdateTemplateMetaByIDParams{
ID: template.ID,
Expand All @@ -681,7 +676,6 @@ func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
Description: req.Description,
Icon: req.Icon,
AllowUserCancelWorkspaceJobs: req.AllowUserCancelWorkspaceJobs,
GroupACL: groupACL,
})
if err != nil {
return xerrors.Errorf("update template metadata: %w", err)
Expand Down
6 changes: 0 additions & 6 deletions codersdk/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,6 @@ type UpdateTemplateMeta struct {
// If passed an empty string, will remove the deprecated message, making
// the template usable for new workspaces again.
DeprecationMessage *string `json:"deprecation_message"`
// DisableEveryoneGroupAccess allows optionally disabling the default
// behavior of granting the 'everyone' group access to use the template.
// If this is set to true, the template will not be available to all users,
// and must be explicitly granted to users or groups in the permissions settings
// of the template.
DisableEveryoneGroupAccess bool `json:"disable_everyone_group_access"`
}

type TemplateExample struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const TemplateSettingsForm: FC<TemplateSettingsForm> = ({
update_workspace_dormant_at: false,
require_active_version: template.require_active_version,
deprecation_message: template.deprecation_message,
disable_everyone_group_access: false,
},
validationSchema,
onSubmit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ const validFormValues: FormValues = {
update_workspace_last_used_at: false,
update_workspace_dormant_at: false,
require_active_version: false,
disable_everyone_group_access: false,
};

const renderTemplateSettingsPage = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
update_workspace_last_used_at: false,
update_workspace_dormant_at: false,
require_active_version: false,
disable_everyone_group_access: false,
},
validationSchema,
onSubmit: () => {
Expand Down Expand Up @@ -239,7 +238,6 @@ export const TemplateScheduleForm: FC<TemplateScheduleForm> = ({
update_workspace_last_used_at: form.values.update_workspace_last_used_at,
update_workspace_dormant_at: form.values.update_workspace_dormant_at,
require_active_version: false,
disable_everyone_group_access: false,
});
};

Expand Down
Loading