MCPcopy
hub / github.com/purpleidea/mgmt / Validate

Function Validate

engine/resources.go:328–353  ·  view source on GitHub ↗

Validate validates a resource by checking multiple aspects. This is the main entry point for running all the validation steps on a resource.

(res Res)

Source from the content-addressed store, hash-verified

326// Validate validates a resource by checking multiple aspects. This is the main
327// entry point for running all the validation steps on a resource.
328func Validate(res Res) error {
329 if res.Kind() == "" { // shouldn't happen IIRC
330 return fmt.Errorf("the Res has an empty Kind")
331 }
332 if res.Name() == "" {
333 return fmt.Errorf("the Res has an empty Name")
334 }
335
336 if err := res.MetaParams().Validate(); err != nil {
337 return errwrap.Wrapf(err, "the Res has an invalid meta param")
338 }
339
340 // TODO: pull dollar prefix from a constant
341 // This catches typos where the user meant to use ${var} interpolation.
342 if !res.MetaParams().Dollar && strings.HasPrefix(res.Name(), "$") {
343 return fmt.Errorf("the Res name starts with a $")
344 }
345
346 // Don't need to validate normally if hidden.
347 // XXX: Check if it's also Exported too? len(res.MetaParams.Export) > 0
348 if res.MetaParams().Hidden {
349 return nil
350 }
351
352 return res.Validate()
353}
354
355// InterruptableRes is an interface that adds interrupt functionality to
356// resources. If the resource implements this interface, the engine will call

Callers 4

ValidateMethod · 0.92
CommitMethod · 0.92
ProcessMethod · 0.92
VertexMergeFunction · 0.92

Calls 5

WrapfFunction · 0.92
KindMethod · 0.65
NameMethod · 0.65
ValidateMethod · 0.65
MetaParamsMethod · 0.65

Tested by

no test coverage detected