[CORD-1502] [CORD-1516] Authenticating the user that is sending the
request and caching it's orm classes
Change-Id: I4754c1395d085ed0cf313c7fffebbd2d0b8c7fd4
diff --git a/src/grpc_client/models_accessor.py b/src/grpc_client/models_accessor.py
index 188a9ce..82934e5 100644
--- a/src/grpc_client/models_accessor.py
+++ b/src/grpc_client/models_accessor.py
@@ -6,7 +6,7 @@
"""
@staticmethod
- def get_model_from_classname(class_name, data):
+ def get_model_from_classname(class_name, data, username, password):
"""
Give a Model Class Name and some data, check if that exits or instantiate a new one
"""
@@ -16,10 +16,13 @@
else:
used_key = data.keys()[0]
- if class_name not in RESOURCES:
+ key = "%s~%s" % (username, password)
+ if not key in RESOURCES:
+ raise Exception("[XOS-TOSCA] User '%s' does not have ready resources" % username)
+ if class_name not in RESOURCES[key]:
raise Exception('[XOS-TOSCA] The model you are trying to create (%s: %s, class: %s) is not know by xos-core' % (used_key, data[used_key], class_name))
- cls = RESOURCES[class_name]
+ cls = RESOURCES[key][class_name]
models = cls.objects.filter(**{used_key: data[used_key]})
if len(models) == 1: