1 # -------------------------------------------------------------------------
2 # Copyright (c) 2015-2017 AT&T Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
22 from osdf.logging.osdf_logging import debug_log
24 def get_local_policies(local_policy_folder, local_policy_list, policy_id_list=None):
26 Get policies from a local file system.
27 Required for the following scenarios:
28 (a) doing work-arounds (e.g. if we are asked to drop some policies for testing purposes)
29 (b) work-arounds when policy platform is giving issues (e.g. if dev/IST policies are wiped out in an upgrade)
30 :param local_policy_folder: where the policy files are present
31 :param local_policy_list: list of local policies
32 :param policy_id_list: list of policies to get (if unspecified or None, get all)
35 debug_log.debug("Policy folder: {}, local_list {}, policy id list {}".format(local_policy_folder, local_policy_list, policy_id_list))
38 for policy_id in policy_id_list:
39 with open(os.path.join(local_policy_folder, policy_id + ".json")) as fid:
40 policies.append(json.load(fid))
42 for fname in local_policy_list:
43 with open(os.path.join(local_policy_folder, fname)) as fid:
44 policies.append(json.load(fid))
48 def get_policy_names_from_file(fname_for_list_of_files):
49 """Get policy names; take care of comments, empty lines, etc"""
50 with open(fname_for_list_of_files) as fid:
52 re.sub(r'#.*$', '', x).strip() # remove inline comments and strip spaces
54 if not re.search(r'^#|^$', x.strip()) # remove blank or comments-only lines