resources: Officially add Validate method

This officially adds the Validate method to the resource API, and also
cleans up the ordering in existing resources.
This commit is contained in:
James Shubin
2017-01-09 05:05:16 -05:00
parent 668ec8a248
commit 56efef69ba
13 changed files with 120 additions and 115 deletions

View File

@@ -87,6 +87,14 @@ func (obj *HostnameRes) Default() Res {
return &HostnameRes{}
}
// Validate if the params passed in are valid data.
func (obj *HostnameRes) Validate() error {
if obj.PrettyHostname == "" && obj.StaticHostname == "" && obj.TransientHostname == "" {
return ErrResourceInsufficientParameters
}
return nil
}
// Init runs some startup code for this resource.
func (obj *HostnameRes) Init() error {
obj.BaseRes.kind = "Hostname"
@@ -102,15 +110,6 @@ func (obj *HostnameRes) Init() error {
return obj.BaseRes.Init() // call base init, b/c we're overriding
}
// Validate if the params passed in are valid data.
// FIXME: where should this get called ?
func (obj *HostnameRes) Validate() error {
if obj.PrettyHostname == "" && obj.StaticHostname == "" && obj.TransientHostname == "" {
return ErrResourceInsufficientParameters
}
return nil
}
// Watch is the primary listener for this resource and it outputs events.
func (obj *HostnameRes) Watch(processChan chan event.Event) error {
cuid := obj.ConvergerUID() // get the converger uid used to report status