From 3cde62a7e57cab8d9251f0062c1812f39e13e552 Mon Sep 17 00:00:00 2001 From: Garrett Date: Mon, 6 Jun 2022 16:55:31 +0000 Subject: [PATCH 1/3] fix: add workspace option 'deleted' to options type --- coderd/workspaces.go | 6 ------ codersdk/workspaces.go | 21 ++++++++++++++++++++- site/src/api/typesGenerated.ts | 15 ++++++++++----- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/coderd/workspaces.go b/coderd/workspaces.go index 3b9ea88ecc91a..23c142bcdf873 100644 --- a/coderd/workspaces.go +++ b/coderd/workspaces.go @@ -60,12 +60,6 @@ func (api *API) workspace(rw http.ResponseWriter, r *http.Request) { }) return } - if !workspace.Deleted && showDeleted { - httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{ - Message: fmt.Sprintf("Workspace %q is not deleted, please remove '?deleted=true' and try again", workspace.ID.String()), - }) - return - } build, err := api.Database.GetLatestWorkspaceBuildByWorkspaceID(r.Context(), workspace.ID) if err != nil { diff --git a/codersdk/workspaces.go b/codersdk/workspaces.go index 0d9aadccedca1..3e81645957314 100644 --- a/codersdk/workspaces.go +++ b/codersdk/workspaces.go @@ -38,6 +38,22 @@ type CreateWorkspaceBuildRequest struct { ProvisionerState []byte `json:"state,omitempty"` } +type WorkspaceOptions struct { + Deleted bool `json:"deleted,omitempty"` +} + +// asRequestOption returns a function that can be used in (*Client).Request. +// It modifies the request query parameters. +func (o WorkspaceOptions) asRequestOption() requestOption { + return func(r *http.Request) { + q := r.URL.Query() + if o.Deleted { + q.Set("deleted", "true") + } + r.URL.RawQuery = q.Encode() + } +} + // Workspace returns a single workspace. func (c *Client) Workspace(ctx context.Context, id uuid.UUID) (Workspace, error) { return c.getWorkspace(ctx, id) @@ -45,7 +61,10 @@ func (c *Client) Workspace(ctx context.Context, id uuid.UUID) (Workspace, error) // DeletedWorkspace returns a single workspace that was deleted. func (c *Client) DeletedWorkspace(ctx context.Context, id uuid.UUID) (Workspace, error) { - return c.getWorkspace(ctx, id, queryParam("deleted", "true")) + o := WorkspaceOptions{ + Deleted: true, + } + return c.getWorkspace(ctx, id, o.asRequestOption()) } func (c *Client) getWorkspace(ctx context.Context, id uuid.UUID, opts ...requestOption) (Workspace, error) { diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 1f227c08aa88e..8e71d52a3906c 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -221,7 +221,7 @@ export interface ProvisionerJobLog { readonly output: string } -// From codersdk/workspaces.go:182:6 +// From codersdk/workspaces.go:201:6 export interface PutExtendWorkspaceRequest { readonly deadline: string } @@ -298,12 +298,12 @@ export interface UpdateUserProfileRequest { readonly username: string } -// From codersdk/workspaces.go:141:6 +// From codersdk/workspaces.go:160:6 export interface UpdateWorkspaceAutostartRequest { readonly schedule?: string } -// From codersdk/workspaces.go:161:6 +// From codersdk/workspaces.go:180:6 export interface UpdateWorkspaceTTLRequest { readonly ttl_ms?: number } @@ -445,18 +445,23 @@ export interface WorkspaceBuild { readonly deadline: string } -// From codersdk/workspaces.go:64:6 +// From codersdk/workspaces.go:83:6 export interface WorkspaceBuildsRequest extends Pagination { readonly WorkspaceID: string } -// From codersdk/workspaces.go:200:6 +// From codersdk/workspaces.go:219:6 export interface WorkspaceFilter { readonly organization_id?: string readonly owner?: string readonly name?: string } +// From codersdk/workspaces.go:41:6 +export interface WorkspaceOptions { + readonly deleted?: boolean +} + // From codersdk/workspaceresources.go:21:6 export interface WorkspaceResource { readonly id: string From 3de6806f7877c02cad41ec5b7b91f45b65aacfe2 Mon Sep 17 00:00:00 2001 From: Garrett Date: Mon, 6 Jun 2022 17:03:52 +0000 Subject: [PATCH 2/3] dead code --- codersdk/client.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/codersdk/client.go b/codersdk/client.go index c8e613a631202..78a266db02202 100644 --- a/codersdk/client.go +++ b/codersdk/client.go @@ -36,14 +36,6 @@ type Client struct { type requestOption func(*http.Request) -func queryParam(k, v string) requestOption { - return func(r *http.Request) { - q := r.URL.Query() - q.Set(k, v) - r.URL.RawQuery = q.Encode() - } -} - // Request performs an HTTP request with the body provided. // The caller is responsible for closing the response body. func (c *Client) Request(ctx context.Context, method, path string, body interface{}, opts ...requestOption) (*http.Response, error) { From f19c0edfefc85c6b17ecded8c5128b9686692b6f Mon Sep 17 00:00:00 2001 From: Garrett Date: Mon, 6 Jun 2022 17:08:47 +0000 Subject: [PATCH 3/3] fix go test --- coderd/workspaces_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/coderd/workspaces_test.go b/coderd/workspaces_test.go index c7b0e28f3b391..e7fa0855e0bdf 100644 --- a/coderd/workspaces_test.go +++ b/coderd/workspaces_test.go @@ -46,10 +46,9 @@ func TestWorkspace(t *testing.T) { workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID) coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID) - // Getting with deleted=true should fail. + // Getting with deleted=true should still work. _, err := client.DeletedWorkspace(context.Background(), workspace.ID) - require.Error(t, err) - require.ErrorContains(t, err, "400") // bad request + require.NoError(t, err) // Delete the workspace build, err := client.CreateWorkspaceBuild(context.Background(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy