mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: Add workspace proxy enterprise cli commands (#7176)
* feat: Add workspace proxy enterprise cli commands * chore: Handle custom workspace proxy options. Remove excess * chore: Add endpoint to register workspace proxies
This commit is contained in:
+33
-10
@@ -3,6 +3,7 @@ package codersdk
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -12,16 +13,16 @@ import (
|
||||
)
|
||||
|
||||
type WorkspaceProxy struct {
|
||||
ID uuid.UUID `db:"id" json:"id" format:"uuid"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
ID uuid.UUID `db:"id" json:"id" format:"uuid" table:"id"`
|
||||
Name string `db:"name" json:"name" table:"name,default_sort"`
|
||||
Icon string `db:"icon" json:"icon" table:"icon"`
|
||||
// Full url including scheme of the proxy api url: https://us.example.com
|
||||
URL string `db:"url" json:"url"`
|
||||
URL string `db:"url" json:"url" table:"url"`
|
||||
// WildcardHostname with the wildcard for subdomain based app hosting: *.us.example.com
|
||||
WildcardHostname string `db:"wildcard_hostname" json:"wildcard_hostname"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at" format:"date-time"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at" format:"date-time"`
|
||||
Deleted bool `db:"deleted" json:"deleted"`
|
||||
WildcardHostname string `db:"wildcard_hostname" json:"wildcard_hostname" table:"wildcard_hostname"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at" format:"date-time" table:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at" format:"date-time" table:"updated_at"`
|
||||
Deleted bool `db:"deleted" json:"deleted" table:"deleted"`
|
||||
}
|
||||
|
||||
type CreateWorkspaceProxyRequest struct {
|
||||
@@ -33,8 +34,9 @@ type CreateWorkspaceProxyRequest struct {
|
||||
}
|
||||
|
||||
type CreateWorkspaceProxyResponse struct {
|
||||
Proxy WorkspaceProxy `json:"proxy"`
|
||||
ProxyToken string `json:"proxy_token"`
|
||||
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) {
|
||||
@@ -71,3 +73,24 @@ func (c *Client) WorkspaceProxies(ctx context.Context) ([]WorkspaceProxy, error)
|
||||
var proxies []WorkspaceProxy
|
||||
return proxies, json.NewDecoder(res.Body).Decode(&proxies)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteWorkspaceProxyByName(ctx context.Context, name string) error {
|
||||
res, err := c.Request(ctx, http.MethodDelete,
|
||||
fmt.Sprintf("/api/v2/workspaceproxies/%s", name),
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("make request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return ReadBodyAsError(res)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) DeleteWorkspaceProxyByID(ctx context.Context, id uuid.UUID) error {
|
||||
return c.DeleteWorkspaceProxyByName(ctx, id.String())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user