func (c *aclCache) useACLPolicy(id, authDC string, cached *aclCacheEntry, p *structs.ACLPolicy) (acl.ACL, error) {
	// Check if we can used the cached policy
	if cached != nil && cached.ETag == p.ETag {
		if p.TTL > 0 {
			// TODO (slackpad) - This seems like it's an unsafe
			// write.
			cached.Expires = time.Now().Add(p.TTL)
		}
		return cached.ACL, nil
	}

	// Check for a cached compiled policy
	var compiled acl.ACL
	raw, ok := c.policies.Get(p.ETag)
	if ok {
		compiled = raw.(acl.ACL)
	} else {
		// Resolve the parent policy
		parent := acl.RootACL(p.Parent)
		if parent == nil {
			var err error
			parent, err = c.lookupACL(p.Parent, authDC)
			if err != nil {
				return nil, err
			}
		}

		// Compile the ACL
		acl, err := acl.New(parent, p.Policy)
		if err != nil {
			return nil, err
		}

		// Cache the policy
		c.policies.Add(p.ETag, acl)
		compiled = acl
	}

	// Cache the ACL
	cached = &aclCacheEntry{
		ACL:  compiled,
		ETag: p.ETag,
	}
	if p.TTL > 0 {
		cached.Expires = time.Now().Add(p.TTL)
	}
	c.acls.Add(id, cached)
	return compiled, nil
}
// useACLPolicy handles an ACLPolicy response
useACLPolicy handles an ACLPolicy response
// useACLPolicy handles an ACLPolicy response
func (c *aclCache) useACLPolicy(id, authDC string, cached *aclCacheEntry, p *structs.ACLPolicy) (acl.ACL, error) {
	if cached != nil && cached.ETag == p.ETag {
		if p.TTL > 0 {
			cached.Expires = time.Now().Add(p.TTL)
		}
		return cached.ACL, nil
	}
	var compiled acl.ACL
	raw, ok := c.policies.Get(p.ETag)
	if ok {
		compiled = raw.(acl.ACL)
	} else {
		parent := acl.RootACL(p.Parent)
		if parent == nil {
			var err error
			parent, err = c.lookupACL(p.Parent, authDC)
			if err != nil {
				return nil, err
			}
		}
		acl, err := acl.New(parent, p.Policy)
		if err != nil {
			return nil, err
		}
		c.policies.Add(p.ETag, acl)
		compiled = acl
	}
	cached = &aclCacheEntry{
		ACL:  compiled,
		ETag: p.ETag,
	}
	if p.TTL > 0 {
		cached.Expires = time.Now().Add(p.TTL)
	}
	c.acls.Add(id, cached)
	return compiled, nil
}
func ( c * aclCache ) useACLPolicy ( id , authDC string , cached * aclCacheEntry , p * structs . ACLPolicy ) ( acl . ACL , error ) { if cached != nil && cached . ETag == p . ETag { if p . TTL > 0 { cached . Expires = time . Now ( ) . Add ( p . TTL ) } return cached . ACL , nil } var compiled acl . ACL raw , ok := c . policies . Get ( p . ETag ) if ok { compiled = raw . ( acl . ACL ) } else { parent := acl . RootACL ( p . Parent ) if parent == nil { var err error parent , err = c . lookupACL ( p . Parent , authDC ) if err != nil { return nil , err } } acl , err := acl . New ( parent , p . Policy ) if err != nil { return nil , err } c . policies . Add ( p . ETag , acl ) compiled = acl } cached = & aclCacheEntry { ACL : compiled , ETag : p . ETag , } if p . TTL > 0 { cached . Expires = time . Now ( ) . Add ( p . TTL ) } c . acls . Add ( id , cached ) return compiled , nil }
useACLPolicy handles an ACLPolicy response
useACLPolicy handles an ACLPolicy response
// Check if we can used the cached policy // TODO (slackpad) - This seems like it's an unsafe // write. // Check for a cached compiled policy // Resolve the parent policy // Compile the ACL // Cache the policy // Cache the ACL