Skip to content

Commit eaeaae5

Browse files
committed
fixup! Share formatter for similar commands
1 parent 8f38d52 commit eaeaae5

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

codersdk/workspaceproxy.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,26 @@ type CreateWorkspaceProxyRequest struct {
7070
Icon string `json:"icon"`
7171
}
7272

73-
type CreateWorkspaceProxyResponse struct {
73+
type UpdateWorkspaceProxyResponse struct {
7474
Proxy WorkspaceProxy `json:"proxy" table:"proxy,recursive"`
7575
// The recursive table sort is not working very well.
7676
ProxyToken string `json:"proxy_token" table:"proxy token,default_sort"`
7777
}
7878

79-
func (c *Client) CreateWorkspaceProxy(ctx context.Context, req CreateWorkspaceProxyRequest) (CreateWorkspaceProxyResponse, error) {
79+
func (c *Client) CreateWorkspaceProxy(ctx context.Context, req CreateWorkspaceProxyRequest) (UpdateWorkspaceProxyResponse, error) {
8080
res, err := c.Request(ctx, http.MethodPost,
8181
"/api/v2/workspaceproxies",
8282
req,
8383
)
8484
if err != nil {
85-
return CreateWorkspaceProxyResponse{}, xerrors.Errorf("make request: %w", err)
85+
return UpdateWorkspaceProxyResponse{}, xerrors.Errorf("make request: %w", err)
8686
}
8787
defer res.Body.Close()
8888

8989
if res.StatusCode != http.StatusCreated {
90-
return CreateWorkspaceProxyResponse{}, ReadBodyAsError(res)
90+
return UpdateWorkspaceProxyResponse{}, ReadBodyAsError(res)
9191
}
92-
var resp CreateWorkspaceProxyResponse
92+
var resp UpdateWorkspaceProxyResponse
9393
return resp, json.NewDecoder(res.Body).Decode(&resp)
9494
}
9595

@@ -119,26 +119,20 @@ type PatchWorkspaceProxy struct {
119119
RegenerateToken bool `json:"regenerate_token"`
120120
}
121121

122-
type PatchWorkspaceProxyResponse struct {
123-
Proxy WorkspaceProxy `json:"proxy" table:"proxy,recursive"`
124-
// ProxyToken is only returned if 'RegenerateToken' is set.
125-
ProxyToken string `json:"proxy_token" table:"proxy token,default_sort"`
126-
}
127-
128-
func (c *Client) PatchWorkspaceProxy(ctx context.Context, req PatchWorkspaceProxy) (WorkspaceProxy, error) {
122+
func (c *Client) PatchWorkspaceProxy(ctx context.Context, req PatchWorkspaceProxy) (UpdateWorkspaceProxyResponse, error) {
129123
res, err := c.Request(ctx, http.MethodPatch,
130124
fmt.Sprintf("/api/v2/workspaceproxies/%s", req.ID.String()),
131125
req,
132126
)
133127
if err != nil {
134-
return WorkspaceProxy{}, xerrors.Errorf("make request: %w", err)
128+
return UpdateWorkspaceProxyResponse{}, xerrors.Errorf("make request: %w", err)
135129
}
136130
defer res.Body.Close()
137131

138132
if res.StatusCode != http.StatusOK {
139-
return WorkspaceProxy{}, ReadBodyAsError(res)
133+
return UpdateWorkspaceProxyResponse{}, ReadBodyAsError(res)
140134
}
141-
var resp WorkspaceProxy
135+
var resp UpdateWorkspaceProxyResponse
142136
return resp, json.NewDecoder(res.Body).Decode(&resp)
143137
}
144138

enterprise/cli/workspaceproxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ func (r *RootCmd) workspaceProxy() *clibase.Cmd {
2828
r.deleteProxy(),
2929
r.listProxies(),
3030
r.patchProxy(),
31+
r.regenerateProxyToken(),
3132
},
3233
}
3334

3435
return cmd
3536
}
3637

37-
func (r *RootCmd) regenerateProxy() *clibase.Cmd {
38+
func (r *RootCmd) regenerateProxyToken() *clibase.Cmd {
3839
var (
3940
formatter = newUpdateProxyResponseFormatter()
4041
)

site/src/api/typesGenerated.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,6 @@ export interface CreateWorkspaceProxyRequest {
262262
readonly icon: string
263263
}
264264

265-
// From codersdk/workspaceproxy.go
266-
export interface CreateWorkspaceProxyResponse {
267-
readonly proxy: WorkspaceProxy
268-
readonly proxy_token: string
269-
}
270-
271265
// From codersdk/organizations.go
272266
export interface CreateWorkspaceRequest {
273267
readonly template_id: string
@@ -639,12 +633,6 @@ export interface PatchWorkspaceProxy {
639633
readonly regenerate_token: boolean
640634
}
641635

642-
// From codersdk/workspaceproxy.go
643-
export interface PatchWorkspaceProxyResponse {
644-
readonly proxy: WorkspaceProxy
645-
readonly proxy_token: string
646-
}
647-
648636
// From codersdk/deployment.go
649637
export interface PprofConfig {
650638
readonly enable: boolean
@@ -1043,6 +1031,12 @@ export interface UpdateWorkspaceAutostartRequest {
10431031
readonly schedule?: string
10441032
}
10451033

1034+
// From codersdk/workspaceproxy.go
1035+
export interface UpdateWorkspaceProxyResponse {
1036+
readonly proxy: WorkspaceProxy
1037+
readonly proxy_token: string
1038+
}
1039+
10461040
// From codersdk/workspaces.go
10471041
export interface UpdateWorkspaceRequest {
10481042
readonly name?: string

0 commit comments

Comments
 (0)