Skip to content

Commit 42a3021

Browse files
committed
Merge remote-tracking branch 'origin/main' into stevenmasley/relax_csrf
2 parents c6c4141 + 359a642 commit 42a3021

File tree

80 files changed

+2028
-917
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2028
-917
lines changed

.github/dependabot.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ updates:
3838
commit-message:
3939
prefix: "chore"
4040
labels: []
41+
open-pull-requests-limit: 15
4142
ignore:
4243
# Ignore patch updates for all dependencies
4344
- dependency-name: "*"

.github/workflows/dogfood.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
7676
- name: "Push template"
7777
run: |
78-
./coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION --message="$CODER_TEMPLATE_MESSAGE"
78+
./coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION --message="$CODER_TEMPLATE_MESSAGE" --variable jfrog_url=${{ secrets.JFROG_URL }}
7979
env:
8080
# Consumed by Coder CLI
8181
CODER_URL: https://dev.coder.com

.github/workflows/pr-deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ jobs:
416416
417417
# Create template
418418
cd ./.github/pr-deployments/template
419-
coder templates create -y --variable namespace=pr${{ env.PR_NUMBER }} kubernetes
419+
coder templates push -y --variable namespace=pr${{ env.PR_NUMBER }} kubernetes
420420
421421
# Create workspace
422422
coder create --template="kubernetes" kube --parameter cpu=2 --parameter memory=4 --parameter home_disk_size=2 -y

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"idtoken",
6161
"Iflag",
6262
"incpatch",
63+
"initialisms",
6364
"ipnstate",
6465
"isatty",
6566
"Jobf",

cli/cliui/deprecation.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package cliui
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/coder/coder/v2/cli/clibase"
7+
"github.com/coder/pretty"
8+
)
9+
10+
func DeprecationWarning(message string) clibase.MiddlewareFunc {
11+
return func(next clibase.HandlerFunc) clibase.HandlerFunc {
12+
return func(i *clibase.Invocation) error {
13+
_, _ = fmt.Fprintln(i.Stdout, "\n"+pretty.Sprint(DefaultStyles.Wrap,
14+
pretty.Sprint(
15+
DefaultStyles.Warn,
16+
"DEPRECATION WARNING: This command will be removed in a future release."+"\n"+message+"\n"),
17+
))
18+
return next(i)
19+
}
20+
}
21+
}

cli/list.go

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@ type workspaceListRow struct {
2222
codersdk.Workspace `table:"-"`
2323

2424
// For table format:
25-
WorkspaceName string `json:"-" table:"workspace,default_sort"`
26-
Template string `json:"-" table:"template"`
27-
Status string `json:"-" table:"status"`
28-
Healthy string `json:"-" table:"healthy"`
29-
LastBuilt string `json:"-" table:"last built"`
30-
Outdated bool `json:"-" table:"outdated"`
31-
StartsAt string `json:"-" table:"starts at"`
32-
StartsNext string `json:"-" table:"starts next"`
33-
StopsAfter string `json:"-" table:"stops after"`
34-
StopsNext string `json:"-" table:"stops next"`
35-
DailyCost string `json:"-" table:"daily cost"`
25+
WorkspaceName string `json:"-" table:"workspace,default_sort"`
26+
Template string `json:"-" table:"template"`
27+
Status string `json:"-" table:"status"`
28+
Healthy string `json:"-" table:"healthy"`
29+
LastBuilt string `json:"-" table:"last built"`
30+
CurrentVersion string `json:"-" table:"current version"`
31+
Outdated bool `json:"-" table:"outdated"`
32+
StartsAt string `json:"-" table:"starts at"`
33+
StartsNext string `json:"-" table:"starts next"`
34+
StopsAfter string `json:"-" table:"stops after"`
35+
StopsNext string `json:"-" table:"stops next"`
36+
DailyCost string `json:"-" table:"daily cost"`
3637
}
3738

3839
func workspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace) workspaceListRow {
@@ -46,18 +47,19 @@ func workspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace)
4647
healthy = strconv.FormatBool(workspace.Health.Healthy)
4748
}
4849
return workspaceListRow{
49-
Workspace: workspace,
50-
WorkspaceName: workspace.OwnerName + "/" + workspace.Name,
51-
Template: workspace.TemplateName,
52-
Status: status,
53-
Healthy: healthy,
54-
LastBuilt: durationDisplay(lastBuilt),
55-
Outdated: workspace.Outdated,
56-
StartsAt: schedRow.StartsAt,
57-
StartsNext: schedRow.StartsNext,
58-
StopsAfter: schedRow.StopsAfter,
59-
StopsNext: schedRow.StopsNext,
60-
DailyCost: strconv.Itoa(int(workspace.LatestBuild.DailyCost)),
50+
Workspace: workspace,
51+
WorkspaceName: workspace.OwnerName + "/" + workspace.Name,
52+
Template: workspace.TemplateName,
53+
Status: status,
54+
Healthy: healthy,
55+
LastBuilt: durationDisplay(lastBuilt),
56+
CurrentVersion: workspace.LatestBuild.TemplateVersionName,
57+
Outdated: workspace.Outdated,
58+
StartsAt: schedRow.StartsAt,
59+
StartsNext: schedRow.StartsNext,
60+
StopsAfter: schedRow.StopsAfter,
61+
StopsNext: schedRow.StopsNext,
62+
DailyCost: strconv.Itoa(int(workspace.LatestBuild.DailyCost)),
6163
}
6264
}
6365

@@ -73,6 +75,7 @@ func (r *RootCmd) list() *clibase.Cmd {
7375
"status",
7476
"healthy",
7577
"last built",
78+
"current version",
7679
"outdated",
7780
"starts at",
7881
"stops after",

cli/templatecreate.go

Lines changed: 5 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package cli
22

33
import (
4-
"errors"
54
"fmt"
6-
"io"
75
"net/http"
8-
"strings"
96
"time"
107
"unicode/utf8"
118

12-
"github.com/google/uuid"
139
"golang.org/x/xerrors"
1410

1511
"github.com/coder/pretty"
@@ -40,9 +36,13 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
4036
client := new(codersdk.Client)
4137
cmd := &clibase.Cmd{
4238
Use: "create [name]",
43-
Short: "Create a template from the current directory or as specified by flag",
39+
Short: "DEPRECATED: Create a template from the current directory or as specified by flag",
4440
Middleware: clibase.Chain(
4541
clibase.RequireRangeArgs(0, 1),
42+
cliui.DeprecationWarning(
43+
"Use `coder templates push` command for creating and updating templates. \n"+
44+
"Use `coder templates edit` command for editing template settings. ",
45+
),
4646
r.InitClient(client),
4747
),
4848
Handler: func(inv *clibase.Invocation) error {
@@ -253,107 +253,3 @@ func (r *RootCmd) templateCreate() *clibase.Cmd {
253253
cmd.Options = append(cmd.Options, uploadFlags.options()...)
254254
return cmd
255255
}
256-
257-
type createValidTemplateVersionArgs struct {
258-
Name string
259-
Message string
260-
Client *codersdk.Client
261-
Organization codersdk.Organization
262-
Provisioner codersdk.ProvisionerType
263-
FileID uuid.UUID
264-
265-
// Template is only required if updating a template's active version.
266-
Template *codersdk.Template
267-
// ReuseParameters will attempt to reuse params from the Template field
268-
// before prompting the user. Set to false to always prompt for param
269-
// values.
270-
ReuseParameters bool
271-
ProvisionerTags map[string]string
272-
UserVariableValues []codersdk.VariableValue
273-
}
274-
275-
func createValidTemplateVersion(inv *clibase.Invocation, args createValidTemplateVersionArgs) (*codersdk.TemplateVersion, error) {
276-
client := args.Client
277-
278-
req := codersdk.CreateTemplateVersionRequest{
279-
Name: args.Name,
280-
Message: args.Message,
281-
StorageMethod: codersdk.ProvisionerStorageMethodFile,
282-
FileID: args.FileID,
283-
Provisioner: args.Provisioner,
284-
ProvisionerTags: args.ProvisionerTags,
285-
UserVariableValues: args.UserVariableValues,
286-
}
287-
if args.Template != nil {
288-
req.TemplateID = args.Template.ID
289-
}
290-
version, err := client.CreateTemplateVersion(inv.Context(), args.Organization.ID, req)
291-
if err != nil {
292-
return nil, err
293-
}
294-
295-
err = cliui.ProvisionerJob(inv.Context(), inv.Stdout, cliui.ProvisionerJobOptions{
296-
Fetch: func() (codersdk.ProvisionerJob, error) {
297-
version, err := client.TemplateVersion(inv.Context(), version.ID)
298-
return version.Job, err
299-
},
300-
Cancel: func() error {
301-
return client.CancelTemplateVersion(inv.Context(), version.ID)
302-
},
303-
Logs: func() (<-chan codersdk.ProvisionerJobLog, io.Closer, error) {
304-
return client.TemplateVersionLogsAfter(inv.Context(), version.ID, 0)
305-
},
306-
})
307-
if err != nil {
308-
var jobErr *cliui.ProvisionerJobError
309-
if errors.As(err, &jobErr) && !codersdk.JobIsMissingParameterErrorCode(jobErr.Code) {
310-
return nil, err
311-
}
312-
if err != nil {
313-
return nil, err
314-
}
315-
}
316-
version, err = client.TemplateVersion(inv.Context(), version.ID)
317-
if err != nil {
318-
return nil, err
319-
}
320-
321-
if version.Job.Status != codersdk.ProvisionerJobSucceeded {
322-
return nil, xerrors.New(version.Job.Error)
323-
}
324-
325-
resources, err := client.TemplateVersionResources(inv.Context(), version.ID)
326-
if err != nil {
327-
return nil, err
328-
}
329-
330-
// Only display the resources on the start transition, to avoid listing them more than once.
331-
var startResources []codersdk.WorkspaceResource
332-
for _, r := range resources {
333-
if r.Transition == codersdk.WorkspaceTransitionStart {
334-
startResources = append(startResources, r)
335-
}
336-
}
337-
err = cliui.WorkspaceResources(inv.Stdout, startResources, cliui.WorkspaceResourcesOptions{
338-
HideAgentState: true,
339-
HideAccess: true,
340-
Title: "Template Preview",
341-
})
342-
if err != nil {
343-
return nil, xerrors.Errorf("preview template resources: %w", err)
344-
}
345-
346-
return &version, nil
347-
}
348-
349-
func ParseProvisionerTags(rawTags []string) (map[string]string, error) {
350-
tags := map[string]string{}
351-
for _, rawTag := range rawTags {
352-
parts := strings.SplitN(rawTag, "=", 2)
353-
if len(parts) < 2 {
354-
return nil, xerrors.Errorf("invalid tag format for %q. must be key=value", rawTag)
355-
}
356-
tags[parts[0]] = parts[1]
357-
}
358-
return tags, nil
359-
}

cli/templatecreate_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,6 @@ import (
1919
"github.com/coder/coder/v2/testutil"
2020
)
2121

22-
func completeWithAgent() *echo.Responses {
23-
return &echo.Responses{
24-
Parse: echo.ParseComplete,
25-
ProvisionPlan: []*proto.Response{
26-
{
27-
Type: &proto.Response_Plan{
28-
Plan: &proto.PlanComplete{
29-
Resources: []*proto.Resource{
30-
{
31-
Type: "compute",
32-
Name: "main",
33-
Agents: []*proto.Agent{
34-
{
35-
Name: "smith",
36-
OperatingSystem: "linux",
37-
Architecture: "i386",
38-
},
39-
},
40-
},
41-
},
42-
},
43-
},
44-
},
45-
},
46-
ProvisionApply: []*proto.Response{
47-
{
48-
Type: &proto.Response_Apply{
49-
Apply: &proto.ApplyComplete{
50-
Resources: []*proto.Resource{
51-
{
52-
Type: "compute",
53-
Name: "main",
54-
Agents: []*proto.Agent{
55-
{
56-
Name: "smith",
57-
OperatingSystem: "linux",
58-
Architecture: "i386",
59-
},
60-
},
61-
},
62-
},
63-
},
64-
},
65-
},
66-
},
67-
}
68-
}
69-
7022
func TestTemplateCreate(t *testing.T) {
7123
t.Parallel()
7224
t.Run("Create", func(t *testing.T) {
@@ -418,15 +370,3 @@ func TestTemplateCreate(t *testing.T) {
418370
require.Contains(t, err.Error(), "your deployment appears to be an AGPL deployment, so you cannot set enterprise-only flags")
419371
})
420372
}
421-
422-
// Need this for Windows because of a known issue with Go:
423-
// https://github.com/golang/go/issues/52986
424-
func removeTmpDirUntilSuccessAfterTest(t *testing.T, tempDir string) {
425-
t.Helper()
426-
t.Cleanup(func() {
427-
err := os.RemoveAll(tempDir)
428-
for err != nil {
429-
err = os.RemoveAll(tempDir)
430-
}
431-
})
432-
}

cli/templateedit.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
3535
allowUserAutostop bool
3636
requireActiveVersion bool
3737
deprecationMessage string
38+
disableEveryone bool
3839
)
3940
client := new(codersdk.Client)
4041

@@ -162,6 +163,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
162163
AllowUserAutostop: allowUserAutostop,
163164
RequireActiveVersion: requireActiveVersion,
164165
DeprecationMessage: deprecated,
166+
DisableEveryoneGroupAccess: disableEveryone,
165167
}
166168

167169
_, err = client.UpdateTemplateMeta(inv.Context(), template.ID, req)
@@ -292,6 +294,13 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
292294
Value: clibase.BoolOf(&requireActiveVersion),
293295
Default: "false",
294296
},
297+
{
298+
Flag: "private",
299+
Description: "Disable the default behavior of granting template access to the 'everyone' group. " +
300+
"The template permissions must be updated to allow non-admin users to use this template.",
301+
Value: clibase.BoolOf(&disableEveryone),
302+
Default: "false",
303+
},
295304
cliui.SkipPromptOption(),
296305
}
297306

cli/templateinit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (*RootCmd) templateInit() *clibase.Cmd {
113113
inv.Stdout,
114114
pretty.Sprint(
115115
cliui.DefaultStyles.Code,
116-
"cd "+relPath+" && coder templates create"),
116+
"cd "+relPath+" && coder templates push"),
117117
)
118118
_, _ = fmt.Fprintln(inv.Stdout, pretty.Sprint(cliui.DefaultStyles.Wrap, "\nExamples provide a starting point and are expected to be edited! 🎨"))
119119
return nil

cli/templatelist.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (r *RootCmd) templateList() *clibase.Cmd {
3636

3737
if len(templates) == 0 {
3838
_, _ = fmt.Fprintf(inv.Stderr, "%s No templates found in %s! Create one:\n\n", Caret, color.HiWhiteString(organization.Name))
39-
_, _ = fmt.Fprintln(inv.Stderr, color.HiMagentaString(" $ coder templates create <directory>\n"))
39+
_, _ = fmt.Fprintln(inv.Stderr, color.HiMagentaString(" $ coder templates push <directory>\n"))
4040
return nil
4141
}
4242

0 commit comments

Comments
 (0)