aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWuKong <rebirthmonkey@gmail.com>2015-07-17 15:27:50 +0200
committerWuKong <rebirthmonkey@gmail.com>2015-07-17 15:27:50 +0200
commite23e30ea41726f334ee46ee6698ef75e7bf1d001 (patch)
tree5ba03557b55b7fca0834d549e7dd89276f5b7006
parent790139a9110f9172133a780a8cb8f3f2e96967a4 (diff)
review backends
Change-Id: Ic82081a421e672a3fff0559f5fbd82736316803e Signed-off-by: WuKong <rebirthmonkey@gmail.com>
-rw-r--r--keystone-moon/doc/source/extensions/moon/ExceptionHierarchy-v0.2.pptxbin0 -> 35111 bytes
-rw-r--r--keystone-moon/keystone/contrib/moon/algorithms.py12
-rw-r--r--keystone-moon/keystone/contrib/moon/backends/sql.py1152
-rw-r--r--keystone-moon/keystone/contrib/moon/core.py42
-rw-r--r--keystone-moon/keystone/tests/moon/unit/test_unit_core_configuration.py57
-rw-r--r--keystone-moon/keystone/tests/moon/unit/test_unit_core_tenant.py42
6 files changed, 701 insertions, 604 deletions
diff --git a/keystone-moon/doc/source/extensions/moon/ExceptionHierarchy-v0.2.pptx b/keystone-moon/doc/source/extensions/moon/ExceptionHierarchy-v0.2.pptx
new file mode 100644
index 00000000..f6541354
--- /dev/null
+++ b/keystone-moon/doc/source/extensions/moon/ExceptionHierarchy-v0.2.pptx
Binary files differ
diff --git a/keystone-moon/keystone/contrib/moon/algorithms.py b/keystone-moon/keystone/contrib/moon/algorithms.py
index 49690f64..fe35b7ee 100644
--- a/keystone-moon/keystone/contrib/moon/algorithms.py
+++ b/keystone-moon/keystone/contrib/moon/algorithms.py
@@ -37,14 +37,14 @@ rule_dict = [
def inclusion(authz_buffer, sub_meta_rule_dict, rule_list):
_cat = []
for subject_cat in sub_meta_rule_dict['subject_categories']:
- if subject_cat in authz_buffer['subject_attributes']:
- _cat.append(authz_buffer['subject_attributes'][subject_cat])
+ if subject_cat in authz_buffer['subject_assignments']:
+ _cat.append(authz_buffer['subject_assignments'][subject_cat])
for action_cat in sub_meta_rule_dict['action_categories']:
- if action_cat in authz_buffer['action_attributes']:
- _cat.append(authz_buffer['action_attributes'][action_cat])
+ if action_cat in authz_buffer['action_assignments']:
+ _cat.append(authz_buffer['action_assignments'][action_cat])
for object_cat in sub_meta_rule_dict['object_categories']:
- if object_cat in authz_buffer['object_attributes']:
- _cat.append(authz_buffer['object_attributes'][object_cat])
+ if object_cat in authz_buffer['object_assignments']:
+ _cat.append(authz_buffer['object_assignments'][object_cat])
for _element in itertools.product(*_cat):
if list(_element) in rule_list:
diff --git a/keystone-moon/keystone/contrib/moon/backends/sql.py b/keystone-moon/keystone/contrib/moon/backends/sql.py
index 4da0f1c8..b328112c 100644
--- a/keystone-moon/keystone/contrib/moon/backends/sql.py
+++ b/keystone-moon/keystone/contrib/moon/backends/sql.py
@@ -17,14 +17,12 @@ from keystone.contrib.moon import IntraExtensionDriver
from keystone.contrib.moon import TenantDriver
# from keystone.contrib.moon import InterExtensionDriver
-from keystone.contrib.moon.exception import TenantException, TenantListEmpty
-
CONF = config.CONF
LOG = log.getLogger(__name__)
class IntraExtension(sql.ModelBase, sql.DictBase):
- __tablename__ = 'intra_extension'
+ __tablename__ = 'intra_extensions'
attributes = ['id', 'name', 'model', 'description']
id = sql.Column(sql.String(64), primary_key=True)
name = sql.Column(sql.String(64), nullable=False)
@@ -40,12 +38,12 @@ class IntraExtension(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class Subject(sql.ModelBase, sql.DictBase):
- __tablename__ = 'subject'
- attributes = ['id', 'subjects', 'intra_extension_uuid']
+class SubjectCategory(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'subject_categories'
+ attributes = ['id', 'subject_category', 'intra_extension_id']
id = sql.Column(sql.String(64), primary_key=True)
- subjects = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ subject_category = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -56,12 +54,12 @@ class Subject(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class Object(sql.ModelBase, sql.DictBase):
- __tablename__ = 'object'
- attributes = ['id', 'objects', 'intra_extension_uuid']
+class ObjectCategory(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'object_categories'
+ attributes = ['id', 'object_category', 'intra_extension_id']
id = sql.Column(sql.String(64), primary_key=True)
- objects = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ object_category = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -72,12 +70,12 @@ class Object(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class Action(sql.ModelBase, sql.DictBase):
- __tablename__ = 'action'
- attributes = ['id', 'actions', 'intra_extension_uuid']
+class ActionCategory(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'action_categories'
+ attributes = ['id', 'action_category', 'intra_extension_id']
id = sql.Column(sql.String(64), primary_key=True)
- actions = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ action_category = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -88,12 +86,12 @@ class Action(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class SubjectCategory(sql.ModelBase, sql.DictBase):
- __tablename__ = 'subject_category'
- attributes = ['id', 'subject_categories', 'intra_extension_uuid']
+class Subject(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'subjects'
+ attributes = ['id', 'subject', 'intra_extension_id']
id = sql.Column(sql.String(64), primary_key=True)
- subject_categories = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ subject = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -104,12 +102,12 @@ class SubjectCategory(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class ObjectCategory(sql.ModelBase, sql.DictBase):
- __tablename__ = 'object_category'
- attributes = ['id', 'object_categories', 'intra_extension_uuid']
+class Object(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'objects'
+ attributes = ['id', 'object', 'intra_extension_id']
id = sql.Column(sql.String(64), primary_key=True)
- object_categories = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ object = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -120,12 +118,12 @@ class ObjectCategory(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class ActionCategory(sql.ModelBase, sql.DictBase):
- __tablename__ = 'action_category'
- attributes = ['id', 'action_categories', 'intra_extension_uuid']
+class Action(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'actions'
+ attributes = ['id', 'action', 'intra_extension_id']
id = sql.Column(sql.String(64), primary_key=True)
- action_categories = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ action = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -136,12 +134,13 @@ class ActionCategory(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class SubjectCategoryScope(sql.ModelBase, sql.DictBase):
- __tablename__ = 'subject_category_scope'
- attributes = ['id', 'subject_category_scope', 'intra_extension_uuid']
+class SubjectScope(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'subject_scopes'
+ attributes = ['id', 'subject_scope', 'intra_extension_id', 'subject_category_id']
id = sql.Column(sql.String(64), primary_key=True)
- subject_category_scope = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ subject_scope = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
+ subject_category_id = sql.Column(sql.ForeignKey("subject_categories.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -152,12 +151,13 @@ class SubjectCategoryScope(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class ObjectCategoryScope(sql.ModelBase, sql.DictBase):
- __tablename__ = 'object_category_scope'
- attributes = ['id', 'object_category_scope', 'intra_extension_uuid']
+class ObjectScope(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'object_scopes'
+ attributes = ['id', 'object_scope', 'intra_extension_id', 'object_category_id']
id = sql.Column(sql.String(64), primary_key=True)
- object_category_scope = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ object_scope = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
+ object_category_id = sql.Column(sql.ForeignKey("object_categories.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -168,12 +168,13 @@ class ObjectCategoryScope(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class ActionCategoryScope(sql.ModelBase, sql.DictBase):
- __tablename__ = 'action_category_scope'
- attributes = ['id', 'action_category_scope', 'intra_extension_uuid']
+class ActionScope(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'action_scopes'
+ attributes = ['id', 'action_scope', 'intra_extension_id', 'action_category']
id = sql.Column(sql.String(64), primary_key=True)
- action_category_scope = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ action_scope = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
+ action_category_id = sql.Column(sql.ForeignKey("action_categories.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -184,12 +185,13 @@ class ActionCategoryScope(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class SubjectCategoryAssignment(sql.ModelBase, sql.DictBase):
- __tablename__ = 'subject_category_assignment'
- attributes = ['id', 'subject_category_assignments', 'intra_extension_uuid']
+class SubjectAssignment(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'subject_assignments'
+ attributes = ['id', 'subject_assignment', 'intra_extension_id', 'subject_id']
id = sql.Column(sql.String(64), primary_key=True)
- subject_category_assignments = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ subject_assignment = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
+ subject_id = sql.Column(sql.ForeignKey("subjects.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -200,12 +202,13 @@ class SubjectCategoryAssignment(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class ObjectCategoryAssignment(sql.ModelBase, sql.DictBase):
- __tablename__ = 'object_category_assignment'
- attributes = ['id', 'object_category_assignments', 'intra_extension_uuid']
+class ObjectAssignment(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'object_assignments'
+ attributes = ['id', 'object_assignment', 'intra_extension_id', 'object_id']
id = sql.Column(sql.String(64), primary_key=True)
- object_category_assignments = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ object_assignment = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
+ object_id = sql.Column(sql.ForeignKey("objects.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -216,12 +219,13 @@ class ObjectCategoryAssignment(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class ActionCategoryAssignment(sql.ModelBase, sql.DictBase):
- __tablename__ = 'action_category_assignment'
- attributes = ['id', 'action_category_assignments', 'intra_extension_uuid']
+class ActionAssignment(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'action_assignments'
+ attributes = ['id', 'action_assignment', 'intra_extension_id', 'action_id']
id = sql.Column(sql.String(64), primary_key=True)
- action_category_assignments = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ action_assignment = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
+ action_id = sql.Column(sql.ForeignKey("actions.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -232,13 +236,28 @@ class ActionCategoryAssignment(sql.ModelBase, sql.DictBase):
return dict(six.iteritems(self))
-class MetaRule(sql.ModelBase, sql.DictBase):
- __tablename__ = 'metarule'
- attributes = ['id', 'sub_meta_rules', 'aggregation', 'intra_extension_uuid']
+class AggregationAlgorithm(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'aggregation_algorithm'
+ attributes = ['id', 'aggregation_algorithm_id', 'intra_extension_id']
id = sql.Column(sql.String(64), primary_key=True)
- sub_meta_rules = sql.Column(sql.JsonBlob(), nullable=True)
- aggregation = sql.Column(sql.Text(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ aggregation_algorithm_id = sql.Column(sql.Text(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
+
+ @classmethod
+ def from_dict(cls, d):
+ new_d = d.copy()
+ return cls(**new_d)
+
+ def to_dict(self):
+ return dict(six.iteritems(self))
+
+
+class SubMetaRule(sql.ModelBase, sql.DictBase):
+ __tablename__ = 'sub_meta_rules'
+ attributes = ['id', 'sub_meta_rule', 'intra_extension_id']
+ id = sql.Column(sql.String(64), primary_key=True)
+ sub_meta_rule = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -250,11 +269,12 @@ class MetaRule(sql.ModelBase, sql.DictBase):
class Rule(sql.ModelBase, sql.DictBase):
- __tablename__ = 'rule'
- attributes = ['id', 'rules', 'intra_extension_uuid']
+ __tablename__ = 'rules'
+ attributes = ['id', 'rule', 'intra_extension_id', 'sub_meta_rule_id']
id = sql.Column(sql.String(64), primary_key=True)
- rules = sql.Column(sql.JsonBlob(), nullable=True)
- intra_extension_uuid = sql.Column(sql.ForeignKey("intra_extension.id"), nullable=False)
+ rule = sql.Column(sql.JsonBlob(), nullable=True)
+ intra_extension_id = sql.Column(sql.ForeignKey("intra_extensions.id"), nullable=False)
+ sub_meta_rule_id = sql.Column(sql.ForeignKey("sub_meta_rules.id"), nullable=False)
@classmethod
def from_dict(cls, d):
@@ -298,23 +318,25 @@ __all_objects__ = (
SubjectCategory,
ObjectCategory,
ActionCategory,
- SubjectCategoryScope,
- ObjectCategoryScope,
- ActionCategoryScope,
- SubjectCategoryAssignment,
- ObjectCategoryAssignment,
- ActionCategoryAssignment,
- MetaRule,
+ SubjectScope,
+ ObjectScope,
+ ActionScope,
+ SubjectAssignment,
+ ObjectAssignment,
+ ActionAssignment,
+ AggregationAlgorithm,
+ SubMetaRule,
Rule,
)
class IntraExtensionConnector(IntraExtensionDriver):
+ # Tenant functions
+
def get_intra_extension_dict(self):
with sql.transaction() as session:
query = session.query(IntraExtension.id)
intraextensions = query.all()
- # return intraextensions
return [intraextension[0] for intraextension in intraextensions]
def set_intra_extension(self, intra_id, intra_extension):
@@ -325,10 +347,10 @@ class IntraExtensionConnector(IntraExtensionDriver):
session.add(ie_ref)
return IntraExtension.to_dict(ie_ref)
- def get_intra_extension(self, uuid):
+ def get_intra_extension(self, intra_extension_id):
with sql.transaction() as session:
query = session.query(IntraExtension)
- query = query.filter_by(id=uuid)
+ query = query.filter_by(id=intra_extension_id)
ref = query.first()
if not ref:
raise exception.NotFound
@@ -340,1081 +362,1091 @@ class IntraExtensionConnector(IntraExtensionDriver):
# Must delete all references to that IntraExtension
for _object in __all_objects__:
query = session.query(_object)
- query = query.filter_by(intra_extension_uuid=intra_extension_id)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
_ref = query.first()
if _ref:
session.delete(_ref)
session.flush()
session.delete(ref)
- # Getter and setter for name
-
- def get_name(self, uuid):
- intra_extension = self.get_intra_extension(uuid)
+ def get_intra_extension_name(self, intra_extension_id):
+ intra_extension = self.get_intra_extension(intra_extension_id)
return intra_extension["name"]
- def set_name(self, uuid, name):
+ def set_intra_extension_name(self, intra_extension_id, intra_extension_name):
raise exception.NotImplemented() # pragma: no cover
- # Getter and setter for model
-
- def get_model(self, uuid):
- intra_extension = self.get_intra_extension(uuid)
+ def get_intra_extension_model(self, intra_extension_id):
+ intra_extension = self.get_intra_extension(intra_extension_id)
return intra_extension["model"]
- def set_model(self, uuid, model):
+ def set_intra_extension_model(self, intra_extension_id, intra_extension_model):
raise exception.NotImplemented() # pragma: no cover
- # Getter and setter for description
-
- def get_description(self, uuid):
- intra_extension = self.get_intra_extension(uuid)
+ def get_intra_extension_description(self, intra_extension_id):
+ intra_extension = self.get_intra_extension(intra_extension_id)
return intra_extension["description"]
- def set_description(self, uuid, args):
+ def set_intra_extension_description(self, intra_extension_id, intra_extension_description):
raise exception.NotImplemented() # pragma: no cover
- # Perimeter
+ # Getter and Setter for subject_category
- def get_subject_dict(self, extension_uuid):
+ def get_subject_category_dict(self, intra_extension_id):
with sql.transaction() as session:
- query = session.query(Subject)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
return ref.to_dict()
- def set_subject_dict(self, extension_uuid, subject_uuid):
+ # TODO: review the code
+ def set_subject_category_dict(self, intra_extension_id, subject_category_id, subject_category_dict):
with sql.transaction() as session:
- query = session.query(Subject)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- new_ref = Subject.from_dict(
+ if not ref:
+ raise IntraExtensionUnknown()
+ old_ref = ref.to_dict()
+ new_ref = SubjectCategory.from_dict(
{
- "id": uuid4().hex,
- 'subjects': subject_uuid,
- 'intra_extension_uuid': extension_uuid
+ "id": subject_category_id,
+ 'subject_category': subject_category_dict,
+ 'intra_extension_id': intra_extension_id
}
)
- if not ref:
- session.add(new_ref)
- ref = new_ref
- else:
- for attr in Subject.attributes:
- if attr != 'id':
- setattr(ref, attr, getattr(new_ref, attr))
+ for attr in SubjectCategory.attributes:
+ if attr != 'id':
+ setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_subject(self, extension_uuid, subject_uuid, subject_name):
+ # TODO: review the code
+ def add_subject_category(self, intra_extension_id, subject_category_id, subject_category_name):
with sql.transaction() as session:
- query = session.query(Subject)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- if not ref:
- raise IntraExtensionUnknown()
- old_ref = ref.to_dict()
- subjects = dict(old_ref["subjects"])
- subjects[subject_uuid] = subject_name
- new_ref = Subject.from_dict(
+ subject_category_dict = {
+ 'name': subject_category_name,
+ 'description': None
+ }
+ new_ref = SubjectCategory.from_dict(
{
- "id": old_ref["id"],
- 'subjects': subjects,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ "id": subject_category_id,
+ 'subject_category': subject_category_dict,
+ 'intra_extension_id': intra_extension_id
}
)
- for attr in Subject.attributes:
- if attr != 'id':
- setattr(ref, attr, getattr(new_ref, attr))
+ if not ref:
+ session.add(new_ref)
+ ref = new_ref
+ else:
+ for attr in SubjectCategory.attributes:
+ if attr != 'id':
+ setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def del_subject(self, extension_uuid, subject_uuid):
+ def del_subject_category(self, intra_extension_id, subject_category_id):
with sql.transaction() as session:
- query = session.query(Subject)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
else:
old_ref = ref.to_dict()
- subjects = dict(old_ref["subjects"])
+ subject_category_dict = dict(old_ref["subject_category"])
try:
- subjects.pop(subject_uuid)
+ subject_category_dict.pop(subject_category_id)
except KeyError:
- LOG.error("KeyError in remove_subject {} | {}".format(subject_uuid, subjects))
+ pass
else:
- new_ref = Subject.from_dict(
+ new_ref = SubjectCategory.from_dict(
{
"id": old_ref["id"],
- 'subjects': subjects,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'subject_categories': subject_category_dict,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in Subject.attributes:
+ for attr in SubjectCategory.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
+ return ref.to_dict()
- def get_object_dict(self, extension_uuid):
+ # Getter and Setter for object_category
+
+ def get_object_category_dict(self, intra_extension_id):
with sql.transaction() as session:
- query = session.query(Object)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
return ref.to_dict()
- def set_object_dict(self, extension_uuid, object_uuid):
+ # TODO: to recheck
+ def set_object_category_dict(self, intra_extension_id, object_categories):
with sql.transaction() as session:
- query = session.query(Object)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- new_ref = Object.from_dict(
+ new_ref = ObjectCategory.from_dict(
{
"id": uuid4().hex,
- 'objects': object_uuid,
- 'intra_extension_uuid': extension_uuid
+ 'object_categories': object_categories,
+ 'intra_extension_id': intra_extension_id
}
)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- for attr in Object.attributes:
+ for attr in ObjectCategory.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_object(self, extension_uuid, object_uuid, object_name):
+ def add_object_category(self, intra_extension_id, object_category_id, object_category_name):
with sql.transaction() as session:
- query = session.query(Object)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- objects = dict(old_ref["objects"])
- objects[object_uuid] = object_name
- new_ref = Object.from_dict(
+ object_categories = dict(old_ref["object_categories"])
+ # TODO: object_categories[object_category_id] is a dict
+ object_categories[object_category_id] = object_category_name
+ new_ref = ObjectCategory.from_dict(
{
"id": old_ref["id"],
- 'objects': objects,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'object_categories': object_categories,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in Object.attributes:
+ for attr in ObjectCategory.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def del_object(self, extension_uuid, object_uuid):
+ def del_object_category(self, intra_extension_id, object_category_id):
with sql.transaction() as session:
- query = session.query(Object)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
else:
old_ref = ref.to_dict()
- objects = dict(old_ref["objects"])
+ object_categories = dict(old_ref["object_categories"])
try:
- objects.pop(object_uuid)
+ object_categories.pop(object_category_id)
except KeyError:
- LOG.error("KeyError in remove_object {} | {}".format(object_uuid, objects))
+ pass
else:
- new_ref = Object.from_dict(
+ new_ref = ObjectCategory.from_dict(
{
"id": old_ref["id"],
- 'objects': objects,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'object_categories': object_categories,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in Object.attributes:
+ for attr in ObjectCategory.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
+ return ref.to_dict()
- def get_action_dict(self, extension_uuid):
+ # Getter and Setter for action_category
+
+ def get_action_category_dict(self, intra_extension_id):
with sql.transaction() as session:
- query = session.query(Action)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
return ref.to_dict()
- def set_action_dict(self, extension_uuid, action_uuid):
+ # TODO: to recheck
+ def set_action_category_dict(self, intra_extension_id, action_categories):
with sql.transaction() as session:
- query = session.query(Action)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- new_ref = Action.from_dict(
+ new_ref = ActionCategory.from_dict(
{
"id": uuid4().hex,
- 'actions': action_uuid,
- 'intra_extension_uuid': extension_uuid
+ 'action_categories': action_categories,
+ 'intra_extension_id': intra_extension_id
}
)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- for attr in Action.attributes:
+ for attr in ActionCategory.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_action(self, extension_uuid, action_uuid, action_name):
+ def add_action_category(self, intra_extension_id, action_category_id, action_category_name):
with sql.transaction() as session:
- query = session.query(Action)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- actions = dict(old_ref["actions"])
- actions[action_uuid] = action_name
- new_ref = Action.from_dict(
+ action_categories = dict(old_ref["action_categories"])
+ # TODO: action_categories[action_category_id] is a dict
+ action_categories[action_category_id] = action_category_name
+ new_ref = ActionCategory.from_dict(
{
"id": old_ref["id"],
- 'actions': actions,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'action_categories': action_categories,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in Action.attributes:
+ for attr in ActionCategory.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def del_action(self, extension_uuid, action_uuid):
+ def del_action_category(self, intra_extension_id, action_category_id):
with sql.transaction() as session:
- query = session.query(Action)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionCategory)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
else:
old_ref = ref.to_dict()
- actions = dict(old_ref["actions"])
+ action_categories = dict(old_ref["action_categories"])
try:
- actions.pop(action_uuid)
+ action_categories.pop(action_category_id)
except KeyError:
- LOG.error("KeyError in remove_action {} | {}".format(action_uuid, actions))
+ pass
else:
- new_ref = Action.from_dict(
+ new_ref = ActionCategory.from_dict(
{
"id": old_ref["id"],
- 'actions': actions,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'action_categories': action_categories,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in Action.attributes:
+ for attr in ActionCategory.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
+ return ref.to_dict()
- # Getter and Setter for subject_category
+ # Perimeter
- def get_subject_category_dict(self, extension_uuid):
+ def get_subject_dict(self, intra_extension_id):
with sql.transaction() as session:
- query = session.query(SubjectCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Subject)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
return ref.to_dict()
- def set_subject_category_dict(self, extension_uuid, subject_categories):
+ # TODO: to recheck
+ def set_subject_dict(self, intra_extension_id, subject_id):
with sql.transaction() as session:
- query = session.query(SubjectCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Subject)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- new_ref = SubjectCategory.from_dict(
+ new_ref = Subject.from_dict(
{
"id": uuid4().hex,
- 'subject_categories': subject_categories,
- 'intra_extension_uuid': extension_uuid
+ 'subjects': subject_id,
+ 'intra_extension_id': intra_extension_id
}
)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- for attr in SubjectCategory.attributes:
+ for attr in Subject.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_subject_category(self, extension_uuid, subject_category_uuid, subject_category_name):
+ def add_subject(self, intra_extension_id, subject_id, subject_name):
with sql.transaction() as session:
- query = session.query(SubjectCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Subject)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- subject_categories = dict(old_ref["subject_categories"])
- subject_categories[subject_category_uuid] = subject_category_name
- new_ref = SubjectCategory.from_dict(
+ subjects = dict(old_ref["subjects"])
+ # TODO: subjects[subject_id] is a dict
+ subjects[subject_id] = subject_name
+ new_ref = Subject.from_dict(
{
"id": old_ref["id"],
- 'subject_categories': subject_categories,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'subjects': subjects,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in SubjectCategory.attributes:
+ for attr in Subject.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def del_subject_category(self, extension_uuid, subject_category_uuid):
+ def del_subject(self, intra_extension_id, subject_id):
with sql.transaction() as session:
- query = session.query(SubjectCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Subject)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
else:
old_ref = ref.to_dict()
- subject_categories = dict(old_ref["subject_categories"])
+ subjects = dict(old_ref["subjects"])
try:
- subject_categories.pop(subject_category_uuid)
+ subjects.pop(subject_id)
except KeyError:
- pass
+ LOG.error("KeyError in remove_subject {} | {}".format(subject_id, subjects))
else:
- new_ref = SubjectCategory.from_dict(
+ new_ref = Subject.from_dict(
{
"id": old_ref["id"],
- 'subject_categories': subject_categories,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'subjects': subjects,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in SubjectCategory.attributes:
+ for attr in Subject.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
- return ref.to_dict()
- # Getter and Setter for object_category
-
- def get_object_category_dict(self, extension_uuid):
+ def get_object_dict(self, intra_extension_id):
with sql.transaction() as session:
- query = session.query(ObjectCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Object)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
return ref.to_dict()
- def set_object_category_dict(self, extension_uuid, object_categories):
+ # TODO: to recheck
+ def set_object_dict(self, intraa_extension_id, object_id):
with sql.transaction() as session:
- query = session.query(ObjectCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Object)
+ query = query.filter_by(intra_extension_id=intraa_extension_id)
ref = query.first()
- new_ref = ObjectCategory.from_dict(
+ new_ref = Object.from_dict(
{
"id": uuid4().hex,
- 'object_categories': object_categories,
- 'intra_extension_uuid': extension_uuid
+ 'objects': object_id,
+ 'intra_extension_id': intraa_extension_id
}
)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- for attr in ObjectCategory.attributes:
+ for attr in Object.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_object_category(self, extension_uuid, object_category_uuid, object_category_name):
+ def add_object(self, intra_extension_id, object_id, object_name):
with sql.transaction() as session:
- query = session.query(ObjectCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Object)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- object_categories = dict(old_ref["object_categories"])
- object_categories[object_category_uuid] = object_category_name
- new_ref = ObjectCategory.from_dict(
+ objects = dict(old_ref["objects"])
+ # TODO: objects[object_id] is a dict
+ objects[object_id] = object_name
+ new_ref = Object.from_dict(
{
"id": old_ref["id"],
- 'object_categories': object_categories,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'objects': objects,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in ObjectCategory.attributes:
+ for attr in Object.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def del_object_category(self, extension_uuid, object_category_uuid):
+ def del_object(self, intra_extension_id, object_id):
with sql.transaction() as session:
- query = session.query(ObjectCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Object)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
else:
old_ref = ref.to_dict()
- object_categories = dict(old_ref["object_categories"])
+ objects = dict(old_ref["objects"])
try:
- object_categories.pop(object_category_uuid)
+ objects.pop(object_id)
except KeyError:
- pass
+ LOG.error("KeyError in remove_object {} | {}".format(object_id, objects))
else:
- new_ref = ObjectCategory.from_dict(
+ new_ref = Object.from_dict(
{
"id": old_ref["id"],
- 'object_categories': object_categories,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'objects': objects,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in ObjectCategory.attributes:
+ for attr in Object.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
- return ref.to_dict()
-
- # Getter and Setter for action_category
- def get_action_category_dict(self, extension_uuid):
+ def get_action_dict(self, intra_extension_id):
with sql.transaction() as session:
- query = session.query(ActionCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Action)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
return ref.to_dict()
- def set_action_category_dict(self, extension_uuid, action_categories):
+ # TODO: to recheck
+ def set_action_dict(self, intra_extension_id, action_id):
with sql.transaction() as session:
- query = session.query(ActionCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Action)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- new_ref = ActionCategory.from_dict(
+ new_ref = Action.from_dict(
{
"id": uuid4().hex,
- 'action_categories': action_categories,
- 'intra_extension_uuid': extension_uuid
+ 'actions': action_id,
+ 'intra_extension_id': intra_extension_id
}
)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- for attr in ActionCategory.attributes:
+ for attr in Action.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_action_category(self, extension_uuid, action_category_uuid, action_category_name):
+ def add_action(self, intra_extension_id, action_id, action_name):
with sql.transaction() as session:
- query = session.query(ActionCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Action)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- action_categories = dict(old_ref["action_categories"])
- action_categories[action_category_uuid] = action_category_name
- new_ref = ActionCategory.from_dict(
+ actions = dict(old_ref["actions"])
+ # TODO: actions[action_id] is a dict
+ actions[action_id] = action_name
+ new_ref = Action.from_dict(
{
"id": old_ref["id"],
- 'action_categories': action_categories,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'actions': actions,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in ActionCategory.attributes:
+ for attr in Action.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def del_action_category(self, extension_uuid, action_category_uuid):
+ def del_action(self, intra_extension_id, action_id):
with sql.transaction() as session:
- query = session.query(ActionCategory)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(Action)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
else:
old_ref = ref.to_dict()
- action_categories = dict(old_ref["action_categories"])
+ actions = dict(old_ref["actions"])
try:
- action_categories.pop(action_category_uuid)
+ actions.pop(action_id)
except KeyError:
- pass
+ LOG.error("KeyError in remove_action {} | {}".format(action_id, actions))
else:
- new_ref = ActionCategory.from_dict(
+ new_ref = Action.from_dict(
{
"id": old_ref["id"],
- 'action_categories': action_categories,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'actions': actions,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in ActionCategory.attributes:
+ for attr in Action.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
- return ref.to_dict()
- # Getter and Setter for subject_category_value_scope
+ # Getter and Setter for subject_scope
- def get_subject_category_scope_dict(self, extension_uuid, subject_category):
+ def get_subject_scope_dict(self, intra_extension_id, subject_category_id):
with sql.transaction() as session:
- query = session.query(SubjectCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectScope)
+ query = query.filter_by(
+ intra_extension_id=intra_extension_id,
+ subject_category_id=subject_category_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
result = copy.deepcopy(ref.to_dict())
- if subject_category not in result["subject_category_scope"].keys():
+ if subject_category_id not in result["subject_scopes"].keys():
raise SubjectScopeUnknown()
return result
- def set_subject_scope_dict(self, extension_uuid, subject_category, scope):
+ def set_subject_scope_dict(self, intra_extension_id, subject_category_id, subject_scope_id):
with sql.transaction() as session:
- query = session.query(SubjectCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
- new_ref = SubjectCategoryScope.from_dict(
+ new_ref = SubjectScope.from_dict(
{
"id": uuid4().hex,
- 'subject_category_scope': {subject_category: scope},
- 'intra_extension_uuid': extension_uuid
+ 'subject_scope': {subject_category_id: subject_scope_id},
+ 'intra_extension_id': intra_extension_id
}
)
session.add(new_ref)
else:
tmp_ref = ref.to_dict()
- tmp_ref['subject_category_scope'].update({subject_category: scope})
+ tmp_ref['subject_scope'].update({subject_category_id: subject_scope_id})
session.delete(ref)
- new_ref = SubjectCategoryScope.from_dict(tmp_ref)
+ new_ref = SubjectScope.from_dict(tmp_ref)
session.add(new_ref)
return new_ref.to_dict()
- def add_subject_scope(self, extension_uuid, subject_category, scope_uuid, scope_name):
+ def add_subject_scope(self, intra_extension_id, subject_category_id, subject_scope_id, subject_scope_name):
with sql.transaction() as session:
- query = session.query(SubjectCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- scope = copy.deepcopy(old_ref["subject_category_scope"])
- if subject_category not in scope.keys():
- scope[subject_category] = dict()
- scope[subject_category][scope_uuid] = scope_name
- return self.set_subject_scope_dict(extension_uuid, subject_category, scope[subject_category])
+ scope = copy.deepcopy(old_ref["subject_scope"])
+ if subject_category_id not in scope.keys():
+ scope[subject_category_id] = dict()
+ scope[subject_category_id][subject_scope_id] = subject_scope_name
+ return self.set_subject_scope_dict(intra_extension_id, subject_category_id, scope[subject_category_id])
- def del_subject_scope(self, extension_uuid, subject_category, scope_uuid):
+ def del_subject_scope(self, intra_extension_id, subject_category_id, subject_scope_id):
with sql.transaction() as session:
- query = session.query(SubjectCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- scope = dict(old_ref["subject_category_scope"])
- if subject_category not in scope:
+ scope = dict(old_ref["subject_scope"])
+ if subject_category_id not in scope:
return
try:
- scope[subject_category].pop(scope_uuid)
+ scope[subject_category_id].pop(subject_scope_id)
except KeyError:
return
- new_ref = SubjectCategoryScope.from_dict(
+ new_ref = SubjectScope.from_dict(
{
"id": old_ref["id"],
- 'subject_category_scope': scope,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'subject_scope': scope,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in SubjectCategoryScope.attributes:
+ for attr in SubjectScope.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
# Getter and Setter for object_category_scope
- def get_object_scope_dict(self, extension_uuid, object_category):
+ def get_object_scope_dict(self, intra_extension_id, object_category_id):
with sql.transaction() as session:
- query = session.query(ObjectCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
result = copy.deepcopy(ref.to_dict())
- if object_category not in result["object_category_scope"].keys():
+ if object_category_id not in result["object_scopes"].keys():
raise ObjectScopeUnknown()
return result
- def set_object_scope_dict(self, extension_uuid, object_category, scope):
+ def set_object_scope_dict(self, intra_extension_id, object_category_id, object_scope_id):
with sql.transaction() as session:
- query = session.query(ObjectCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
- new_ref = ObjectCategoryScope.from_dict(
+ new_ref = ObjectScope.from_dict(
{
"id": uuid4().hex,
- 'object_category_scope': {object_category: scope},
- 'intra_extension_uuid': extension_uuid
+ 'object_scope': {object_category_id: object_scope_id},
+ 'intra_extension_id': intra_extension_id
}
)
session.add(new_ref)
else:
tmp_ref = ref.to_dict()
- tmp_ref['object_category_scope'].update({object_category: scope})
+ tmp_ref['object_scope'].update({object_category_id: object_scope_id})
session.delete(ref)
- new_ref = ObjectCategoryScope.from_dict(tmp_ref)
+ new_ref = ObjectScope.from_dict(tmp_ref)
session.add(new_ref)
return new_ref.to_dict()
- def add_object_scope(self, extension_uuid, object_category, scope_uuid, scope_name):
+ def add_object_scope(self, intra_extension_id, object_category_id, object_scope_id, object_scope_name):
with sql.transaction() as session:
- query = session.query(ObjectCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- scope = dict(old_ref["object_category_scope"])
- if object_category not in scope:
- scope[object_category] = dict()
- scope[object_category][scope_uuid] = scope_name
- return self.set_object_scope_dict(extension_uuid, object_category, scope[object_category])
+ scope = dict(old_ref["object_scope"])
+ if object_category_id not in scope:
+ scope[object_category_id] = dict()
+ scope[object_category_id][object_scope_id] = object_scope_name
+ return self.set_object_scope_dict(intra_extension_id, object_category_id, scope[object_category_id])
- def del_object_scope(self, extension_uuid, object_category, scope_uuid):
+ def del_object_scope(self, intra_extension_id, object_category_id, object_scope_id):
with sql.transaction() as session:
- query = session.query(ObjectCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- scope = dict(old_ref["object_category_scope"])
- if object_category not in scope:
+ scope = dict(old_ref["object_scope"])
+ if object_category_id not in scope:
return
try:
- scope[object_category].pop(scope_uuid)
+ scope[object_category_id].pop(object_scope_id)
except KeyError:
return
- new_ref = ObjectCategoryScope.from_dict(
+ new_ref = ObjectScope.from_dict(
{
"id": old_ref["id"],
- 'object_category_scope': scope,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'object_scope': scope,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in ObjectCategoryScope.attributes:
+ for attr in ObjectScope.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- # Getter and Setter for action_category_scope
+ # Getter and Setter for action_scope
- def get_action_scope_dict(self, extension_uuid, action_category):
+ def get_action_scope_dict(self, intra_extension_id, action_category_id):
with sql.transaction() as session:
- query = session.query(ActionCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
result = copy.deepcopy(ref.to_dict())
- if action_category not in result["action_category_scope"].keys():
+ if action_category_id not in result["action_scope"].keys():
raise ActionScopeUnknown()
return result
- def set_action_scope_dict(self, extension_uuid, action_category, scope):
+ def set_action_scope_dict(self, intra_extension_id, action_category_id, action_scope_id):
with sql.transaction() as session:
- query = session.query(ActionCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
- new_ref = ActionCategoryScope.from_dict(
+ new_ref = ActionScope.from_dict(
{
"id": uuid4().hex,
- 'action_category_scope': {action_category: scope},
- 'intra_extension_uuid': extension_uuid
+ 'action_scope': {action_category_id: action_scope_id},
+ 'intra_extension_id': intra_extension_id
}
)
session.add(new_ref)
else:
tmp_ref = ref.to_dict()
- tmp_ref['action_category_scope'].update({action_category: scope})
+ tmp_ref['action_scope'].update({action_category_id: action_scope_id})
session.delete(ref)
- new_ref = ActionCategoryScope.from_dict(tmp_ref)
+ new_ref = ActionScope.from_dict(tmp_ref)
session.add(new_ref)
return new_ref.to_dict()
- def add_action_scope(self, extension_uuid, action_category, scope_uuid, scope_name):
+ def add_action_scope(self, intra_extension_id, action_category_id, action_scope_id, action_scope_name):
with sql.transaction() as session:
- query = session.query(ActionCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- scope = dict(old_ref["action_category_scope"])
- if action_category not in scope:
- scope[action_category] = dict()
- scope[action_category][scope_uuid] = scope_name
- return self.set_action_scope_dict(extension_uuid, action_category, scope[action_category])
+ scope = dict(old_ref["action_scope"])
+ if action_category_id not in scope:
+ scope[action_category_id] = dict()
+ scope[action_category_id][action_scope_id] = action_scope_name
+ return self.set_action_scope_dict(intra_extension_id, action_category_id, scope[action_category_id])
- def del_action_scope(self, extension_uuid, action_category, scope_uuid):
+ def del_action_scope(self, intra_extension_id, action_category_id, action_scope_id):
with sql.transaction() as session:
- query = session.query(ActionCategoryScope)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionScope)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- scope = dict(old_ref["action_category_scope"])
- if action_category not in scope:
+ scope = dict(old_ref["action_scope"])
+ if action_category_id not in scope:
return
try:
- scope[action_category].pop(scope_uuid)
+ scope[action_category_id].pop(action_scope_id)
except KeyError:
return
- new_ref = ActionCategoryScope.from_dict(
+ new_ref = ActionScope.from_dict(
{
"id": old_ref["id"],
- 'action_category_scope': scope,
- 'intra_extension_uuid': old_ref["intra_extension_uuid"]
+ 'action_scope': scope,
+ 'intra_extension_id': old_ref["intra_extension_id"]
}
)
- for attr in ActionCategoryScope.attributes:
+ for attr in ActionScope.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
# Getter and Setter for subject_category_assignment
- def get_subject_assignment_dict(self, extension_uuid, subject_uuid):
+ def get_subject_assignment_dict(self, intra_extension_id, subject_id):
""" From a subject_uuid, return a dictionary of (category: scope for that subject)
- :param extension_uuid: intra extension UUID
- :param subject_uuid: subject UUID
+ :param intra_extension_id: intra extension UUID
+ :param subject_id: subject UUID
:return: a dictionary of (keys are category nd values are scope for that subject)
"""
with sql.transaction() as session:
- query = session.query(SubjectCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
- raise IntraExtensionUnknown("get_subject_category_assignment_dict")
+ raise IntraExtensionUnknown()
_ref = ref.to_dict()
- if subject_uuid in _ref["subject_category_assignments"]:
- _backup_dict = _ref["subject_category_assignments"][subject_uuid]
- _ref["subject_category_assignments"] = dict()
- _ref["subject_category_assignments"][subject_uuid] = _backup_dict
+ if subject_id in _ref["subject_assignment"]:
+ _backup_dict = _ref["subject_assignment"][subject_id]
+ _ref["subject_assignment"] = dict()
+ _ref["subject_assignment"][subject_id] = _backup_dict
else:
- _ref["subject_category_assignments"] = dict()
- _ref["subject_category_assignments"][subject_uuid] = dict()
+ _ref["subject_assignment"] = dict()
+ _ref["subject_assignment"][subject_id] = dict()
return _ref
- def set_subject_assignment_dict(self, extension_uuid, subject_uuid=None, assignment_dict={}):
+ def set_subject_assignment_dict(self, intra_extension_id, subject_id=None, subject_assignment_dict={}):
with sql.transaction() as session:
- query = session.query(SubjectCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- if type(assignment_dict) is not dict:
+ if type(subject_assignment_dict) is not dict:
raise IntraExtensionError()
- for value in assignment_dict.values():
+ for value in subject_assignment_dict.values():
if type(value) is not list:
raise IntraExtensionError(str(value))
- if not subject_uuid:
- subject_category_assignments = {}
+ if not subject_id:
+ subject_assignments = {}
else:
- subject_category_assignments = {subject_uuid: assignment_dict}
- new_ref = SubjectCategoryAssignment.from_dict(
+ subject_assignments = {subject_id: subject_assignment_dict}
+ new_ref = SubjectAssignment.from_dict(
{
"id": uuid4().hex,
- 'subject_category_assignments': subject_category_assignments,
- 'intra_extension_uuid': extension_uuid
+ 'subject_assignment': subject_assignments,
+ 'intra_extension_id': intra_extension_id
}
)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- new_ref.subject_category_assignments[subject_uuid] = assignment_dict
- for attr in SubjectCategoryAssignment.attributes:
+ new_ref.subject_assignments[subject_id] = subject_assignment_dict
+ for attr in SubjectAssignment.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_subject_assignment(self, extension_uuid, subject_uuid, category_uuid, scope_uuid):
+ def add_subject_assignment(self, intra_extension_id, subject_id, subject_category_id, subject_scope_id):
with sql.transaction() as session:
- query = session.query(SubjectCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
- assignments = ref.to_dict()['subject_category_assignments']
- if subject_uuid not in assignments:
- assignments[subject_uuid] = dict()
- if category_uuid not in assignments[subject_uuid]:
- assignments[subject_uuid][category_uuid] = list()
- if scope_uuid not in assignments[subject_uuid][category_uuid]:
- assignments[subject_uuid][category_uuid].append(scope_uuid)
+ assignment = ref.to_dict()['subject_assignment']
+ if subject_id not in assignment:
+ assignment[subject_id] = dict()
+ if subject_category_id not in assignment[subject_id]:
+ assignment[subject_id][subject_category_id] = list()
+ if subject_scope_id not in assignment[subject_id][subject_category_id]:
+ assignment[subject_id][subject_category_id].append(subject_scope_id)
return self.set_subject_assignment_dict(
- extension_uuid,
- subject_uuid,
- assignments[subject_uuid])
+ intra_extension_id,
+ subject_id,
+ assignment[subject_id])
- def del_subject_assignment(self, extension_uuid, subject_uuid, category_uuid, scope_uuid):
+ def del_subject_assignment(self, intra_extension_id, subject_id, subject_category_id, subject_scope_id):
with sql.transaction() as session:
- query = session.query(SubjectCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubjectAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- if subject_uuid in old_ref["subject_category_assignments"]:
- if category_uuid in old_ref["subject_category_assignments"][subject_uuid]:
- old_ref["subject_category_assignments"][subject_uuid][category_uuid].remove(scope_uuid)
- if not old_ref["subject_category_assignments"][subject_uuid][category_uuid]:
- old_ref["subject_category_assignments"][subject_uuid].pop(category_uuid)
- if not old_ref["subject_category_assignments"][subject_uuid]:
- old_ref["subject_category_assignments"].pop(subject_uuid)
+ if subject_id in old_ref["subject_assignment"]:
+ if subject_category_id in old_ref["subject_assignment"][subject_id]:
+ old_ref["subject_assignment"][subject_id][subject_category_id].remove(subject_scope_id)
+ if not old_ref["subject_assignment"][subject_id][subject_category_id]:
+ old_ref["subject_assignment"][subject_id].pop(subject_category_id)
+ if not old_ref["subject_assignment"][subject_id]:
+ old_ref["subject_assignment"].pop(subject_id)
try:
self.set_subject_assignment_dict(
- extension_uuid,
- subject_uuid,
- old_ref["subject_category_assignments"][subject_uuid])
+ intra_extension_id,
+ subject_id,
+ old_ref["subject_assignment"][subject_id])
except KeyError:
self.set_subject_assignment_dict(
- extension_uuid,
- subject_uuid,
+ intra_extension_id,
+ subject_id,
{})
# Getter and Setter for object_category_assignment
- def get_object_assignment_dict(self, extension_uuid, object_uuid):
+ def get_object_assignment_dict(self, intra_extension_id, object_id):
""" From a object_uuid, return a dictionary of (category: scope for that object)
- :param extension_uuid: intra extension UUID
- :param object_uuid: object UUID
+ :param intra_extension_id: intra extension UUID
+ :param object_id: object UUID
:return: a dictionary of (keys are category nd values are scope for that object)
"""
with sql.transaction() as session:
- query = session.query(ObjectCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
_ref = ref.to_dict()
- if object_uuid in _ref["object_category_assignments"]:
- _backup_dict = _ref["object_category_assignments"][object_uuid]
- _ref["object_category_assignments"] = dict()
- _ref["object_category_assignments"][object_uuid] = _backup_dict
+ if object_id in _ref["object_assignment"]:
+ _backup_dict = _ref["object_assignment"][object_id]
+ _ref["object_assignment"] = dict()
+ _ref["object_assignment"][object_id] = _backup_dict
else:
- _ref["object_category_assignments"] = dict()
- _ref["object_category_assignments"][object_uuid] = dict()
+ _ref["object_assignment"] = dict()
+ _ref["object_assignment"][object_id] = dict()
return _ref
- def set_object_assignment_dict(self, extension_uuid, object_uuid=None, assignment_dict={}):
+ def set_object_assignment_dict(self, intra_extension_id, object_id=None, object_assignment_dict={}):
with sql.transaction() as session:
- query = session.query(ObjectCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- if type(assignment_dict) is not dict:
+ if type(object_assignment_dict) is not dict:
raise IntraExtensionError()
- for value in assignment_dict.values():
+ for value in object_assignment_dict.values():
if type(value) is not list:
raise IntraExtensionError(str(value))
- new_ref = ObjectCategoryAssignment.from_dict(
+ new_ref = ObjectAssignment.from_dict(
{
"id": uuid4().hex,
- 'object_category_assignments': {object_uuid: assignment_dict},
- 'intra_extension_uuid': extension_uuid
+ 'object_assignment': {object_id: object_assignment_dict},
+ 'intra_extension_id': intra_extension_id
}
)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- new_ref.object_category_assignments[object_uuid] = assignment_dict
- for attr in ObjectCategoryAssignment.attributes:
+ new_ref.object_assignment[object_id] = object_assignment_dict
+ for attr in ObjectAssignment.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_object_assignment(self, extension_uuid, object_uuid, category_uuid, scope_uuid):
+ def add_object_assignment(self, intra_extension_id, object_id, object_category_id, object_scope_id):
with sql.transaction() as session:
- query = session.query(ObjectCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
- assignments = ref.to_dict()['object_category_assignments']
- if object_uuid not in assignments:
- assignments[object_uuid] = dict()
- if category_uuid not in assignments[object_uuid]:
- assignments[object_uuid][category_uuid] = list()
- if scope_uuid not in assignments[object_uuid][category_uuid]:
- assignments[object_uuid][category_uuid].append(scope_uuid)
+ assignments = ref.to_dict()['object_assignment']
+ if object_id not in assignments:
+ assignments[object_id] = dict()
+ if object_category_id not in assignments[object_id]:
+ assignments[object_id][object_category_id] = list()
+ if object_scope_id not in assignments[object_id][object_category_id]:
+ assignments[object_id][object_category_id].append(object_scope_id)
return self.set_object_assignment_dict(
- extension_uuid,
- object_uuid,
- assignments[object_uuid])
+ intra_extension_id,
+ object_id,
+ assignments[object_id])
- def del_object_assignment(self, extension_uuid, object_uuid, category_uuid, scope_uuid):
+ def del_object_assignment(self, intra_extension_id, object_id, object_category_id, object_scope_id):
with sql.transaction() as session:
- query = session.query(ObjectCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ObjectAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- if object_uuid in old_ref["object_category_assignments"]:
- if category_uuid in old_ref["object_category_assignments"][object_uuid]:
- old_ref["object_category_assignments"][object_uuid][category_uuid].remove(scope_uuid)
- if not old_ref["object_category_assignments"][object_uuid][category_uuid]:
- old_ref["object_category_assignments"][object_uuid].pop(category_uuid)
- if not old_ref["object_category_assignments"][object_uuid]:
- old_ref["object_category_assignments"].pop(object_uuid)
+ if object_id in old_ref["object_assignment"]:
+ if object_category_id in old_ref["object_assignment"][object_id]:
+ old_ref["object_assignment"][object_id][object_category_id].remove(object_scope_id)
+ if not old_ref["object_assignment"][object_id][object_category_id]:
+ old_ref["object_assignment"][object_id].pop(object_category_id)
+ if not old_ref["object_assignment"][object_id]:
+ old_ref["object_assignment"].pop(object_id)
self.set_object_assignment_dict(
- extension_uuid,
- object_uuid,
- old_ref["object_category_assignments"][object_uuid])
+ intra_extension_id,
+ object_id,
+ old_ref["object_assignment"][object_id])
# Getter and Setter for action_category_assignment
- def get_action_assignment_dict(self, extension_uuid, action_uuid):
- """ From a action_uuid, return a dictionary of (category: scope for that action)
+ def get_action_assignment_dict(self, intra_extension_id, action_id):
+ """ From a action_id, return a dictionary of (category: scope for that action)
- :param extension_uuid: intra extension UUID
- :param action_uuid: action UUID
+ :param intra_extension_id: intra extension UUID
+ :param action_id: action UUID
:return: a dictionary of (keys are category nd values are scope for that action)
"""
with sql.transaction() as session:
- query = session.query(ActionCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
_ref = ref.to_dict()
- if action_uuid in _ref["action_category_assignments"]:
- _backup_dict = _ref["action_category_assignments"][action_uuid]
- _ref["action_category_assignments"] = dict()
- _ref["action_category_assignments"][action_uuid] = _backup_dict
+ if action_id in _ref["action_assignment"]:
+ _backup_dict = _ref["action_assignment"][action_id]
+ _ref["action_assignment"] = dict()
+ _ref["action_assignment"][action_id] = _backup_dict
else:
- _ref["action_category_assignments"] = dict()
- _ref["action_category_assignments"][action_uuid] = dict()
+ _ref["action_assignment"] = dict()
+ _ref["action_assignment"][action_id] = dict()
return _ref
- def set_action_assignment_dict(self, extension_uuid, action_uuid=None, assignment_dict={}):
+ def set_action_assignment_dict(self, intra_extension_id, action_id=None, action_assignment_dict={}):
with sql.transaction() as session:
- query = session.query(ActionCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- if type(assignment_dict) is not dict:
+ if type(action_assignment_dict) is not dict:
raise IntraExtensionError()
- for value in assignment_dict.values():
+ for value in action_assignment_dict.values():
if type(value) is not list:
raise IntraExtensionError(str(value))
- new_ref = ActionCategoryAssignment.from_dict(
+ new_ref = ActionAssignment.from_dict(
{
"id": uuid4().hex,
- 'action_category_assignments': {action_uuid: assignment_dict},
- 'intra_extension_uuid': extension_uuid
+ 'action_assignment': {action_id: action_assignment_dict},
+ 'intra_extension_id': intra_extension_id
}
)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- new_ref.action_category_assignments[action_uuid] = assignment_dict
- for attr in ActionCategoryAssignment.attributes:
+ new_ref.action_assignment[action_id] = action_assignment_dict
+ for attr in ActionAssignment.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
- def add_action_assignment(self, extension_uuid, action_uuid, category_uuid, scope_uuid):
+ def add_action_assignment(self, intra_extension_id, action_id, action_category_id, action_scope_id):
with sql.transaction() as session:
- query = session.query(ActionCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
- assignments = ref.to_dict()['action_category_assignments']
- if action_uuid not in assignments:
- assignments[action_uuid] = dict()
- if category_uuid not in assignments[action_uuid]:
- assignments[action_uuid][category_uuid] = list()
- if scope_uuid not in assignments[action_uuid][category_uuid]:
- assignments[action_uuid][category_uuid].append(scope_uuid)
+ assignments = ref.to_dict()['action_assignment']
+ if action_id not in assignments:
+ assignments[action_id] = dict()
+ if action_category_id not in assignments[action_id]:
+ assignments[action_id][action_category_id] = list()
+ if action_scope_id not in assignments[action_id][action_category_id]:
+ assignments[action_id][action_category_id].append(action_scope_id)
return self.set_action_assignment_dict(
- extension_uuid,
- action_uuid,
- assignments[action_uuid])
+ intra_extension_id,
+ action_id,
+ assignments[action_id])
- def del_action_assignment(self, extension_uuid, action_uuid, category_uuid, scope_uuid):
+ def del_action_assignment(self, intra_extension_id, action_id, action_category_id, action_scope_id):
with sql.transaction() as session:
- query = session.query(ActionCategoryAssignment)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(ActionAssignment)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
old_ref = ref.to_dict()
- if action_uuid in old_ref["action_category_assignments"]:
- if category_uuid in old_ref["action_category_assignments"][action_uuid]:
- old_ref["action_category_assignments"][action_uuid][category_uuid].remove(scope_uuid)
- if not old_ref["action_category_assignments"][action_uuid][category_uuid]:
- old_ref["action_category_assignments"][action_uuid].pop(category_uuid)
- if not old_ref["action_category_assignments"][action_uuid]:
- old_ref["action_category_assignments"].pop(action_uuid)
+ if action_id in old_ref["action_assignment"]:
+ if action_category_id in old_ref["action_assignment"][action_id]:
+ old_ref["action_assignment"][action_id][action_category_id].remove(action_scope_id)
+ if not old_ref["action_assignment"][action_id][action_category_id]:
+ old_ref["action_assignment"][action_id].pop(action_category_id)
+ if not old_ref["action_assignment"][action_id]:
+ old_ref["action_assignment"].pop(action_id)
self.set_action_assignment_dict(
- extension_uuid,
- action_uuid,
- old_ref["action_category_assignments"][action_uuid])
+ intra_extension_id,
+ action_id,
+ old_ref["action_assignment"][action_id])
# Getter and Setter for meta_rule
- def get_meta_rule_dict(self, extension_uuid):
+ def get_sub_meta_rule_dict(self, intra_extension_id):
with sql.transaction() as session:
- query = session.query(MetaRule)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubMetaRule)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
return ref.to_dict()
- def set_meta_rule_dict(self, extension_uuid, meta_rule_dict):
+ def set_sub_meta_rule_dict(self, intra_extension_id, sub_meta_rule_dict):
with sql.transaction() as session:
- query = session.query(MetaRule)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = session.query(SubMetaRule)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
- meta_rule_dict["id"] = uuid4().hex
- meta_rule_dict["intra_extension_uuid"] = extension_uuid
- new_ref = MetaRule.from_dict(meta_rule_dict)
+ sub_meta_rule_dict["id"] = uuid4().hex
+ sub_meta_rule_dict["intra_extension_id"] = intra_extension_id
+ new_ref = SubMetaRule.from_dict(sub_meta_rule_dict)
if not ref:
session.add(new_ref)
ref = new_ref
else:
- for attr in MetaRule.attributes:
+ for attr in SubMetaRule.attributes:
if attr != 'id':
setattr(ref, attr, getattr(new_ref, attr))
return ref.to_dict()
# Getter and Setter for rules
- def get_rule_dict(self, extension_uuid):
+ def get_rule_dict(self, intra_extension_id):
with sql.transaction() as session:
query = session.query(Rule)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
if not ref:
raise IntraExtensionUnknown()
return ref.to_dict()
- def set_rule_dict(self, extension_uuid, rule_dict):
+ def set_rule_dict(self, intra_extension_id, rule_dict):
with sql.transaction() as session:
query = session.query(Rule)
- query = query.filter_by(intra_extension_uuid=extension_uuid)
+ query = query.filter_by(intra_extension_id=intra_extension_id)
ref = query.first()
rules = dict()
rules["id"] = uuid4().hex
- rules["intra_extension_uuid"] = extension_uuid
- rules["rules"] = rule_dict
+ rules["intra_extension_id"] = intra_extension_id
+ rules["rule"] = rule_dict
new_ref = Rule.from_dict(rules)
if not ref:
session.add(new_ref)
@@ -1434,11 +1466,15 @@ class TenantConnector(TenantDriver):
# query = query.filter_by(uuid=tenant_uuid)
# ref = query.first().to_dict()
tenants = query.all()
- if not tenants:
- raise TenantListEmpty()
return {tenant.id: Tenant.to_dict(tenant) for tenant in tenants}
- # return [Tenant.to_dict(tenant) for tenant in tenants]
+ def add_tenant(self, tenant_id, tenant_name, intra_authz_ext_id, intra_admin_ext_id):
+ pass
+
+ def del_tenant(self, tenant_id):
+ pass
+
+ # TODO: def set_tenant(self, tenant_id, tenant_name, intra_authz_ext_id, intra_admin_ext_id)
def set_tenant_dict(self, tenant):
with sql.transaction() as session:
uuid = tenant.keys()[0]
@@ -1474,15 +1510,15 @@ class TenantConnector(TenantDriver):
# __tablename__ = 'inter_extension'
# attributes = [
# 'id',
-# 'requesting_intra_extension_uuid',
-# 'requested_intra_extension_uuid',
+# 'requesting_intra_extension_id',
+# 'requested_intra_extension_id',
# 'virtual_entity_uuid',
# 'genre',
# 'description',
# ]
# id = sql.Column(sql.String(64), primary_key=True)
-# requesting_intra_extension_uuid = sql.Column(sql.String(64))
-# requested_intra_extension_uuid = sql.Column(sql.String(64))
+# requesting_intra_extension_id = sql.Column(sql.String(64))
+# requested_intra_extension_id = sql.Column(sql.String(64))
# virtual_entity_uuid = sql.Column(sql.String(64))
# genre = sql.Column(sql.String(64))
# description = sql.Column(sql.Text())
diff --git a/keystone-moon/keystone/contrib/moon/core.py b/keystone-moon/keystone/contrib/moon/core.py
index b92238f2..74e3404d 100644
--- a/keystone-moon/keystone/contrib/moon/core.py
+++ b/keystone-moon/keystone/contrib/moon/core.py
@@ -187,7 +187,10 @@ class TenantManager(manager.Manager):
:return: dict
"""
# TODO: check user right with user_id in SuperExtension
- return self.driver.get_tenant_dict()
+ tenant_dict = self.driver.get_tenant_dict()
+ if not tenant_dict:
+ raise TenantDictEmpty()
+ return tenant_dict
def add_tenant(self, user_id, tenant_name, intra_authz_ext_id, intra_admin_ext_id):
# TODO: check user right with user_id in SuperExtension
@@ -229,7 +232,6 @@ class TenantManager(manager.Manager):
if tenant_id not in tenant_dict:
raise TenantUnknown()
return self.driver.set_tenant(
- self,
tenant_id,
tenant_name,
tenant_dict[tenant_id]['intra_authz_ext_id'],
@@ -308,14 +310,14 @@ class IntraExtensionManager(manager.Manager):
'subject_uuid': xxx,
'object_uuid': yyy,
'action_uuid': zzz,
- 'subject_attributes': {
+ 'subject_assignments': {
'subject_category1': [],
'subject_category2': [],
...
'subject_categoryn': []
},
- 'object_attributes': {},
- 'action_attributes': {},
+ 'object_assignments': {},
+ 'action_assignments': {},
}
"""
authz_buffer = dict()
@@ -323,30 +325,30 @@ class IntraExtensionManager(manager.Manager):
authz_buffer['object_id'] = object_id
authz_buffer['action_id'] = action_id
meta_data_dict = dict()
- meta_data_dict["subject_categories"] = self.driver.get_subject_category_dict(intra_extension_id)["subject_categories"]
- meta_data_dict["object_categories"] = self.driver.get_object_category_dict(intra_extension_id)["object_categories"]
- meta_data_dict["action_categories"] = self.driver.get_action_category_dict(intra_extension_id)["action_categories"]
+ meta_data_dict["subject_categories"] = self.driver.get_subject_category_dict(intra_extension_id)
+ meta_data_dict["object_categories"] = self.driver.get_object_category_dict(intra_extension_id)
+ meta_data_dict["action_categories"] = self.driver.get_action_category_dict(intra_extension_id)
subject_assignment_dict = dict()
for category in meta_data_dict["subject_categories"]:
subject_assignment_dict[category] = self.driver.get_subject_assignment_dict(
- intra_extension_id, category)["subject_category_assignments"]
+ intra_extension_id, subject_id)[category]
object_assignment_dict = dict()
for category in meta_data_dict["object_categories"]:
object_assignment_dict[category] = self.driver.get_object_assignment_dict(
- intra_extension_id, category)["object_category_assignments"]
+ intra_extension_id, object_id)[category]
action_assignment_dict = dict()
for category in meta_data_dict["action_categories"]:
action_assignment_dict[category] = self.driver.get_action_assignment_dict(
- intra_extension_id, category)["action_category_assignments"]
+ intra_extension_id, action_id)[category]
authz_buffer['subject_attributes'] = dict()
authz_buffer['object_attributes'] = dict()
authz_buffer['action_attributes'] = dict()
for _subject_category in meta_data_dict['subject_categories']:
- authz_buffer['subject_attributes'][_subject_category] = subject_assignment_dict[_subject_category]
+ authz_buffer['subject_assignments'][_subject_category] = subject_assignment_dict[_subject_category]
for _object_category in meta_data_dict['object_categories']:
- authz_buffer['object_attributes'][_object_category] = object_assignment_dict[_object_category]
+ authz_buffer['object_assignments'][_object_category] = object_assignment_dict[_object_category]
for _action_category in meta_data_dict['action_categories']:
- authz_buffer['action_attributes'][_action_category] = action_assignment_dict[_action_category]
+ authz_buffer['action_assignments'][_action_category] = action_assignment_dict[_action_category]
return authz_buffer
def authz(self, intra_extension_id, subject_id, object_id, action_id):
@@ -369,7 +371,7 @@ class IntraExtensionManager(manager.Manager):
authz_buffer = self.__get_authz_buffer(intra_extension_id, subject_id, object_id, action_id)
decision_buffer = dict()
- meta_rule_dict = self.driver.get_meta_rule_dict(intra_extension_id)
+ meta_rule_dict = self.driver.get_sub_meta_rule_dict(intra_extension_id)
for sub_meta_rule_id in meta_rule_dict['sub_meta_rules']:
if meta_rule_dict['sub_meta_rules'][sub_meta_rule_id]['algorithm'] == 'inclusion':
@@ -592,7 +594,7 @@ class IntraExtensionManager(manager.Manager):
"aggregation": json_metarule["aggregation"],
"sub_meta_rules": metarule
}
- self.driver.set_meta_rule_dict(intra_extension_dict["id"], submetarules)
+ self.driver.set_sub_meta_rule_dict(intra_extension_dict["id"], submetarules)
def __load_rule_file(self, intra_extension_dict, policy_dir):
@@ -602,7 +604,7 @@ class IntraExtensionManager(manager.Manager):
intra_extension_dict["rule"] = {"rule": copy.deepcopy(json_rules)}
# Translate value from JSON file to UUID for Database
rules = dict()
- sub_meta_rules = self.driver.get_meta_rule_dict(intra_extension_dict["id"])
+ sub_meta_rules = self.driver.get_sub_meta_rule_dict(intra_extension_dict["id"])
for relation in json_rules:
# print(relation)
# print(self.get_sub_meta_rule_relations("admin", ie["id"]))
@@ -1831,7 +1833,7 @@ class IntraExtensionDriver(object):
"""
raise exception.NotImplemented() # pragma: no cover
- def set_subject_category_dict(self, intra_extension_id, subject_category_dict):
+ def set_subject_category_dict(self, intra_extension_id, subject_category_id, subject_category_dict):
"""Set the list of all subject categories
:param intra_extension_id: IntraExtension UUID
@@ -2409,7 +2411,7 @@ class IntraExtensionDriver(object):
# Meta_rule functions
- def get_meta_rule_dict(self, extension_uuid):
+ def get_sub_meta_rule_dict(self, extension_uuid):
"""Get the Meta rule
:param extension_uuid: IntraExtension UUID
@@ -2431,7 +2433,7 @@ class IntraExtensionDriver(object):
"""
raise exception.NotImplemented() # pragma: no cover
- def set_meta_rule_dict(self, extension_uuid, meta_rule_dict):
+ def set_sub_meta_rule_dict(self, extension_uuid, meta_rule_dict):
"""Set the Meta rule
:param extension_uuid: IntraExtension UUID
diff --git a/keystone-moon/keystone/tests/moon/unit/test_unit_core_configuration.py b/keystone-moon/keystone/tests/moon/unit/test_unit_core_configuration.py
new file mode 100644
index 00000000..e6388559
--- /dev/null
+++ b/keystone-moon/keystone/tests/moon/unit/test_unit_core_configuration.py
@@ -0,0 +1,57 @@
+# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
+# This software is distributed under the terms and conditions of the 'Apache-2.0'
+# license which can be found in the file 'LICENSE' in this package distribution
+# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
+
+"""Unit tests for core configuration."""
+
+import uuid
+from oslo_config import cfg
+from keystone.tests import unit as tests
+from keystone.contrib.moon.core import ConfigurationManager
+from keystone.tests.unit.ksfixtures import database
+from keystone.contrib.moon.exception import *
+from keystone.tests.unit import default_fixtures
+from keystone.contrib.moon.core import LogManager
+
+CONF = cfg.CONF
+
+
+class TestConfigurationManager(tests.TestCase):
+
+ def setUp(self):
+ self.useFixture(database.Database())
+ super(TestConfigurationManager, self).setUp()
+ self.load_backends()
+ self.load_fixtures(default_fixtures)
+ self.manager = ConfigurationManager()
+
+ def load_extra_backends(self):
+ return {
+ "moonlog_api": LogManager()
+ }
+
+ def config_overrides(self):
+ super(TestConfigurationManager, self).config_overrides()
+ self.config_fixture.config(
+ group='moon',
+ tenant_driver='keystone.contrib.moon.backends.sql.ConfigurationConnector')
+
+ def test_get_policy_template_dict(self):
+ pass
+
+ def test_get_policy_template_id_from_name(self):
+ pass
+
+ def test_get_aggregation_algorithm_dict(self):
+ pass
+
+ def test_get_aggregation_algorithm_id_from_name(self):
+ pass
+
+ def test_get_sub_meta_rule_algorithm_dict(self):
+ pass
+
+ def test_get_sub_meta_rule_algorithm_id_from_name(self):
+ pass
+
diff --git a/keystone-moon/keystone/tests/moon/unit/test_unit_core_tenant.py b/keystone-moon/keystone/tests/moon/unit/test_unit_core_tenant.py
index bc34feaa..1da57990 100644
--- a/keystone-moon/keystone/tests/moon/unit/test_unit_core_tenant.py
+++ b/keystone-moon/keystone/tests/moon/unit/test_unit_core_tenant.py
@@ -65,11 +65,7 @@ class TestTenantManager(tests.TestCase):
data = self.manager.get_admin_extension_uuid(new_mapping[_uuid]["authz"])
self.assertEquals(new_mapping[_uuid]["admin"], data)
- def test_tenant_list_empty(self):
- data = self.manager.get_tenant_dict()
- self.assertEqual(data, {})
-
- def test_set_tenant_name(self):
+ def test_del_tenant(self):
_uuid = uuid.uuid4().hex
new_mapping = {
_uuid: {
@@ -86,13 +82,15 @@ class TestTenantManager(tests.TestCase):
)
self.assertEquals(_uuid, data["id"])
self.assertEquals(data["name"], new_mapping[_uuid]["name"])
- data = self.manager.set_tenant_name(_uuid, "new name")
- self.assertEquals(_uuid, data["id"])
- self.assertEquals(data["name"], "new name")
- data = self.manager.get_tenant_name_from_id(_uuid)
- self.assertEquals(data, "new name")
+ self.assertEquals(data["authz"], new_mapping[_uuid]["authz"])
+ self.assertEquals(data["admin"], new_mapping[_uuid]["admin"])
+ data = self.manager.get_tenant_dict()
+ self.assertNotEqual(data, {})
+ self.manager.delete(new_mapping[_uuid]["authz"])
+ data = self.manager.get_tenant_dict()
+ self.assertEqual(data, {})
- def test_delete_tenant(self):
+ def test_set_tenant_name(self):
_uuid = uuid.uuid4().hex
new_mapping = {
_uuid: {
@@ -109,15 +107,13 @@ class TestTenantManager(tests.TestCase):
)
self.assertEquals(_uuid, data["id"])
self.assertEquals(data["name"], new_mapping[_uuid]["name"])
- self.assertEquals(data["authz"], new_mapping[_uuid]["authz"])
- self.assertEquals(data["admin"], new_mapping[_uuid]["admin"])
- data = self.manager.get_tenant_dict()
- self.assertNotEqual(data, {})
- self.manager.delete(new_mapping[_uuid]["authz"])
- data = self.manager.get_tenant_dict()
- self.assertEqual(data, {})
+ data = self.manager.set_tenant_name(_uuid, "new name")
+ self.assertEquals(_uuid, data["id"])
+ self.assertEquals(data["name"], "new name")
+ data = self.manager.get_tenant_name_from_id(_uuid)
+ self.assertEquals(data, "new name")
- def test_get_extension_uuid(self):
+ def test_get_tenant_intra_extension_id(self):
_uuid = uuid.uuid4().hex
new_mapping = {
_uuid: {
@@ -138,7 +134,7 @@ class TestTenantManager(tests.TestCase):
data = self.manager.get_extension_id(_uuid, "admin")
self.assertEqual(data, new_mapping[_uuid]["admin"])
- def test_unkown_tenant_uuid(self):
+ def test_exception_tenantunknown(self):
self.assertRaises(TenantIDNotFound, self.manager.get_tenant_name_from_id, uuid.uuid4().hex)
self.assertRaises(TenantIDNotFound, self.manager.set_tenant_name, uuid.uuid4().hex, "new name")
self.assertRaises(TenantIDNotFound, self.manager.get_extension_id, uuid.uuid4().hex)
@@ -160,3 +156,9 @@ class TestTenantManager(tests.TestCase):
self.assertRaises(IntraExtensionUnknown, self.manager.get_extension_id, _uuid, "admin")
self.assertRaises(TenantIDNotFound, self.manager.get_tenant_uuid, uuid.uuid4().hex)
# self.assertRaises(AdminIntraExtensionNotFound, self.manager.get_admin_extension_uuid, uuid.uuid4().hex)
+
+ def test_exception_tenantaddednameexisting(self):
+ pass
+
+ def test_exception_tenantnointraextension(self):
+ pass \ No newline at end of file