chore: Reuse ComputedParmeter, remove duplicated codersdk type (#2477)

* chore: Reuse ComputedParmeter instead of custom type
This commit is contained in:
Steven Masley
2022-06-17 15:20:13 -05:00
committed by GitHub
parent 0b6efce466
commit 4616499030
4 changed files with 21 additions and 37 deletions
+7
View File
@@ -41,6 +41,13 @@ const (
ParameterTypeSystemHCL ParameterTypeSystem = "hcl"
)
type ComputedParameter struct {
Parameter
SourceValue string `json:"source_value"`
SchemaID uuid.UUID `json:"schema_id"`
DefaultSourceValue bool `json:"default_source_value"`
}
// Parameter represents a set value for the scope.
type Parameter struct {
ID uuid.UUID `json:"id"`
+2 -17
View File
@@ -22,21 +22,6 @@ type TemplateVersion struct {
Readme string `json:"readme"`
}
// TemplateVersionParameter represents a computed parameter value.
type TemplateVersionParameter struct {
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 ParameterSourceScheme `json:"source_scheme"`
SourceValue string `json:"source_value"`
DestinationScheme ParameterDestinationScheme `json:"destination_scheme"`
SchemaID uuid.UUID `json:"schema_id"`
DefaultSourceValue bool `json:"default_source_value"`
}
// 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)
@@ -79,7 +64,7 @@ func (c *Client) TemplateVersionSchema(ctx context.Context, version uuid.UUID) (
}
// TemplateVersionParameters returns computed parameters for a template version.
func (c *Client) TemplateVersionParameters(ctx context.Context, version uuid.UUID) ([]TemplateVersionParameter, error) {
func (c *Client) TemplateVersionParameters(ctx context.Context, version uuid.UUID) ([]ComputedParameter, error) {
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/templateversions/%s/parameters", version), nil)
if err != nil {
return nil, err
@@ -88,7 +73,7 @@ func (c *Client) TemplateVersionParameters(ctx context.Context, version uuid.UUI
if res.StatusCode != http.StatusOK {
return nil, readBodyAsError(res)
}
var params []TemplateVersionParameter
var params []ComputedParameter
return params, json.NewDecoder(res.Body).Decode(&params)
}