fixup from code review

This commit is contained in:
Chelsea Holland Komlo 2017-10-17 17:15:11 -04:00
parent bcfebe032b
commit 8574696bb3
1 changed files with 11 additions and 1 deletions

View File

@ -45,6 +45,16 @@ type Policy struct {
Raw string `hcl:"-"`
}
// IsEmpty checks to make sure that at least one policy has been set and is not
// comprised of only a raw policy.
func (p *Policy) IsEmpty() bool {
return len(p.Namespaces) == 0 &&
p.Agent == nil &&
p.Node == nil &&
p.Operator == nil &&
p.Quota == nil
}
// NamespacePolicy is the policy for a specific namespace
type NamespacePolicy struct {
Name string `hcl:",key"`
@ -136,7 +146,7 @@ func Parse(rules string) (*Policy, error) {
// At least one valid policy must be specified, we don't want to store only
// raw data
if len(p.Namespaces) < 1 && p.Agent == nil && p.Node == nil && p.Operator == nil && p.Quota == nil {
if p.IsEmpty() {
return nil, fmt.Errorf("Invalid policy: %s", p.Raw)
}