Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a36fbb

Browse files
committed
PR fixes
1 parent5ef834e commit3a36fbb

File tree

1 file changed

+25
-35
lines changed

1 file changed

+25
-35
lines changed

‎provider/parameter.go‎

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ const (
3030
// as unused options do not affect the final parameter value. The default value
3131
// is also ignored, assuming a value is provided.
3232
ValidationModeDefaultValidationMode=""
33-
// ValidationModeTemplateImport tolerates empty values, as the value might not be
34-
// available at import. It does not tolerate an invalid default or invalid option
35-
// values.
33+
// ValidationModeTemplateImport tolerates empty values as long as no 'validation'
34+
// block is specified. This allows for importing a template without having to
35+
// specify a value for every parameter. It does not tolerate an invalid default
36+
// or invalid option values.
3637
ValidationModeTemplateImportValidationMode="template-import"
3738
)
3839

@@ -428,14 +429,6 @@ func (v *Parameter) Valid(input *string, mode ValidationMode) (string, diag.Diag
428429
value=v.Default
429430
}
430431

431-
// TODO: When empty values want to be rejected, uncomment this.
432-
// coder/coder should update to use template import mode first,
433-
// before this is uncommented.
434-
//if value == nil && mode == ValidationModeDefault {
435-
//var empty string
436-
//value = &empty
437-
//}
438-
439432
// optionType might differ from parameter.Type. This is ok, and parameter.Type
440433
// should be used for the value type, and optionType for options.
441434
optionType,v.FormType,err=ValidateFormType(v.Type,len(v.Option),v.FormType)
@@ -477,39 +470,36 @@ func (v *Parameter) Valid(input *string, mode ValidationMode) (string, diag.Diag
477470

478471
// TODO: This is a bit of a hack. The current behavior states if validation
479472
// is given, then apply validation to unset values.
480-
// This should be removed, and all values should be validated. Meaning
481473
// value == nil should not be accepted in the first place.
482-
iflen(v.Validation)>0&&value==nil {
483-
empty:=""
484-
value=&empty
474+
// To fix this, value should be coerced to an empty string
475+
// if it is nil. Then let the validation logic always apply.
476+
iflen(v.Validation)==0&&value==nil {
477+
return"",nil
485478
}
486479

487-
//Value is only validated if itisset. If it is unset, validation
488-
// is skipped.
480+
//forcedValue ensures the valueisnot-nil.
481+
varforcedValuestring
489482
ifvalue!=nil {
490-
d:=v.validValue(*value,optionType,optionValues, cty.Path{})
491-
ifd.HasError() {
492-
return"",d
493-
}
483+
forcedValue=*value
484+
}
494485

495-
err=valueIsType(v.Type,*value)
496-
iferr!=nil {
497-
return"", diag.Diagnostics{
498-
{
499-
Severity:diag.Error,
500-
Summary:fmt.Sprintf("Parameter value is not of type %q",v.Type),
501-
Detail:err.Error(),
502-
},
503-
}
504-
}
486+
d:=v.validValue(forcedValue,optionType,optionValues, cty.Path{})
487+
ifd.HasError() {
488+
return"",d
505489
}
506490

507-
ifvalue==nil {
508-
// The previous behavior is to always write an empty string
509-
return"",nil
491+
err=valueIsType(v.Type,forcedValue)
492+
iferr!=nil {
493+
return"", diag.Diagnostics{
494+
{
495+
Severity:diag.Error,
496+
Summary:fmt.Sprintf("Parameter value is not of type %q",v.Type),
497+
Detail:err.Error(),
498+
},
499+
}
510500
}
511501

512-
return*value,nil
502+
returnforcedValue,nil
513503
}
514504

515505
func (v*Parameter)ValidOptions(optionTypeOptionType,modeValidationMode) (map[string]struct{}, diag.Diagnostics) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp