fixup from code review
This commit is contained in:
parent
bcfebe032b
commit
8574696bb3
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue