Skip to content

Commit 358b641

Browse files
authored
chore: skip parameter resolution for dynamic params (#17922)
Pass through the user input as is. The previous code only passed through parameters that existed in the db (static params). This would omit conditional params. Validation is enforced by the dynamic params websocket, so validation at this point is not required.
1 parent fe733af commit 358b641

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

coderd/wsbuilder/wsbuilder.go

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -593,30 +593,42 @@ func (b *Builder) getParameters() (names, values []string, err error) {
593593
return nil, nil, BuildError{http.StatusBadRequest, "Unable to build workspace with unsupported parameters", err}
594594
}
595595

596+
if b.dynamicParametersEnabled {
597+
// Dynamic parameters skip all parameter validation.
598+
// Pass the user's input as is.
599+
// TODO: The previous behavior was only to pass param values
600+
// for parameters that exist. Since dynamic params can have
601+
// conditional parameter existence, the static frame of reference
602+
// is not sufficient. So assume the user is correct, or pull in the
603+
// dynamic param code to find the actual parameters.
604+
for _, value := range b.richParameterValues {
605+
names = append(names, value.Name)
606+
values = append(values, value.Value)
607+
}
608+
b.parameterNames = &names
609+
b.parameterValues = &values
610+
return names, values, nil
611+
}
612+
596613
resolver := codersdk.ParameterResolver{
597614
Rich: db2sdk.WorkspaceBuildParameters(lastBuildParameters),
598615
}
616+
599617
for _, templateVersionParameter := range templateVersionParameters {
600618
tvp, err := db2sdk.TemplateVersionParameter(templateVersionParameter)
601619
if err != nil {
602620
return nil, nil, BuildError{http.StatusInternalServerError, "failed to convert template version parameter", err}
603621
}
604622

605-
var value string
606-
if !b.dynamicParametersEnabled {
607-
var err error
608-
value, err = resolver.ValidateResolve(
609-
tvp,
610-
b.findNewBuildParameterValue(templateVersionParameter.Name),
611-
)
612-
if err != nil {
613-
// At this point, we've queried all the data we need from the database,
614-
// so the only errors are problems with the request (missing data, failed
615-
// validation, immutable parameters, etc.)
616-
return nil, nil, BuildError{http.StatusBadRequest, fmt.Sprintf("Unable to validate parameter %q", templateVersionParameter.Name), err}
617-
}
618-
} else {
619-
value = resolver.Resolve(tvp, b.findNewBuildParameterValue(templateVersionParameter.Name))
623+
value, err := resolver.ValidateResolve(
624+
tvp,
625+
b.findNewBuildParameterValue(templateVersionParameter.Name),
626+
)
627+
if err != nil {
628+
// At this point, we've queried all the data we need from the database,
629+
// so the only errors are problems with the request (missing data, failed
630+
// validation, immutable parameters, etc.)
631+
return nil, nil, BuildError{http.StatusBadRequest, fmt.Sprintf("Unable to validate parameter %q", templateVersionParameter.Name), err}
620632
}
621633

622634
names = append(names, templateVersionParameter.Name)

0 commit comments

Comments
 (0)