MCPcopy
hub / github.com/devtron-labs/devtron / validatePluginVariable

Function validatePluginVariable

pkg/plugin/GlobalPluginService.go:2354–2391  ·  view source on GitHub ↗

ValidateStepVariable validates the step variable It validates the following: - variable.IsExposed is false, then it's an internal variable (not exposed in UI) and no validation is required - variable.Name is mandatory - format commonBean.Format is mandatory - variable.Value should be a valid value f

(variable *bean2.PluginVariableDto)

Source from the content-addressed store, hash-verified

2352// Returns:
2353// - error: validation error (util.ApiError)
2354func validatePluginVariable(variable *bean2.PluginVariableDto) error {
2355 if variable == nil {
2356 return nil
2357 }
2358 if !variable.IsExposed {
2359 // if the variable is not exposed, then it's an internal variable (not exposed in UI).
2360 // for internal variables, we don't need to validate the value.
2361 // assuming internal variables are always valid.
2362 return nil
2363 }
2364 // validate name
2365 // if invalid, return error
2366 if len(variable.Name) == 0 {
2367 errMsg := fmt.Sprintf("variable name is mandatory")
2368 return util.NewApiError(http.StatusBadRequest, errMsg, errMsg)
2369 }
2370 // validate format
2371 // if invalid, return error
2372 // format is mandatory
2373 format, err := commonBean.NewFormat(variable.Format.String())
2374 if err != nil {
2375 errMsg := fmt.Sprintf("variable '%s' has invalid format '%s'", variable.Name, variable.Format)
2376 return util.NewApiError(http.StatusBadRequest, errMsg, errMsg)
2377 }
2378
2379 // value is optional
2380 if len(variable.GetValue()) != 0 {
2381 // validate value based on format
2382 // convert value to format
2383 // if invalid, return error
2384 _, convErr := format.Convert(variable.GetValue())
2385 if convErr != nil {
2386 errMsg := fmt.Sprintf("variable '%s' has invalid value '%s' for format '%s'", variable.Name, variable.Value, variable.Format)
2387 return util.NewApiError(http.StatusBadRequest, errMsg, errMsg)
2388 }
2389 }
2390 return nil
2391}
2392
2393func (impl *GlobalPluginServiceImpl) GetNewPluginStepsDtoByRefPluginIdentifier(identifier string) (*bean2.PluginStepsDto, error) {
2394 pluginMetadata, err := impl.globalPluginRepository.GetPluginMetadataByPluginIdentifier(identifier)

Callers 1

validatePluginVariablesFunction · 0.85

Calls 3

NewApiErrorFunction · 0.92
StringMethod · 0.65
GetValueMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…