From 8574696bb3d97f651da71e91400a60a9ba3ef4d6 Mon Sep 17 00:00:00 2001 From: Chelsea Holland Komlo Date: Tue, 17 Oct 2017 17:15:11 -0400 Subject: [PATCH] fixup from code review --- acl/policy.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/acl/policy.go b/acl/policy.go index 56db3051d..5631f9474 100644 --- a/acl/policy.go +++ b/acl/policy.go @@ -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) }