Skip to content

Commit 0dc9b6b

Browse files
committed
cli + make gen
1 parent 1bad593 commit 0dc9b6b

File tree

9 files changed

+201
-118
lines changed

9 files changed

+201
-118
lines changed

cli/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func (r *RootCmd) create() *clibase.Cmd {
8989
return xerrors.Errorf("get source workspace: %w", err)
9090
}
9191

92-
_, _ = fmt.Fprintf(inv.Stdout, "Coder will use the same template %q as the source workspace.\n", sourceWorkspace.TemplateName)
93-
templateName = sourceWorkspace.TemplateName
92+
_, _ = fmt.Fprintf(inv.Stdout, "Coder will use the same template %q as the source workspace.\n", sourceWorkspace.SafeTemplate().Name)
93+
templateName = sourceWorkspace.SafeTemplate().Name
9494
}
9595

9696
var template codersdk.Template

cli/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ func workspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace)
5252
favIco = "★"
5353
}
5454
workspaceName := favIco + " " + workspace.OwnerName + "/" + workspace.Name
55+
5556
return workspaceListRow{
5657
Favorite: workspace.Favorite,
5758
Workspace: workspace,
5859
WorkspaceName: workspaceName,
59-
Template: workspace.TemplateName,
60+
Template: workspace.SafeTemplate().Name,
6061
Status: status,
6162
Healthy: healthy,
6263
LastBuilt: durationDisplay(lastBuilt),

cli/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func (r *RootCmd) start() *clibase.Cmd {
8080
func buildWorkspaceStartRequest(inv *clibase.Invocation, client *codersdk.Client, workspace codersdk.Workspace, parameterFlags workspaceParameterFlags, action WorkspaceCLIAction) (codersdk.CreateWorkspaceBuildRequest, error) {
8181
version := workspace.LatestBuild.TemplateVersionID
8282

83-
if workspace.AutomaticUpdates == codersdk.AutomaticUpdatesAlways || action == WorkspaceUpdate {
84-
version = workspace.TemplateActiveVersionID
83+
if (workspace.AutomaticUpdates == codersdk.AutomaticUpdatesAlways || action == WorkspaceUpdate) && workspace.Template != nil {
84+
version = workspace.Template.ActiveVersionID
8585
if version != workspace.LatestBuild.TemplateVersionID {
8686
action = WorkspaceUpdate
8787
}

coderd/apidoc/docs.go

Lines changed: 32 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 32 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codersdk/workspaces.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ type Workspace struct {
6262
Favorite bool `json:"favorite"`
6363
}
6464

65+
// SafeTemplate returns some sane value if the template is nil.
66+
// This can happen if the caller cannot read the template.
67+
func (w Workspace) SafeTemplate() WorkspaceTemplateInfo {
68+
if w.Template != nil {
69+
return *w.Template
70+
}
71+
return WorkspaceTemplateInfo{
72+
Name: "<forbidden>",
73+
DisplayName: "<forbidden>",
74+
Icon: "",
75+
AllowUserCancelWorkspaceJobs: false,
76+
ActiveVersionID: uuid.Nil,
77+
RequireActiveVersion: false,
78+
}
79+
}
80+
6581
// WorkspaceTemplateInfo is a subset of Template fields for a workspace.
6682
type WorkspaceTemplateInfo struct {
6783
Name string `json:"name"`

0 commit comments

Comments
 (0)