Skip to content

Commit

Permalink
fixup from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseakomlo committed Oct 17, 2017
1 parent 7453b2c commit b50a3f8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion acl/policy.go
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit b50a3f8

Please sign in to comment.