mirror of
https://github.com/coder/coder.git
synced 2025-07-21 01:28:49 +00:00
chore: loosen static validation when using dynamic parameters (#17516)
Co-authored-by: Steven Masley <stevenmasley@gmail.com>
This commit is contained in:
@ -227,6 +227,7 @@ type CreateWorkspaceRequest struct {
|
||||
RichParameterValues []WorkspaceBuildParameter `json:"rich_parameter_values,omitempty"`
|
||||
AutomaticUpdates AutomaticUpdates `json:"automatic_updates,omitempty"`
|
||||
TemplateVersionPresetID uuid.UUID `json:"template_version_preset_id,omitempty" format:"uuid"`
|
||||
EnableDynamicParameters bool `json:"enable_dynamic_parameters,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) OrganizationByName(ctx context.Context, name string) (Organization, error) {
|
||||
|
@ -190,6 +190,26 @@ func (r *ParameterResolver) ValidateResolve(p TemplateVersionParameter, v *Works
|
||||
return resolvedValue.Value, nil
|
||||
}
|
||||
|
||||
// Resolve returns the value of the parameter. It does not do any validation,
|
||||
// and is meant for use with the new dynamic parameters code path.
|
||||
func (r *ParameterResolver) Resolve(p TemplateVersionParameter, v *WorkspaceBuildParameter) string {
|
||||
prevV := r.findLastValue(p)
|
||||
// First, the provided value
|
||||
resolvedValue := v
|
||||
// Second, previous value if not ephemeral
|
||||
if resolvedValue == nil && !p.Ephemeral {
|
||||
resolvedValue = prevV
|
||||
}
|
||||
// Last, default value
|
||||
if resolvedValue == nil {
|
||||
resolvedValue = &WorkspaceBuildParameter{
|
||||
Name: p.Name,
|
||||
Value: p.DefaultValue,
|
||||
}
|
||||
}
|
||||
return resolvedValue.Value
|
||||
}
|
||||
|
||||
// findLastValue finds the value from the previous build and returns it, or nil if the parameter had no value in the
|
||||
// last build.
|
||||
func (r *ParameterResolver) findLastValue(p TemplateVersionParameter) *WorkspaceBuildParameter {
|
||||
|
Reference in New Issue
Block a user