Skip to content

Commit

Permalink
fix validation func
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Dec 19, 2023
1 parent 1b56dae commit d7a5e51
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,14 @@ func NewAddService(
Name: ServiceConfigArgName,
IsOptional: false,
ZeroValueProvider: builtin_argument.ZeroValueProvider[*service_config.ServiceConfig],
Validator: nil,
//Validator: func(value starlark.Value) *startosis_errors.InterpretationError {
// // we just try to convert the configs here to validate their shape, to avoid code duplication with Interpret
// if _, _, err := validateAndConvertConfigAndReadyCondition(
// serviceNetwork,
// value,
// packageId, // use package id for root locator
// packageId,
// packageContentProvider,
// packageReplaceOptions); err != nil {
// return err
// }
// return nil
//},
Validator: func(value starlark.Value) *startosis_errors.InterpretationError {
// we just try to convert the configs here to validate their shape, to avoid code duplication with Interpret
_, ok := value.(*service_config.ServiceConfig)
if !ok {
return startosis_errors.NewInterpretationError("The '%s' argument is not a ServiceConfig (was '%s').", ConfigsArgName, reflect.TypeOf(value))
}
return nil
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,11 @@ func NewAddServices(
Name: ConfigsArgName,
IsOptional: false,
ZeroValueProvider: builtin_argument.ZeroValueProvider[*starlark.Dict],
// TODO: add a validator
Validator: func(value starlark.Value) *startosis_errors.InterpretationError {
// we just try to convert the configs here to validate their shape, to avoid code duplication with Interpret
if _, _, err := validateAndConvertConfigsAndReadyConditions(
serviceNetwork,
value,
"",
packageId,
packageContentProvider,
packageReplaceOptions); err != nil {
return err
_, ok := value.(*starlark.Dict)
if !ok {
return startosis_errors.NewInterpretationError("The '%s' argument is not a ServiceConfig (was '%s').", ConfigsArgName, reflect.TypeOf(value))
}
return nil
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (config *ServiceConfig) ToKurtosisType(
if !found {
return nil, startosis_errors.NewInterpretationError("Required attribute '%s' could not be found on type '%s'", ImageAttr, ServiceConfigTypeName)
}
imageName, imageBuildSpec, interpretationErr = convertImageAttr(
imageName, imageBuildSpec, interpretationErr = convertImage(
rawImageAttrValue,
locatorOfModuleInWhichThisBuiltInIsBeingCalled,
packageId,
Expand Down Expand Up @@ -580,15 +580,15 @@ func convertFilesArguments(attrNameForLogging string, filesDict *starlark.Dict)
return filesArtifacts, persistentDirectories, nil
}

// If [rawImageAttrValue] is an ImageBuildSpec type, returns name for the image to build and ImageBuildSpec converted to KurtosisType
// If [rawImageAttrValue] is a string, returns the image name with no image build spec (image will be fetched from local cache or remote)
func convertImageAttr(
rawImageAttrValue starlark.Value,
// If [image] is an ImageBuildSpec type, returns name for the image to build and ImageBuildSpec converted to KurtosisType
// If [image] is a string, returns the image name with no image build spec (image will be fetched from local cache or remote)
func convertImage(
image starlark.Value,
locatorOfModuleInWhichThisBuiltInIsBeingCalled string,
packageId string,
packageContentProvider startosis_packages.PackageContentProvider,
packageReplaceOptions map[string]string) (string, *image_build_spec.ImageBuildSpec, *startosis_errors.InterpretationError) {
imageBuildSpecStarlarkType, isImageBuildSpecStarlarkType := rawImageAttrValue.(*ImageBuildSpec)
imageBuildSpecStarlarkType, isImageBuildSpecStarlarkType := image.(*ImageBuildSpec)
if isImageBuildSpecStarlarkType {
imageBuildSpec, interpretationErr := imageBuildSpecStarlarkType.ToKurtosisType(locatorOfModuleInWhichThisBuiltInIsBeingCalled, packageId, packageContentProvider, packageReplaceOptions)
if interpretationErr != nil {
Expand All @@ -601,7 +601,7 @@ func convertImageAttr(
logrus.Debugf("CONVERT IMAGE ATTRIBUTE: %v %v", imageName, imageBuildSpec)
return imageName, imageBuildSpec, nil
} else {
imageName, interpretationErr := kurtosis_types.SafeCastToString(rawImageAttrValue, ImageAttr)
imageName, interpretationErr := kurtosis_types.SafeCastToString(image, ImageAttr)
if interpretationErr != nil {
return "", nil, interpretationErr
}
Expand Down

0 comments on commit d7a5e51

Please sign in to comment.