Advertisement
Guest User

Untitled

a guest
Aug 27th, 2020
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. diff --git a/nova/policy.py b/nova/policy.py
  2. index ad1b79c542..ea79e47b83 100644
  3. --- a/nova/policy.py
  4. +++ b/nova/policy.py
  5. @@ -48,6 +48,22 @@ def reset():
  6. _ENFORCER = None
  7.  
  8.  
  9. +def pick_file(policy_file):
  10. + if policy_file:
  11. + return policy file
  12. +
  13. + if CONF.policy_file == DEFAULT_POLICY_FILE:
  14. + if os.path.exists(CONF.policy_file):
  15. + return CONF.policy_file
  16. + else:
  17. + # Do this smarter
  18. + json_backup = CONF.policy_file.replace('yaml', 'json')
  19. + if os.path.exists(json_backup):
  20. + return json_backup
  21. + # Same behavior if no overrides
  22. + return CONF.policy_file
  23. +
  24. +
  25. def init(policy_file=None, rules=None, default_rule=None, use_conf=True,
  26. suppress_deprecation_warnings=False):
  27. """Init an Enforcer class.
  28. @@ -68,7 +84,7 @@ def init(policy_file=None, rules=None, default_rule=None, use_conf=True,
  29.  
  30. if not _ENFORCER:
  31. _ENFORCER = policy.Enforcer(CONF,
  32. - policy_file=policy_file,
  33. + policy_file=pick_file(policy_file),
  34. rules=rules,
  35. default_rule=default_rule,
  36. use_conf=use_conf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement