Skip to content

Commit

Permalink
added applyTo pattern to policy
Browse files Browse the repository at this point in the history
  • Loading branch information
bitmage committed Jan 7, 2013
1 parent 3da4b55 commit 10c5056
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/applyPolicy.coffee
Expand Up @@ -34,10 +34,14 @@ getPolicy = (services, policy) ->
else if rule.except?
validateServices rule.except

# don't apply it to the specified rules, or to any other filters
for service in Object.keys services
unless (service in rule.except or startsWith service, policy.filterPrefix)
policyMap[service].push filters...

# don't apply it to the exceptions, to any other filters, or to things not matching applyTo
continue if service in rule.except
continue if policy.filterPrefix and startsWith service, policy.filterPrefix
continue if policy.applyTo and not service.match policy.applyTo

policyMap[service].push filters...

return policyMap

Expand Down
1 change: 1 addition & 0 deletions sample/app/domain/auth/policy.coffee
@@ -1,4 +1,5 @@
module.exports =
applyTo: /^[^\/]+$/ # only top level
filterPrefix: 'filters'
rules:
[
Expand Down
1 change: 0 additions & 1 deletion sample/app/domain/auth/services/dashboard.coffee
@@ -1,3 +1,2 @@
module.exports = (args, done) ->
console.log 'arrived in dashboard service'
done null, {user: {name: 'Bob'}}

0 comments on commit 10c5056

Please sign in to comment.