// FindByRoleAndToken finds a matching policy by its role and token
// If the provided token is nil, matches policies that don't have any tokens associated with them.
FindByRoleAndToken finds a matching policy by its role and token
If the provided token is nil, matches policies that don't have any tokens associated with them.
// FindByRoleAndToken finds a matching policy by its role and token // If the provided token is nil matches policies that don ' t have any tokens associated with them .
func (s *PolicyStorage) FindByRoleAndToken(q FindPolicyQuery) *recommendations.Policy {
	for _, policy := range s.policies {
		var policyMatchesToken bool
		if q.Token != nil && policy.Token != nil {
			policyMatchesToken = policy.Token.ID == q.Token.ID
		} else {
			policyMatchesToken = policy.Token == nil
		}
		if policy.Identity.Role == q.Role && policyMatchesToken && policy.Status == q.Status {
			return &policy
		}
	}
	return nil
}
func ( s * PolicyStorage ) FindByRoleAndToken ( q FindPolicyQuery ) * recommendations . Policy { for _ , policy := range s . policies { var policyMatchesToken bool if q . Token != nil && policy . Token != nil { policyMatchesToken = policy . Token . ID == q . Token . ID } else { policyMatchesToken = policy . Token == nil } if policy . Identity . Role == q . Role && policyMatchesToken && policy . Status == q . Status { return & policy } } return nil }
FindByRoleAndToken finds a matching policy by its role and token
If the provided token is nil, matches policies that don't have any tokens associated with them.
FindByRoleAndToken finds a matching policy by its role and token If the provided token is nil matches policies that don ' t have any tokens associated with them .