engine: resources: file: Require paths to be absolute

This is a requirement of our file resource, so we should validate this
and clearly express it in the documentation.
This commit is contained in:
James Shubin
2018-12-16 07:02:52 -05:00
parent 8282f3b59c
commit d5bfb7257e
3 changed files with 25 additions and 2 deletions

View File

@@ -54,7 +54,10 @@ type FileRes struct {
init *engine.Init
Path string `yaml:"path"` // path variable (usually defaults to name)
// Path variable, which usually defaults to the name, represents the
// destination path for the file or directory being managed. It must be
// an absolute path, and as a result must start with a slash.
Path string `yaml:"path"`
Dirname string `yaml:"dirname"` // override the path dirname
Basename string `yaml:"basename"` // override the path basename
Content *string `yaml:"content"` // nil to mark as undefined
@@ -93,6 +96,10 @@ func (obj *FileRes) Validate() error {
return fmt.Errorf("basename must not start with a slash")
}
if !strings.HasPrefix(obj.GetPath(), "/") {
return fmt.Errorf("resultant path must be absolute")
}
if obj.Content != nil && obj.Source != "" {
return fmt.Errorf("can't specify both Content and Source")
}