mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Add basic support for rich parameters to coderd and provisionerd (#5710)
This commit is contained in:
@@ -87,7 +87,8 @@ type CreateWorkspaceRequest struct {
|
||||
TTLMillis *int64 `json:"ttl_ms,omitempty"`
|
||||
// ParameterValues allows for additional parameters to be provided
|
||||
// during the initial provision.
|
||||
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"`
|
||||
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"`
|
||||
RichParameterValues []WorkspaceBuildParameter `json:"rich_parameter_values,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) Organization(ctx context.Context, id uuid.UUID) (Organization, error) {
|
||||
|
||||
@@ -24,6 +24,29 @@ type TemplateVersion struct {
|
||||
CreatedBy User `json:"created_by"`
|
||||
}
|
||||
|
||||
// TemplateVersionParameter represents a parameter for a template version.
|
||||
type TemplateVersionParameter struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
Mutable bool `json:"mutable"`
|
||||
DefaultValue string `json:"default_value"`
|
||||
Icon string `json:"icon"`
|
||||
Options []TemplateVersionParameterOption `json:"options"`
|
||||
ValidationError string `json:"validation_error"`
|
||||
ValidationRegex string `json:"validation_regex"`
|
||||
ValidationMin int32 `json:"validation_min"`
|
||||
ValidationMax int32 `json:"validation_max"`
|
||||
}
|
||||
|
||||
// TemplateVersionParameterOption represents a selectable option for a template parameter.
|
||||
type TemplateVersionParameterOption struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Value string `json:"value"`
|
||||
Icon string `json:"icon"`
|
||||
}
|
||||
|
||||
// TemplateVersion returns a template version by ID.
|
||||
func (c *Client) TemplateVersion(ctx context.Context, id uuid.UUID) (TemplateVersion, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templateversions/%s", id), nil)
|
||||
@@ -51,6 +74,20 @@ func (c *Client) CancelTemplateVersion(ctx context.Context, version uuid.UUID) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// TemplateVersionParameters returns parameters a template version exposes.
|
||||
func (c *Client) TemplateVersionRichParameters(ctx context.Context, version uuid.UUID) ([]TemplateVersionParameter, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templateversions/%s/rich-parameters", version), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return nil, readBodyAsError(res)
|
||||
}
|
||||
var params []TemplateVersionParameter
|
||||
return params, json.NewDecoder(res.Body).Decode(¶ms)
|
||||
}
|
||||
|
||||
// TemplateVersionSchema returns schemas for a template version by ID.
|
||||
func (c *Client) TemplateVersionSchema(ctx context.Context, version uuid.UUID) ([]ParameterSchema, error) {
|
||||
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templateversions/%s/schema", version), nil)
|
||||
|
||||
@@ -95,6 +95,12 @@ type WorkspaceResourceMetadata struct {
|
||||
Sensitive bool `json:"sensitive"`
|
||||
}
|
||||
|
||||
// WorkspaceBuildParameter represents a parameter specific for a workspace build.
|
||||
type WorkspaceBuildParameter struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
||||
// WorkspaceBuild returns a single workspace build for a workspace.
|
||||
// If history is "", the latest version is returned.
|
||||
func (c *Client) WorkspaceBuild(ctx context.Context, id uuid.UUID) (WorkspaceBuild, error) {
|
||||
|
||||
Reference in New Issue
Block a user