aboutsummaryrefslogtreecommitdiffstats
path: root/python_moonutilities
diff options
context:
space:
mode:
authorsgdt6900 <rhanafy.ext@orange.com>2018-01-03 17:25:54 +0200
committersgdt6900 <rhanafy.ext@orange.com>2018-01-03 22:21:48 +0200
commitf741f98623d4d987ef00f6541e3d0cd2aca0d407 (patch)
tree8b7921f1424d710af396d46edcc916baf23dce39 /python_moonutilities
parented403078a96170ca4dcb102d7357fefbe16b45c8 (diff)
update condition to check correctly on all keys
remove default value for policy_id Change-Id: I88e983adea98ed72476008a96ec4765194f4eef1 Signed-off-by: sgdt6900 <rhanafy.ext@orange.com>
Diffstat (limited to 'python_moonutilities')
-rw-r--r--python_moonutilities/python_moonutilities/cache.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/python_moonutilities/python_moonutilities/cache.py b/python_moonutilities/python_moonutilities/cache.py
index 154365a4..cfc24a56 100644
--- a/python_moonutilities/python_moonutilities/cache.py
+++ b/python_moonutilities/python_moonutilities/cache.py
@@ -89,7 +89,7 @@ class Cache(object):
def subjects(self):
return self.__SUBJECTS
- def __update_subjects(self, policy_id=None):
+ def __update_subjects(self, policy_id):
response = requests.get("{}/policies/{}/subjects".format(self.manager_url, policy_id))
if 'subjects' in response.json():
self.__SUBJECTS[policy_id] = response.json()['subjects']
@@ -118,7 +118,7 @@ class Cache(object):
def objects(self):
return self.__OBJECTS
- def __update_objects(self, policy_id=None):
+ def __update_objects(self, policy_id):
response = requests.get("{}/policies/{}/objects".format(self.manager_url, policy_id))
if 'objects' in response.json():
self.__OBJECTS[policy_id] = response.json()['objects']
@@ -147,7 +147,7 @@ class Cache(object):
def actions(self):
return self.__ACTIONS
- def __update_actions(self, policy_id=None):
+ def __update_actions(self, policy_id):
response = requests.get("{}/policies/{}/actions".format(self.manager_url, policy_id))
if 'actions' in response.json():
@@ -222,7 +222,7 @@ class Cache(object):
def subject_assignments(self):
return self.__SUBJECT_ASSIGNMENTS
- def __update_subject_assignments(self, policy_id=None, perimeter_id=None):
+ def __update_subject_assignments(self, policy_id, perimeter_id=None):
if perimeter_id:
response = requests.get("{}/policies/{}/subject_assignments/{}".format(
self.manager_url, policy_id, perimeter_id))
@@ -247,7 +247,7 @@ class Cache(object):
self.__update_subject_assignments(policy_id, perimeter_id)
for key, value in self.subject_assignments[policy_id].items():
- if "subject_id" and "category_id" and "assignments" in value:
+ if all(k in value for k in ("subject_id", "category_id", "assignments")):
if perimeter_id == value['subject_id'] and category_id == value['category_id']:
return value['assignments']
else:
@@ -259,7 +259,7 @@ class Cache(object):
def object_assignments(self):
return self.__OBJECT_ASSIGNMENTS
- def __update_object_assignments(self, policy_id=None, perimeter_id=None):
+ def __update_object_assignments(self, policy_id, perimeter_id=None):
if perimeter_id:
response = requests.get("{}/policies/{}/object_assignments/{}".format(
self.manager_url, policy_id, perimeter_id))
@@ -284,7 +284,7 @@ class Cache(object):
self.__update_object_assignments(policy_id, perimeter_id)
for key, value in self.object_assignments[policy_id].items():
- if "object_id" and "category_id" and "assignments" in value:
+ if all(k in value for k in ("object_id", "category_id", "assignments")):
if perimeter_id == value['object_id'] and category_id == value['category_id']:
return value['assignments']
else:
@@ -296,7 +296,7 @@ class Cache(object):
def action_assignments(self):
return self.__ACTION_ASSIGNMENTS
- def __update_action_assignments(self, policy_id=None, perimeter_id=None):
+ def __update_action_assignments(self, policy_id, perimeter_id=None):
if perimeter_id:
response = requests.get("{}/policies/{}/action_assignments/{}".format(
self.manager_url, policy_id, perimeter_id))
@@ -321,7 +321,7 @@ class Cache(object):
self.__update_action_assignments(policy_id, perimeter_id)
for key, value in self.action_assignments[policy_id].items():
- if "action_id" and "category_id" and "assignments" in value:
+ if all(k in value for k in ("action_id", "category_id", "assignments")):
if perimeter_id == value['action_id'] and category_id == value['category_id']:
return value['assignments']
else:
@@ -561,10 +561,9 @@ class Cache(object):
:return:
"""
- if "keystone_project_id" and "name" and "container_id" and "policy_id" and "meta_rule_id" \
- and "port" in container_data \
- and "PublicPort" in container_data['port'] and "Type" in container_data['port'] \
- and "IP" in container_data['port'] and "PrivatePort" in container_data['port']:
+ if all(k in container_data for k in ("keystone_project_id", "name", "container_id", "policy_id",
+ "meta_rule_id", "port")) \
+ and all(k in container_data['port'] for k in ("PublicPort", "Type", "IP", "PrivatePort")):
self.__CONTAINERS[uuid4().hex] = {
"keystone_project_id": container_data['keystone_project_id'],
@@ -638,7 +637,7 @@ class Cache(object):
container_ids = []
for pdp_id, pdp_value, in self.__PDP.items():
if pdp_value:
- if "keystone_project_id" and "security_pipeline" in pdp_value \
+ if all(k in pdp_value for k in ("keystone_project_id", "security_pipeline")) \
and pdp_value["keystone_project_id"] == keystone_project_id:
for policy_id in pdp_value["security_pipeline"]:
if policy_id in self.policies and "model_id" in self.policies[policy_id]:
@@ -650,7 +649,7 @@ class Cache(object):
meta_rule_id
):
if "name" in container_value:
- if "genre" and "port" in container_value:
+ if all(k in container_value for k in ("genre", "port")):
container_ids.append(
{
"container_id": container_value["name"],