From 94c735ce8bab27394ff8c4da3abfb44d770f4170 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Mon, 21 Aug 2023 17:32:19 +0000 Subject: [PATCH 1/3] feat: add `template_active_version_id` to workspaces This reduces a fetch in the VS Code extension when getting the active version update message! --- coderd/apidoc/docs.go | 4 ++++ coderd/apidoc/swagger.json | 4 ++++ coderd/oauthpki/oidcpki.go | 5 ++--- coderd/workspaces.go | 1 + codersdk/workspaces.go | 1 + docs/api/schemas.md | 3 +++ docs/api/workspaces.md | 5 +++++ site/src/api/typesGenerated.ts | 1 + 8 files changed, 21 insertions(+), 3 deletions(-) diff --git a/coderd/apidoc/docs.go b/coderd/apidoc/docs.go index 247000282b388..06258bf0b40c3 100644 --- a/coderd/apidoc/docs.go +++ b/coderd/apidoc/docs.go @@ -10519,6 +10519,10 @@ const docTemplate = `{ "owner_name": { "type": "string" }, + "template_active_version_id": { + "type": "string", + "format": "uuid" + }, "template_allow_user_cancel_workspace_jobs": { "type": "boolean" }, diff --git a/coderd/apidoc/swagger.json b/coderd/apidoc/swagger.json index b21fd94032a90..0fcc8fa339a25 100644 --- a/coderd/apidoc/swagger.json +++ b/coderd/apidoc/swagger.json @@ -9525,6 +9525,10 @@ "owner_name": { "type": "string" }, + "template_active_version_id": { + "type": "string", + "format": "uuid" + }, "template_allow_user_cancel_workspace_jobs": { "type": "boolean" }, diff --git a/coderd/oauthpki/oidcpki.go b/coderd/oauthpki/oidcpki.go index 3f3ceaf221941..d5bc625336ab7 100644 --- a/coderd/oauthpki/oidcpki.go +++ b/coderd/oauthpki/oidcpki.go @@ -8,7 +8,6 @@ import ( "encoding/base64" "encoding/json" "encoding/pem" - "fmt" "io" "net/http" "net/url" @@ -243,7 +242,7 @@ func (src *jwtTokenSource) Token() (*oauth2.Token, error) { } if unmarshalError != nil { - return nil, fmt.Errorf("oauth2: cannot unmarshal token: %w", err) + return nil, xerrors.Errorf("oauth2: cannot unmarshal token: %w", err) } newToken := &oauth2.Token{ @@ -264,7 +263,7 @@ func (src *jwtTokenSource) Token() (*oauth2.Token, error) { // decode returned id token to get expiry claimSet, err := jws.Decode(v) if err != nil { - return nil, fmt.Errorf("oauth2: error decoding JWT token: %w", err) + return nil, xerrors.Errorf("oauth2: error decoding JWT token: %w", err) } newToken.Expiry = time.Unix(claimSet.Exp, 0) } diff --git a/coderd/workspaces.go b/coderd/workspaces.go index 0f493e5995b24..b0bb826a10ae8 100644 --- a/coderd/workspaces.go +++ b/coderd/workspaces.go @@ -1187,6 +1187,7 @@ func convertWorkspace( TemplateIcon: template.Icon, TemplateDisplayName: template.DisplayName, TemplateAllowUserCancelWorkspaceJobs: template.AllowUserCancelWorkspaceJobs, + TemplateActiveVersionID: template.ActiveVersionID, Outdated: workspaceBuild.TemplateVersionID.String() != template.ActiveVersionID.String(), Name: workspace.Name, AutostartSchedule: autostartSchedule, diff --git a/codersdk/workspaces.go b/codersdk/workspaces.go index 0f43143bfe0fb..21fe0e6f9193d 100644 --- a/codersdk/workspaces.go +++ b/codersdk/workspaces.go @@ -28,6 +28,7 @@ type Workspace struct { TemplateDisplayName string `json:"template_display_name"` TemplateIcon string `json:"template_icon"` TemplateAllowUserCancelWorkspaceJobs bool `json:"template_allow_user_cancel_workspace_jobs"` + TemplateActiveVersionID uuid.UUID `json:"template_active_version_id" format:"uuid"` LatestBuild WorkspaceBuild `json:"latest_build"` Outdated bool `json:"outdated"` Name string `json:"name"` diff --git a/docs/api/schemas.md b/docs/api/schemas.md index dca1dd3d6c1be..30968d5bd3bdc 100644 --- a/docs/api/schemas.md +++ b/docs/api/schemas.md @@ -5488,6 +5488,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| "outdated": true, "owner_id": "8826ee2e-7933-4665-aef2-2393f84a0d05", "owner_name": "string", + "template_active_version_id": "b0da9c29-67d8-4c87-888c-bafe356f7f3c", "template_allow_user_cancel_workspace_jobs": true, "template_display_name": "string", "template_icon": "string", @@ -5515,6 +5516,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| | `outdated` | boolean | false | | | | `owner_id` | string | false | | | | `owner_name` | string | false | | | +| `template_active_version_id` | string | false | | | | `template_allow_user_cancel_workspace_jobs` | boolean | false | | | | `template_display_name` | string | false | | | | `template_icon` | string | false | | | @@ -6618,6 +6620,7 @@ If the schedule is empty, the user will be updated to use the default schedule.| "outdated": true, "owner_id": "8826ee2e-7933-4665-aef2-2393f84a0d05", "owner_name": "string", + "template_active_version_id": "b0da9c29-67d8-4c87-888c-bafe356f7f3c", "template_allow_user_cancel_workspace_jobs": true, "template_display_name": "string", "template_icon": "string", diff --git a/docs/api/workspaces.md b/docs/api/workspaces.md index f5c4aadd729c5..e004ee0126ab4 100644 --- a/docs/api/workspaces.md +++ b/docs/api/workspaces.md @@ -188,6 +188,7 @@ curl -X POST http://coder-server:8080/api/v2/organizations/{organization}/member "outdated": true, "owner_id": "8826ee2e-7933-4665-aef2-2393f84a0d05", "owner_name": "string", + "template_active_version_id": "b0da9c29-67d8-4c87-888c-bafe356f7f3c", "template_allow_user_cancel_workspace_jobs": true, "template_display_name": "string", "template_icon": "string", @@ -376,6 +377,7 @@ curl -X GET http://coder-server:8080/api/v2/users/{user}/workspace/{workspacenam "outdated": true, "owner_id": "8826ee2e-7933-4665-aef2-2393f84a0d05", "owner_name": "string", + "template_active_version_id": "b0da9c29-67d8-4c87-888c-bafe356f7f3c", "template_allow_user_cancel_workspace_jobs": true, "template_display_name": "string", "template_icon": "string", @@ -563,6 +565,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaces \ "outdated": true, "owner_id": "8826ee2e-7933-4665-aef2-2393f84a0d05", "owner_name": "string", + "template_active_version_id": "b0da9c29-67d8-4c87-888c-bafe356f7f3c", "template_allow_user_cancel_workspace_jobs": true, "template_display_name": "string", "template_icon": "string", @@ -752,6 +755,7 @@ curl -X GET http://coder-server:8080/api/v2/workspaces/{workspace} \ "outdated": true, "owner_id": "8826ee2e-7933-4665-aef2-2393f84a0d05", "owner_name": "string", + "template_active_version_id": "b0da9c29-67d8-4c87-888c-bafe356f7f3c", "template_allow_user_cancel_workspace_jobs": true, "template_display_name": "string", "template_icon": "string", @@ -1074,6 +1078,7 @@ curl -X PUT http://coder-server:8080/api/v2/workspaces/{workspace}/lock \ "outdated": true, "owner_id": "8826ee2e-7933-4665-aef2-2393f84a0d05", "owner_name": "string", + "template_active_version_id": "b0da9c29-67d8-4c87-888c-bafe356f7f3c", "template_allow_user_cancel_workspace_jobs": true, "template_display_name": "string", "template_icon": "string", diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 3960997706c6a..7b19a6e0e5250 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -1299,6 +1299,7 @@ export interface Workspace { readonly template_display_name: string readonly template_icon: string readonly template_allow_user_cancel_workspace_jobs: boolean + readonly template_active_version_id: string readonly latest_build: WorkspaceBuild readonly outdated: boolean readonly name: string From 77af9da60d98db4539b59702dd214fd656418af2 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 23 Aug 2023 19:55:15 +0000 Subject: [PATCH 2/3] Fix entities.ts --- site/src/testHelpers/entities.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/site/src/testHelpers/entities.ts b/site/src/testHelpers/entities.ts index 2a77a174e8831..7454f02e74ed6 100644 --- a/site/src/testHelpers/entities.ts +++ b/site/src/testHelpers/entities.ts @@ -848,6 +848,7 @@ export const MockWorkspace: TypesGen.Workspace = { template_display_name: MockTemplate.display_name, template_allow_user_cancel_workspace_jobs: MockTemplate.allow_user_cancel_workspace_jobs, + template_active_version_id: MockTemplate.active_version_id, outdated: false, owner_id: MockUser.id, organization_id: MockOrganization.id, From 6da0d7384b8f5fe09044ea7200cc1c2da29935d1 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Sun, 27 Aug 2023 16:19:54 +0000 Subject: [PATCH 3/3] Fix golden gen --- cli/testdata/coder_list_--output_json.golden | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/testdata/coder_list_--output_json.golden b/cli/testdata/coder_list_--output_json.golden index f680c9e210cbc..2e317f996047b 100644 --- a/cli/testdata/coder_list_--output_json.golden +++ b/cli/testdata/coder_list_--output_json.golden @@ -11,6 +11,7 @@ "template_display_name": "", "template_icon": "", "template_allow_user_cancel_workspace_jobs": false, + "template_active_version_id": "[version ID]", "latest_build": { "id": "[workspace build ID]", "created_at": "[timestamp]",