aboutsummaryrefslogtreecommitdiffstats
path: root/python_moonutilities
diff options
context:
space:
mode:
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"],