mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Implement experiment gated CRUD for workspace proxies (#6928)
* feat: Implement basic moon crud * chore: Implement enterprise endpoints for moons
This commit is contained in:
@@ -45,6 +45,7 @@ const (
|
||||
FeatureExternalProvisionerDaemons FeatureName = "external_provisioner_daemons"
|
||||
FeatureAppearance FeatureName = "appearance"
|
||||
FeatureAdvancedTemplateScheduling FeatureName = "advanced_template_scheduling"
|
||||
FeatureWorkspaceProxy FeatureName = "workspace_proxy"
|
||||
)
|
||||
|
||||
// FeatureNames must be kept in-sync with the Feature enum above.
|
||||
@@ -59,6 +60,7 @@ var FeatureNames = []FeatureName{
|
||||
FeatureExternalProvisionerDaemons,
|
||||
FeatureAppearance,
|
||||
FeatureAdvancedTemplateScheduling,
|
||||
FeatureWorkspaceProxy,
|
||||
}
|
||||
|
||||
// Humanize returns the feature name in a human-readable format.
|
||||
@@ -1559,6 +1561,10 @@ const (
|
||||
// for all users.
|
||||
ExperimentTemplateEditor Experiment = "template_editor"
|
||||
|
||||
// ExperimentMoons enabled the workspace proxy endpoints and CRUD. This
|
||||
// feature is not yet complete in functionality.
|
||||
ExperimentMoons Experiment = "moons"
|
||||
|
||||
// Add new experiments here!
|
||||
// ExperimentExample Experiment = "example"
|
||||
)
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package codersdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type CreateWorkspaceProxyRequest struct {
|
||||
Name string `json:"name"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Icon string `json:"icon"`
|
||||
URL string `json:"url"`
|
||||
WildcardHostname string `json:"wildcard_hostname"`
|
||||
}
|
||||
|
||||
type WorkspaceProxy struct {
|
||||
ID uuid.UUID `db:"id" json:"id" format:"uuid"`
|
||||
OrganizationID uuid.UUID `db:"organization_id" json:"organization_id" format:"uuid"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
// Full url including scheme of the proxy api url: https://us.example.com
|
||||
URL string `db:"url" json:"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"`
|
||||
}
|
||||
|
||||
func (c *Client) CreateWorkspaceProxy(ctx context.Context, req CreateWorkspaceProxyRequest) (WorkspaceProxy, error) {
|
||||
res, err := c.Request(ctx, http.MethodPost,
|
||||
"/api/v2/workspaceproxies",
|
||||
req,
|
||||
)
|
||||
if err != nil {
|
||||
return WorkspaceProxy{}, xerrors.Errorf("make request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusCreated {
|
||||
return WorkspaceProxy{}, ReadBodyAsError(res)
|
||||
}
|
||||
var resp WorkspaceProxy
|
||||
return resp, json.NewDecoder(res.Body).Decode(&resp)
|
||||
}
|
||||
|
||||
func (c *Client) WorkspaceProxiesByOrganization(ctx context.Context) ([]WorkspaceProxy, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet,
|
||||
"/api/v2/workspaceproxies",
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("make request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return nil, ReadBodyAsError(res)
|
||||
}
|
||||
|
||||
var proxies []WorkspaceProxy
|
||||
return proxies, json.NewDecoder(res.Body).Decode(&proxies)
|
||||
}
|
||||
Reference in New Issue
Block a user