-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add EnforceEx Signed-off-by: Zxilly <zhouxinyu1001@gmail.com> * fix: wrong implement Signed-off-by: Zxilly <zhouxinyu1001@gmail.com> * feat: new effector interface BREAKING CHANGE: Custom effectors will need a rewrite Signed-off-by: Andreas Bichinger <andreas.bichinger@gmail.com> Co-authored-by: Andreas Bichinger <andreas.bichinger@gmail.com>
- Loading branch information
1 parent
fd624fc
commit c577e1d
Showing
7 changed files
with
154 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,24 @@ | ||
from .default_effector import DefaultEffector | ||
from .default_effectors import AllowOverrideEffector, DenyOverrideEffector, AllowAndDenyEffector, PriorityEffector | ||
from .effector import Effector | ||
|
||
def get_effector(expr): | ||
''' creates an effector based on the current policy effect expression ''' | ||
|
||
if expr == "some(where (p_eft == allow))": | ||
return AllowOverrideEffector() | ||
elif expr == "!some(where (p_eft == deny))": | ||
return DenyOverrideEffector() | ||
elif expr == "some(where (p_eft == allow)) && !some(where (p_eft == deny))": | ||
return AllowAndDenyEffector() | ||
elif expr == "priority(p_eft) || deny": | ||
return PriorityEffector() | ||
else: | ||
raise RuntimeError("unsupported effect") | ||
|
||
def effect_to_bool(effect): | ||
""" """ | ||
if effect == Effector.ALLOW: | ||
return True | ||
if effect == Effector.DENY: | ||
return False | ||
raise RuntimeError("effect can't be converted to boolean") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from .effector import Effector | ||
|
||
class AllowOverrideEffector(Effector): | ||
|
||
def intermediate_effect(self, effects): | ||
""" returns a intermediate effect based on the matched effects of the enforcer """ | ||
if Effector.ALLOW in effects: | ||
return Effector.ALLOW | ||
return Effector.INDETERMINATE | ||
|
||
def final_effect(self, effects): | ||
""" returns the final effect based on the matched effects of the enforcer """ | ||
if Effector.ALLOW in effects: | ||
return Effector.ALLOW | ||
return Effector.DENY | ||
|
||
class DenyOverrideEffector(Effector): | ||
|
||
def intermediate_effect(self, effects): | ||
""" returns a intermediate effect based on the matched effects of the enforcer """ | ||
if Effector.DENY in effects: | ||
return Effector.DENY | ||
return Effector.INDETERMINATE | ||
|
||
def final_effect(self, effects): | ||
""" returns the final effect based on the matched effects of the enforcer """ | ||
if Effector.DENY in effects: | ||
return Effector.DENY | ||
return Effector.ALLOW | ||
|
||
class AllowAndDenyEffector(Effector): | ||
|
||
def intermediate_effect(self, effects): | ||
""" returns a intermediate effect based on the matched effects of the enforcer """ | ||
if Effector.DENY in effects: | ||
return Effector.DENY | ||
return Effector.INDETERMINATE | ||
|
||
def final_effect(self, effects): | ||
""" returns the final effect based on the matched effects of the enforcer """ | ||
if Effector.DENY in effects or Effector.ALLOW not in effects: | ||
return Effector.DENY | ||
return Effector.ALLOW | ||
|
||
class PriorityEffector(Effector): | ||
|
||
def intermediate_effect(self, effects): | ||
""" returns a intermediate effect based on the matched effects of the enforcer """ | ||
if Effector.ALLOW in effects: | ||
return Effector.ALLOW | ||
if Effector.DENY in effects: | ||
return Effector.DENY | ||
return Effector.INDETERMINATE | ||
|
||
def final_effect(self, effects): | ||
""" returns the final effect based on the matched effects of the enforcer """ | ||
if Effector.ALLOW in effects: | ||
return Effector.ALLOW | ||
if Effector.DENY in effects: | ||
return Effector.DENY | ||
return Effector.DENY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.