feat: Expose managed variables via API (#6134)

* WIP

* hcl

* useManagedVariables

* fix

* Fix

* Fix

* fix

* go:build

* Fix

* fix: bool flag

* Insert template variables

* API

* fix

* Expose via API

* More wiring

* CLI for testing purposes

* WIP

* Delete FIXME

* planVars

* WIP

* WIP

* UserVariableValues

* no dry run

* Dry run

* Done FIXME

* Fix

* Fix: CLI

* Fix: migration

* API tests

* Test info

* Tests

* More tests

* fix: lint

* Fix: authz

* Address PR comments

* Fix

* fix

* fix
This commit is contained in:
Marcin Tojek
2023-02-15 18:24:15 +01:00
committed by GitHub
parent f0f39b4892
commit 3b7b96ac28
41 changed files with 2423 additions and 667 deletions
+7
View File
@@ -54,6 +54,13 @@ type CreateTemplateVersionRequest struct {
// ParameterValues allows for additional parameters to be provided
// during the dry-run provision stage.
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"`
UserVariableValues []VariableValue `json:"user_variable_values,omitempty"`
}
type VariableValue struct {
Name string `json:"name"`
Value string `json:"value"`
}
// CreateTemplateRequest provides options when creating a template.
+26
View File
@@ -56,6 +56,17 @@ type TemplateVersionParameterOption struct {
Icon string `json:"icon"`
}
// TemplateVersionVariable represents a managed template variable.
type TemplateVersionVariable struct {
Name string `json:"name"`
Description string `json:"description"`
Type string `json:"type" enums:"string,number,bool"`
Value string `json:"value"`
DefaultValue string `json:"default_value"`
Required bool `json:"required"`
Sensitive bool `json:"sensitive"`
}
// 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)
@@ -139,6 +150,20 @@ func (c *Client) TemplateVersionResources(ctx context.Context, version uuid.UUID
return resources, json.NewDecoder(res.Body).Decode(&resources)
}
// TemplateVersionVariables returns resources a template version variables.
func (c *Client) TemplateVersionVariables(ctx context.Context, version uuid.UUID) ([]TemplateVersionVariable, error) {
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templateversions/%s/variables", version), nil)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return nil, ReadBodyAsError(res)
}
var variables []TemplateVersionVariable
return variables, json.NewDecoder(res.Body).Decode(&variables)
}
// TemplateVersionLogsBefore returns logs that occurred before a specific log ID.
func (c *Client) TemplateVersionLogsBefore(ctx context.Context, version uuid.UUID, before int64) ([]ProvisionerJobLog, error) {
return c.provisionerJobLogsBefore(ctx, fmt.Sprintf("/api/v2/templateversions/%s/logs", version), before)
@@ -155,6 +180,7 @@ type CreateTemplateVersionDryRunRequest struct {
WorkspaceName string `json:"workspace_name"`
ParameterValues []CreateParameterRequest `json:"parameter_values"`
RichParameterValues []WorkspaceBuildParameter `json:"rich_parameter_values"`
UserVariableValues []VariableValue `json:"user_variable_values,omitempty"`
}
// CreateTemplateVersionDryRun begins a dry-run provisioner job against the