aboutsummaryrefslogtreecommitdiffstats
path: root/moon_manager
diff options
context:
space:
mode:
authorThomas Duval <thomas.duval@orange.com>2018-01-05 16:28:07 +0100
committerThomas Duval <thomas.duval@orange.com>2018-01-08 09:32:19 +0100
commit48857b80be18bb0985aab643f5c8c899194d636b (patch)
tree649feb37d8c2c0dd672aad4ce4a38365cd79f4dd /moon_manager
parent646e77e86cd220f4be02110b16ce802d85c35b27 (diff)
prevent the mapping N*PDP <=> 1*Keystone_project
Change-Id: Ia43d7fb2a2c8054e9cf492395f2e3ef396d184cf
Diffstat (limited to 'moon_manager')
-rw-r--r--moon_manager/moon_manager/api/pdp.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/moon_manager/moon_manager/api/pdp.py b/moon_manager/moon_manager/api/pdp.py
index 4dc2c310..3ae55d33 100644
--- a/moon_manager/moon_manager/api/pdp.py
+++ b/moon_manager/moon_manager/api/pdp.py
@@ -14,9 +14,7 @@ import requests
import time
from python_moonutilities.security_functions import check_auth
from python_moondb.core import PDPManager
-from python_moondb.core import PolicyManager
-from python_moondb.core import ModelManager
-from python_moonutilities import configuration
+from python_moonutilities import configuration, exceptions
__version__ = "4.3.2"
@@ -51,6 +49,14 @@ def add_pod(uuid, data):
logger.info(req.text)
+def check_keystone_pid(k_pid):
+ data = PDPManager.get_pdp(user_id="admin")
+ for pdp_key, pdp_value in data.items():
+ logger.info("pdp={}".format(pdp_value))
+ if pdp_value["keystone_project_id"] == k_pid:
+ return True
+
+
class PDP(Resource):
"""
Endpoint for pdp requests
@@ -113,6 +119,9 @@ class PDP(Resource):
data = dict(request.json)
if not data.get("keystone_project_id"):
data["keystone_project_id"] = None
+ else:
+ if check_keystone_pid(data.get("keystone_project_id")):
+ raise exceptions.PdpKeystoneMappingConflict
data = PDPManager.add_pdp(
user_id=user_id, pdp_id=None, value=request.json)
uuid = list(data.keys())[0]
@@ -166,6 +175,9 @@ class PDP(Resource):
_data = dict(request.json)
if not _data.get("keystone_project_id"):
_data["keystone_project_id"] = None
+ else:
+ if check_keystone_pid(_data.get("keystone_project_id")):
+ raise exceptions.PdpKeystoneMappingConflict
data = PDPManager.update_pdp(
user_id=user_id, pdp_id=uuid, value=_data)
logger.debug("data={}".format(data))