mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00: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:
@ -8,9 +8,11 @@ import (
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/coderd/database"
|
||||
"github.com/coder/coder/coderd/httpapi"
|
||||
"github.com/coder/coder/coderd/parameter"
|
||||
"github.com/coder/coder/codersdk"
|
||||
)
|
||||
|
||||
@ -122,6 +124,37 @@ func (api *api) deleteParameter(rw http.ResponseWriter, r *http.Request) {
|
||||
})
|
||||
}
|
||||
|
||||
func convertParameterSchema(parameterSchema database.ParameterSchema) (codersdk.ParameterSchema, error) {
|
||||
contains := []string{}
|
||||
if parameterSchema.ValidationCondition != "" {
|
||||
var err error
|
||||
contains, _, err = parameter.Contains(parameterSchema.ValidationCondition)
|
||||
if err != nil {
|
||||
return codersdk.ParameterSchema{}, xerrors.Errorf("parse validation condition for %q: %w", parameterSchema.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
return codersdk.ParameterSchema{
|
||||
ID: parameterSchema.ID,
|
||||
CreatedAt: parameterSchema.CreatedAt,
|
||||
JobID: parameterSchema.JobID,
|
||||
Name: parameterSchema.Name,
|
||||
Description: parameterSchema.Description,
|
||||
DefaultSourceScheme: string(parameterSchema.DefaultSourceScheme),
|
||||
DefaultSourceValue: parameterSchema.DefaultSourceValue,
|
||||
AllowOverrideSource: parameterSchema.AllowOverrideSource,
|
||||
DefaultDestinationScheme: string(parameterSchema.DefaultDestinationScheme),
|
||||
AllowOverrideDestination: parameterSchema.AllowOverrideDestination,
|
||||
DefaultRefresh: parameterSchema.DefaultRefresh,
|
||||
RedisplayValue: parameterSchema.RedisplayValue,
|
||||
ValidationError: parameterSchema.ValidationError,
|
||||
ValidationCondition: parameterSchema.ValidationCondition,
|
||||
ValidationTypeSystem: string(parameterSchema.ValidationTypeSystem),
|
||||
ValidationValueType: parameterSchema.ValidationValueType,
|
||||
ValidationContains: contains,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func convertParameterValue(parameterValue database.ParameterValue) codersdk.Parameter {
|
||||
return codersdk.Parameter{
|
||||
ID: parameterValue.ID,
|
||||
|
Reference in New Issue
Block a user