mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
feat: Expose the values contained in an HCL validation string to the API (#1587)
* feat: Expose the values contained in an HCL validation string to the API This allows the frontend to render inputs displaying these values! * Update codersdk/parameters.go Co-authored-by: Cian Johnston <cian@coder.com> * Call a spade a space * Fix linting errors with type conversion Co-authored-by: Cian Johnston <cian@coder.com>
This commit is contained in:
co-authored by
Cian Johnston
parent
ad9bdb7bd1
commit
38ee519f42
+31
-8
@@ -24,14 +24,37 @@ const (
|
||||
|
||||
// Parameter represents a set value for the scope.
|
||||
type Parameter struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
Scope ParameterScope `db:"scope" json:"scope"`
|
||||
ScopeID uuid.UUID `db:"scope_id" json:"scope_id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
SourceScheme database.ParameterSourceScheme `db:"source_scheme" json:"source_scheme"`
|
||||
DestinationScheme database.ParameterDestinationScheme `db:"destination_scheme" json:"destination_scheme"`
|
||||
ID uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Scope ParameterScope `json:"scope"`
|
||||
ScopeID uuid.UUID `json:"scope_id"`
|
||||
Name string `json:"name"`
|
||||
SourceScheme database.ParameterSourceScheme `json:"source_scheme"`
|
||||
DestinationScheme database.ParameterDestinationScheme `json:"destination_scheme"`
|
||||
}
|
||||
|
||||
type ParameterSchema struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
JobID uuid.UUID `json:"job_id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
DefaultSourceScheme string `json:"default_source_scheme"`
|
||||
DefaultSourceValue string `json:"default_source_value"`
|
||||
AllowOverrideSource bool `json:"allow_override_source"`
|
||||
DefaultDestinationScheme string `json:"default_destination_scheme"`
|
||||
AllowOverrideDestination bool `json:"allow_override_destination"`
|
||||
DefaultRefresh string `json:"default_refresh"`
|
||||
RedisplayValue bool `json:"redisplay_value"`
|
||||
ValidationError string `json:"validation_error"`
|
||||
ValidationCondition string `json:"validation_condition"`
|
||||
ValidationTypeSystem string `json:"validation_type_system"`
|
||||
ValidationValueType string `json:"validation_value_type"`
|
||||
|
||||
// This is a special array of items provided if the validation condition
|
||||
// explicitly states the value must be one of a set.
|
||||
ValidationContains []string `json:"validation_contains"`
|
||||
}
|
||||
|
||||
// CreateParameterRequest is used to create a new parameter value for a scope.
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/coder/coder/coderd/database"
|
||||
"github.com/coder/coder/coderd/parameter"
|
||||
)
|
||||
|
||||
@@ -24,9 +23,6 @@ type TemplateVersion struct {
|
||||
Readme string `json:"readme"`
|
||||
}
|
||||
|
||||
// TemplateVersionParameterSchema represents a parameter parsed from template version source.
|
||||
type TemplateVersionParameterSchema database.ParameterSchema
|
||||
|
||||
// TemplateVersionParameter represents a computed parameter value.
|
||||
type TemplateVersionParameter parameter.ComputedValue
|
||||
|
||||
@@ -58,7 +54,7 @@ func (c *Client) CancelTemplateVersion(ctx context.Context, version uuid.UUID) e
|
||||
}
|
||||
|
||||
// TemplateVersionSchema returns schemas for a template version by ID.
|
||||
func (c *Client) TemplateVersionSchema(ctx context.Context, version uuid.UUID) ([]TemplateVersionParameterSchema, error) {
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -67,7 +63,7 @@ func (c *Client) TemplateVersionSchema(ctx context.Context, version uuid.UUID) (
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return nil, readBodyAsError(res)
|
||||
}
|
||||
var params []TemplateVersionParameterSchema
|
||||
var params []ParameterSchema
|
||||
return params, json.NewDecoder(res.Body).Decode(¶ms)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user