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)
| 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. |
| 328 | func 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 |
no test coverage detected