mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
chore: Allow editing proxy fields via api. (#7435)
* chore: Add ability to update workspace proxy fields
This commit is contained in:
@@ -46,9 +46,10 @@ type ProxyHealthReport struct {
|
||||
}
|
||||
|
||||
type WorkspaceProxy struct {
|
||||
ID uuid.UUID `json:"id" format:"uuid" table:"id"`
|
||||
Name string `json:"name" table:"name,default_sort"`
|
||||
Icon string `json:"icon" table:"icon"`
|
||||
ID uuid.UUID `json:"id" format:"uuid" table:"id"`
|
||||
Name string `json:"name" table:"name,default_sort"`
|
||||
DisplayName string `json:"display_name" table:"display_name"`
|
||||
Icon string `json:"icon" table:"icon"`
|
||||
// Full url including scheme of the proxy api url: https://us.example.com
|
||||
URL string `json:"url" table:"url"`
|
||||
// WildcardHostname with the wildcard for subdomain based app hosting: *.us.example.com
|
||||
@@ -69,26 +70,26 @@ type CreateWorkspaceProxyRequest struct {
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
|
||||
type CreateWorkspaceProxyResponse struct {
|
||||
type UpdateWorkspaceProxyResponse struct {
|
||||
Proxy WorkspaceProxy `json:"proxy" table:"proxy,recursive"`
|
||||
// The recursive table sort is not working very well.
|
||||
ProxyToken string `json:"proxy_token" table:"proxy token,default_sort"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateWorkspaceProxy(ctx context.Context, req CreateWorkspaceProxyRequest) (CreateWorkspaceProxyResponse, error) {
|
||||
func (c *Client) CreateWorkspaceProxy(ctx context.Context, req CreateWorkspaceProxyRequest) (UpdateWorkspaceProxyResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodPost,
|
||||
"/api/v2/workspaceproxies",
|
||||
req,
|
||||
)
|
||||
if err != nil {
|
||||
return CreateWorkspaceProxyResponse{}, xerrors.Errorf("make request: %w", err)
|
||||
return UpdateWorkspaceProxyResponse{}, xerrors.Errorf("make request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusCreated {
|
||||
return CreateWorkspaceProxyResponse{}, ReadBodyAsError(res)
|
||||
return UpdateWorkspaceProxyResponse{}, ReadBodyAsError(res)
|
||||
}
|
||||
var resp CreateWorkspaceProxyResponse
|
||||
var resp UpdateWorkspaceProxyResponse
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
@@ -110,6 +111,31 @@ func (c *Client) WorkspaceProxies(ctx context.Context) ([]WorkspaceProxy, error)
|
||||
return proxies, json.NewDecoder(res.Body).Decode(&proxies)
|
||||
}
|
||||
|
||||
type PatchWorkspaceProxy struct {
|
||||
ID uuid.UUID `json:"id" format:"uuid" validate:"required"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
DisplayName string `json:"display_name" validate:"required"`
|
||||
Icon string `json:"icon" validate:"required"`
|
||||
RegenerateToken bool `json:"regenerate_token"`
|
||||
}
|
||||
|
||||
func (c *Client) PatchWorkspaceProxy(ctx context.Context, req PatchWorkspaceProxy) (UpdateWorkspaceProxyResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodPatch,
|
||||
fmt.Sprintf("/api/v2/workspaceproxies/%s", req.ID.String()),
|
||||
req,
|
||||
)
|
||||
if err != nil {
|
||||
return UpdateWorkspaceProxyResponse{}, xerrors.Errorf("make request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return UpdateWorkspaceProxyResponse{}, ReadBodyAsError(res)
|
||||
}
|
||||
var resp UpdateWorkspaceProxyResponse
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteWorkspaceProxyByName(ctx context.Context, name string) error {
|
||||
res, err := c.Request(ctx, http.MethodDelete,
|
||||
fmt.Sprintf("/api/v2/workspaceproxies/%s", name),
|
||||
@@ -131,6 +157,28 @@ func (c *Client) DeleteWorkspaceProxyByID(ctx context.Context, id uuid.UUID) err
|
||||
return c.DeleteWorkspaceProxyByName(ctx, id.String())
|
||||
}
|
||||
|
||||
func (c *Client) WorkspaceProxyByName(ctx context.Context, name string) (WorkspaceProxy, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet,
|
||||
fmt.Sprintf("/api/v2/workspaceproxies/%s", name),
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return WorkspaceProxy{}, xerrors.Errorf("make request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return WorkspaceProxy{}, ReadBodyAsError(res)
|
||||
}
|
||||
|
||||
var resp WorkspaceProxy
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
func (c *Client) WorkspaceProxyByID(ctx context.Context, id uuid.UUID) (WorkspaceProxy, error) {
|
||||
return c.WorkspaceProxyByName(ctx, id.String())
|
||||
}
|
||||
|
||||
type RegionsResponse struct {
|
||||
Regions []Region `json:"regions"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user