"Fossies" - the Fresh Open Source Software Archive 
Member "monasca-log-api-2.9.0/monasca_log_api/policies/__init__.py" (1 Apr 2019, 2045 Bytes) of package /linux/misc/openstack/monasca-log-api-2.9.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "__init__.py" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
2.7.0_vs_2.9.0.
1 # Copyright 2017 FUJITSU LIMITED
2 # Copyright 2018 OP5 AB
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 import os
17 import pkgutil
18
19 from oslo_config import cfg
20 from oslo_log import log
21 from oslo_utils import importutils
22
23 from monasca_log_api.conf import role_middleware
24
25 LOG = log.getLogger(__name__)
26 _BASE_MOD_PATH = 'monasca_log_api.policies.'
27 CONF = cfg.CONF
28
29
30 def roles_list_to_check_str(roles_list):
31 if roles_list:
32 converted_roles_list = ["role:" + role if role != '@' else role for role in roles_list]
33 return ' or '.join(converted_roles_list)
34 else:
35 return None
36
37
38 role_middleware.register_opts(CONF)
39
40
41 def load_policy_modules():
42 """Load all modules that contain policies.
43
44 Method iterates over modules of :py:mod:`monasca_events_api.policies`
45 and imports only those that contain following methods:
46
47 - list_rules
48
49 """
50 for modname in _list_module_names():
51 mod = importutils.import_module(_BASE_MOD_PATH + modname)
52 if hasattr(mod, 'list_rules'):
53 yield mod
54
55
56 def _list_module_names():
57 package_path = os.path.dirname(os.path.abspath(__file__))
58 for _, modname, ispkg in pkgutil.iter_modules(path=[package_path]):
59 if not (modname == "opts" and ispkg):
60 yield modname
61
62
63 def list_rules():
64 """List all policy modules rules.
65
66 Goes through all policy modules and yields their rules
67
68 """
69 all_rules = []
70 for mod in load_policy_modules():
71 rules = mod.list_rules()
72 all_rules.extend(rules)
73 return all_rules