mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: secure and cross-domain subdomain-based proxying (#4136)
Co-authored-by: Kyle Carberry <kyle@carberry.com>
This commit is contained in:
co-authored by
Kyle Carberry
parent
80b45f1aa1
commit
6deef06ad2
+28
-3
@@ -51,7 +51,7 @@ type WorkspaceOptions struct {
|
||||
|
||||
// asRequestOption returns a function that can be used in (*Client).Request.
|
||||
// It modifies the request query parameters.
|
||||
func (o WorkspaceOptions) asRequestOption() requestOption {
|
||||
func (o WorkspaceOptions) asRequestOption() RequestOption {
|
||||
return func(r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
if o.IncludeDeleted {
|
||||
@@ -74,7 +74,7 @@ func (c *Client) DeletedWorkspace(ctx context.Context, id uuid.UUID) (Workspace,
|
||||
return c.getWorkspace(ctx, id, o.asRequestOption())
|
||||
}
|
||||
|
||||
func (c *Client) getWorkspace(ctx context.Context, id uuid.UUID, opts ...requestOption) (Workspace, error) {
|
||||
func (c *Client) getWorkspace(ctx context.Context, id uuid.UUID, opts ...RequestOption) (Workspace, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/workspaces/%s", id), nil, opts...)
|
||||
if err != nil {
|
||||
return Workspace{}, err
|
||||
@@ -254,7 +254,7 @@ type WorkspaceFilter struct {
|
||||
|
||||
// asRequestOption returns a function that can be used in (*Client).Request.
|
||||
// It modifies the request query parameters.
|
||||
func (f WorkspaceFilter) asRequestOption() requestOption {
|
||||
func (f WorkspaceFilter) asRequestOption() RequestOption {
|
||||
return func(r *http.Request) {
|
||||
var params []string
|
||||
// Make sure all user input is quoted to ensure it's parsed as a single
|
||||
@@ -314,3 +314,28 @@ func (c *Client) WorkspaceByOwnerAndName(ctx context.Context, owner string, name
|
||||
var workspace Workspace
|
||||
return workspace, json.NewDecoder(res.Body).Decode(&workspace)
|
||||
}
|
||||
|
||||
type GetAppHostResponse struct {
|
||||
Host string `json:"host"`
|
||||
}
|
||||
|
||||
// GetAppHost returns the site-wide application wildcard hostname without the
|
||||
// leading "*.", e.g. "apps.coder.com". Apps are accessible at:
|
||||
// "<app-name>--<agent-name>--<workspace-name>--<username>.<app-host>", e.g.
|
||||
// "my-app--agent--workspace--username.apps.coder.com".
|
||||
//
|
||||
// If the app host is not set, the response will contain an empty string.
|
||||
func (c *Client) GetAppHost(ctx context.Context) (GetAppHostResponse, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, "/api/v2/applications/host", nil)
|
||||
if err != nil {
|
||||
return GetAppHostResponse{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return GetAppHostResponse{}, readBodyAsError(res)
|
||||
}
|
||||
|
||||
var host GetAppHostResponse
|
||||
return host, json.NewDecoder(res.Body).Decode(&host)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user