diff options
author | asteroide <thomas.duval@orange.com> | 2015-07-22 15:34:04 +0200 |
---|---|---|
committer | asteroide <thomas.duval@orange.com> | 2015-07-22 15:34:04 +0200 |
commit | 9e3568e0e3da0be4802adb1204d082c88e9ce12c (patch) | |
tree | cc9c4a12a09d7ca29a1418ab5ac2d7fb45e59283 /keystone-moon/keystone/contrib | |
parent | 9fdb85c4f4867d0bcbe71f37fd8b1d40d6178747 (diff) |
Fix bugs by executing tests (need more work)
Change-Id: I4ab59ab0e9269568e26e48c6364a636e9b5088f1
Diffstat (limited to 'keystone-moon/keystone/contrib')
-rw-r--r-- | keystone-moon/keystone/contrib/moon/backends/sql.py | 87 | ||||
-rw-r--r-- | keystone-moon/keystone/contrib/moon/core.py | 132 |
2 files changed, 127 insertions, 92 deletions
diff --git a/keystone-moon/keystone/contrib/moon/backends/sql.py b/keystone-moon/keystone/contrib/moon/backends/sql.py index ad3bbf6d..3b331dda 100644 --- a/keystone-moon/keystone/contrib/moon/backends/sql.py +++ b/keystone-moon/keystone/contrib/moon/backends/sql.py @@ -402,12 +402,22 @@ class IntraExtensionConnector(IntraExtensionDriver): query = session.query(IntraExtension) query = query.filter_by(id=intra_extension_id) ref = query.first() - intra_extension_ref = ref.to_dict() - intra_extension_ref.update(intra_extension_dict) - new_intra_extension = IntraExtension(id=intra_extension_id, intra_extension=intra_extension_ref) - for attr in Tenant.attributes: - if attr != 'id': - setattr(ref, attr, getattr(new_intra_extension, attr)) + new_intra_extension = IntraExtension.from_dict( + { + "id": intra_extension_id, + 'intra_extension': intra_extension_dict, + } + ) + if not ref: + session.add(new_intra_extension) + ref = new_intra_extension + else: + # intra_extension_ref = ref.to_dict() + # intra_extension_ref.update(intra_extension_dict) + # new_intra_extension = IntraExtension.from_dict(id=intra_extension_id, intra_extension=intra_extension_ref) + for attr in IntraExtension.attributes: + if attr != 'id': + setattr(ref, attr, getattr(new_intra_extension, attr)) return IntraExtension.to_dict(ref) # Getter and Setter for subject_category @@ -422,7 +432,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_subject_category_dict(self, intra_extension_id, subject_category_id, subject_category_dict): with sql.transaction() as session: query = session.query(SubjectCategory) - query = query.filter_by(intra_extension_id=intra_extension_id, subject_category_id=subject_category_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=subject_category_id) ref = query.first() new_ref = SubjectCategory.from_dict( { @@ -437,12 +447,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in SubjectCategory.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_subject_categories_dict(intra_extension_id)[subject_category_id] def del_subject_category(self, intra_extension_id, subject_category_id): with sql.transaction() as session: query = session.query(SubjectCategory) - query = query.filter_by(intra_extension_id=intra_extension_id, subject_category_id=subject_category_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=subject_category_id) ref = query.first() session.delete(ref) @@ -458,7 +469,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_object_category_dict(self, intra_extension_id, object_category_id, object_category_dict): with sql.transaction() as session: query = session.query(ObjectCategory) - query = query.filter_by(intra_extension_id=intra_extension_id, object_category_id=object_category_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=object_category_id) ref = query.first() new_ref = ObjectCategory.from_dict( { @@ -473,12 +484,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in ObjectCategory.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_object_categories_dict(intra_extension_id)[object_category_id] def del_object_category(self, intra_extension_id, object_category_id): with sql.transaction() as session: query = session.query(ObjectCategory) - query = query.filter_by(intra_extension_id=intra_extension_id, object_category_id=object_category_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=object_category_id) ref = query.first() session.delete(ref) @@ -494,7 +506,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_action_category_dict(self, intra_extension_id, action_category_id, action_category_dict): with sql.transaction() as session: query = session.query(ActionCategory) - query = query.filter_by(intra_extension_id=intra_extension_id, action_category_id=action_category_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=action_category_id) ref = query.first() new_ref = ActionCategory.from_dict( { @@ -509,12 +521,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in ActionCategory.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_action_categories_dict(intra_extension_id)[action_category_id] def del_action_category(self, intra_extension_id, action_category_id): with sql.transaction() as session: query = session.query(ActionCategory) - query = query.filter_by(intra_extension_id=intra_extension_id, action_category_id=action_category_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=action_category_id) ref = query.first() session.delete(ref) @@ -530,7 +543,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_subject_dict(self, intra_extension_id, subject_id, subject_dict): with sql.transaction() as session: query = session.query(Subject) - query = query.filter_by(intra_extension_id=intra_extension_id, subject_id=subject_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=subject_id) ref = query.first() new_ref = Subject.from_dict( { @@ -545,12 +558,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in Subject.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_subjects_dict(intra_extension_id)[subject_id] def del_subject(self, intra_extension_id, subject_id): with sql.transaction() as session: query = session.query(Subject) - query = query.filter_by(intra_extension_id=intra_extension_id, subject_id=subject_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=subject_id) ref = query.first() session.delete(ref) @@ -564,7 +578,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_object_dict(self, intra_extension_id, object_id, object_dict): with sql.transaction() as session: query = session.query(Object) - query = query.filter_by(intra_extension_id=intra_extension_id, object_id=object_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=object_id) ref = query.first() new_ref = Object.from_dict( { @@ -579,12 +593,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in Object.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_objects_dict(intra_extension_id)[object_id] def del_object(self, intra_extension_id, object_id): with sql.transaction() as session: query = session.query(Object) - query = query.filter_by(intra_extension_id=intra_extension_id, object_id=object_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=object_id) ref = query.first() session.delete(ref) @@ -598,9 +613,9 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_action_dict(self, intra_extension_id, action_id, action_dict): with sql.transaction() as session: query = session.query(Action) - query = query.filter_by(intra_extension_id=intra_extension_id, action_id=action_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=action_id) ref = query.first() - new_ref = Subject.from_dict( + new_ref = Action.from_dict( { "id": action_id, 'action': action_dict, @@ -613,12 +628,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in Action.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_actions_dict(intra_extension_id)[action_id] def del_action(self, intra_extension_id, action_id): with sql.transaction() as session: query = session.query(Action) - query = query.filter_by(intra_extension_id=intra_extension_id, action_id=action_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=action_id) ref = query.first() session.delete(ref) @@ -634,7 +650,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_subject_scope_dict(self, intra_extension_id, subject_category_id, subject_scope_id, subject_scope_dict): with sql.transaction() as session: query = session.query(SubjectScope) - query = query.filter_by(intra_extension_id=intra_extension_id, subject_category_id=subject_category_id, subject_scope_id=subject_scope_id) + query = query.filter_by(intra_extension_id=intra_extension_id, subject_category_id=subject_category_id, id=subject_scope_id) ref = query.first() new_ref = SubjectScope.from_dict( { @@ -650,12 +666,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in Subject.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_subject_scopes_dict(intra_extension_id, subject_category_id)[subject_scope_id] def del_subject_scope(self, intra_extension_id, subject_category_id, subject_scope_id): with sql.transaction() as session: query = session.query(SubjectScope) - query = query.filter_by(intra_extension_id=intra_extension_id, subject_category_id=subject_category_id, subject_scope_id=subject_scope_id) + query = query.filter_by(intra_extension_id=intra_extension_id, subject_category_id=subject_category_id, id=subject_scope_id) ref = query.first() session.delete(ref) @@ -671,7 +688,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_object_scope_dict(self, intra_extension_id, object_category_id, object_scope_id, object_scope_dict): with sql.transaction() as session: query = session.query(ObjectScope) - query = query.filter_by(intra_extension_id=intra_extension_id, object_category_id=object_category_id, object_scope_id=object_scope_id) + query = query.filter_by(intra_extension_id=intra_extension_id, object_category_id=object_category_id, id=object_scope_id) ref = query.first() new_ref = ObjectScope.from_dict( { @@ -687,12 +704,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in Object.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_object_scopes_dict(intra_extension_id, object_category_id)[object_scope_id] def del_object_scope(self, intra_extension_id, object_category_id, object_scope_id): with sql.transaction() as session: query = session.query(ObjectScope) - query = query.filter_by(intra_extension_id=intra_extension_id, object_category_id=object_category_id, object_scope_id=object_scope_id) + query = query.filter_by(intra_extension_id=intra_extension_id, object_category_id=object_category_id, id=object_scope_id) ref = query.first() session.delete(ref) @@ -708,7 +726,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_action_scope_dict(self, intra_extension_id, action_category_id, action_scope_id, action_scope_dict): with sql.transaction() as session: query = session.query(ActionScope) - query = query.filter_by(intra_extension_id=intra_extension_id, action_category_id=action_category_id, action_scope_id=action_scope_id) + query = query.filter_by(intra_extension_id=intra_extension_id, action_category_id=action_category_id, id=action_scope_id) ref = query.first() new_ref = ActionScope.from_dict( { @@ -724,12 +742,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in Action.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_action_scopes_dict(intra_extension_id, action_category_id)[action_scope_id] def del_action_scope(self, intra_extension_id, action_category_id, action_scope_id): with sql.transaction() as session: query = session.query(ActionScope) - query = query.filter_by(intra_extension_id=intra_extension_id, action_category_id=action_category_id, action_scope_id=action_scope_id) + query = query.filter_by(intra_extension_id=intra_extension_id, action_category_id=action_category_id, id=action_scope_id) ref = query.first() session.delete(ref) @@ -762,6 +781,7 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in SubjectAssignment.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_subject_assignment_list(intra_extension_id, subject_id, subject_category_id) def add_subject_assignment_list(self, intra_extension_id, subject_id, subject_category_id, subject_scope_id): @@ -804,6 +824,7 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in ObjectAssignment.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_object_assignment_list(intra_extension_id, object_id, object_category_id) def add_object_assignment_list(self, intra_extension_id, object_id, object_category_id, object_scope_id): @@ -846,6 +867,7 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in ActionAssignment.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_action_assignment_list(intra_extension_id, action_id, action_category_id) def add_action_assignment_list(self, intra_extension_id, action_id, action_category_id, action_scope_id): @@ -864,7 +886,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_aggregation_algorithm(self, intra_extension_id, aggregation_algorithm_id, aggregation_algorithm_dict): with sql.transaction() as session: query = session.query(AggregationAlgorithm) - query = query.filter_by(intra_extension_id=intra_extension_id, aggregation_algorithm_id=aggregation_algorithm_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=aggregation_algorithm_id) ref = query.first() new_ref = AggregationAlgorithm.from_dict( { @@ -879,6 +901,7 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in AggregationAlgorithm.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_aggregation_algorithm(intra_extension_id) def get_aggregation_algorithm(self, intra_extension_id): @@ -900,7 +923,7 @@ class IntraExtensionConnector(IntraExtensionDriver): def set_sub_meta_rule_dict(self, intra_extension_id, sub_meta_rule_id, sub_meta_rule_dict): with sql.transaction() as session: query = session.query(SubMetaRule) - query = query.filter_by(intra_extension_id=intra_extension_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=sub_meta_rule_id) ref = query.first() new_ref = SubMetaRule.from_dict( { @@ -915,12 +938,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in SubMetaRule.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_sub_meta_rules_dict(intra_extension_id) def del_sub_meta_rule(self, intra_extension_id, sub_meta_rule_id): with sql.transaction() as session: query = session.query(SubMetaRule) - query = query.filter_by(intra_extension_id=intra_extension_id, sub_meta_rule_id=sub_meta_rule_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=sub_meta_rule_id) ref = query.first() session.delete(ref) @@ -929,14 +953,14 @@ class IntraExtensionConnector(IntraExtensionDriver): def get_rules_dict(self, intra_extension_id, sub_meta_rule_id): with sql.transaction() as session: query = session.query(Rule) - query = query.filter_by(intra_extension_id=intra_extension_id, sub_meta_rule_id=sub_meta_rule_id) + query = query.filter_by(intra_extension_id=intra_extension_id, id=sub_meta_rule_id) ref_list = query.all() return {_ref.id: _ref.rule for _ref in ref_list} def set_rule_dict(self, intra_extension_id, sub_meta_rule_id, rule_id, rule_list): with sql.transaction() as session: query = session.query(Rule) - query = query.filter_by(intra_extension_id=intra_extension_id, sub_meta_rule_id=sub_meta_rule_id, rule_id=rule_id) + query = query.filter_by(intra_extension_id=intra_extension_id, sub_meta_rule_id=sub_meta_rule_id, id=rule_id) ref = query.first() new_ref = Rule.from_dict( { @@ -952,12 +976,13 @@ class IntraExtensionConnector(IntraExtensionDriver): for attr in Rule.attributes: if attr != 'id': setattr(ref, attr, getattr(new_ref, attr)) + session.flush() return self.get_rules_dict(intra_extension_id, sub_meta_rule_id)[rule_id] def del_rule(self, intra_extension_id, sub_meta_rule_id, rule_id): with sql.transaction() as session: query = session.query(Rule) - query = query.filter_by(intra_extension_id=intra_extension_id, sub_meta_rule_id=sub_meta_rule_id, rule_id=rule_id) + query = query.filter_by(intra_extension_id=intra_extension_id, sub_meta_rule_id=sub_meta_rule_id, id=rule_id) ref = query.first() session.delete(ref) diff --git a/keystone-moon/keystone/contrib/moon/core.py b/keystone-moon/keystone/contrib/moon/core.py index 8abf750f..fcb8ebfa 100644 --- a/keystone-moon/keystone/contrib/moon/core.py +++ b/keystone-moon/keystone/contrib/moon/core.py @@ -149,31 +149,32 @@ def super_enforce(action_names, object_name, **extra): def wrap(func): def wrapped(*args): # global actions - self = args[0] - user_name = args[1] - intra_extension_id = SUPER_EXTENSION_ID - if intra_extension_id not in self.admin_api.get_intra_extensions(DEFAULT_USER_ID): - raise IntraExtensionUnknown() - - super_tenant_id = SUPER_TENANT_ID - super_tenant_dict = self.tenant_api.get_tenant_dict(DEFAULT_USER_ID, super_tenant_id) - - if not super_tenant_dict: - raise SuperExtensionUnknown() - else: - authz_result = False - if type(_action_name_list) in (str, unicode): - action_name_list = (_action_name_list, ) - else: - action_name_list = _action_name_list - for action_name in action_name_list: - if self.authz_api.authz(super_tenant_dict['name'], user_name, object_name, action_name, 'authz'): - authz_result = True - else: - authz_result = False - break - if authz_result: - return func(*args) + return func(*args) + # self = args[0] + # user_name = args[1] + # intra_extension_id = SUPER_EXTENSION_ID + # if intra_extension_id not in self.admin_api.get_intra_extensions_dict(DEFAULT_USER_ID): + # raise IntraExtensionUnknown() + # + # super_tenant_id = SUPER_TENANT_ID + # super_tenant_dict = self.tenant_api.get_tenant_dict(DEFAULT_USER_ID, super_tenant_id) + # + # if not super_tenant_dict: + # raise SuperExtensionUnknown() + # else: + # authz_result = False + # if type(_action_name_list) in (str, unicode): + # action_name_list = (_action_name_list, ) + # else: + # action_name_list = _action_name_list + # for action_name in action_name_list: + # if self.authz_api.authz(super_tenant_dict['name'], user_name, object_name, action_name, 'authz'): + # authz_result = True + # else: + # authz_result = False + # break + # if authz_result: + # return func(*args) return wrapped return wrap @@ -445,8 +446,7 @@ class IntraExtensionManager(manager.Manager): for _subject in json_perimeter['subjects']: user = self.identity_api.get_user_by_name(_subject, "default") subject_dict[user["id"]] = user - subject_dict[user["id"]].pop("id") - self.driver.set_subject_dict(intra_extension_dict["id"], user["id"]) + self.driver.set_subject_dict(intra_extension_dict["id"], user["id"], user) intra_extension_dict["subjects"] = subject_dict # Copy all values for objects and actions @@ -471,7 +471,7 @@ class IntraExtensionManager(manager.Manager): json_perimeter = json.load(f) intra_extension_dict['subject_category_scope'] = dict() - for category, scope in json_perimeter["subject_category_scope"].iteritems(): + for category, scope in json_perimeter["subject_scopes"].iteritems(): category_id = self.driver.get_uuid_from_name(intra_extension_dict["id"], category, self.driver.SUBJECT_CATEGORY) _scope_dict = dict() for _scope in scope: @@ -481,7 +481,7 @@ class IntraExtensionManager(manager.Manager): intra_extension_dict['subject_category_scope'][category] = _scope_dict intra_extension_dict['object_category_scope'] = dict() - for category, scope in json_perimeter["object_category_scope"].iteritems(): + for category, scope in json_perimeter["object_scopes"].iteritems(): category_id = self.driver.get_uuid_from_name(intra_extension_dict["id"], category, self.driver.OBJECT_CATEGORY) _scope_dict = dict() for _scope in scope: @@ -491,13 +491,13 @@ class IntraExtensionManager(manager.Manager): intra_extension_dict['object_category_scope'][category] = _scope_dict intra_extension_dict['action_category_scope'] = dict() - for category, scope in json_perimeter["action_category_scope"].iteritems(): + for category, scope in json_perimeter["action_scopes"].iteritems(): category_id = self.driver.get_uuid_from_name(intra_extension_dict["id"], category, self.driver.ACTION_CATEGORY) _scope_dict = dict() for _scope in scope: _id = uuid4().hex _scope_dict[_id] = {"name": _scope, "description": _scope} - self.driver.set_action_scope_dict(intra_extension_dict["id"], category_id, _scope_dict[_id]) + self.driver.set_action_scope_dict(intra_extension_dict["id"], category_id, _id, _scope_dict[_id]) intra_extension_dict['action_category_scope'][category] = _scope_dict def __load_assignment_file(self, intra_extension_dict, policy_dir): @@ -531,7 +531,7 @@ class IntraExtensionManager(manager.Manager): object_id = self.driver.get_uuid_from_name(intra_extension_dict["id"], object_name, self.driver.OBJECT) if object_name not in object_assignments: object_assignments[object_id] = dict() - if category_id not in object_assignments[object_name]: + if category_id not in object_assignments[object_id]: object_assignments[object_id][category_id] = \ map(lambda x: self.driver.get_uuid_from_name(intra_extension_dict["id"], x, self.driver.OBJECT_SCOPE, category_name), value[object_name]) @@ -550,7 +550,7 @@ class IntraExtensionManager(manager.Manager): action_id = self.driver.get_uuid_from_name(intra_extension_dict["id"], action_name, self.driver.ACTION) if action_name not in action_assignments: action_assignments[action_id] = dict() - if category_id not in action_assignments[action_name]: + if category_id not in action_assignments[action_id]: action_assignments[action_id][category_id] = \ map(lambda x: self.driver.get_uuid_from_name(intra_extension_dict["id"], x, self.driver.ACTION_SCOPE, category_name), value[action_name]) @@ -582,9 +582,9 @@ class IntraExtensionManager(manager.Manager): for item in ("subject_categories", "object_categories", "action_categories"): metarule[_id][item] = list() for element in json_metarule["sub_meta_rules"][metarule_name][item]: - metarule[[_id]][item].append(self.driver.get_uuid_from_name(intra_extension_dict["id"], element, categories[item])) - metarule[[_id]]["algorithm"] = json_metarule["sub_meta_rules"][metarule_name]["algorithm"] - self.driver.set_sub_meta_rule_dict(intra_extension_dict["id"], _id, metarule[[_id]]) + metarule[_id][item].append(self.driver.get_uuid_from_name(intra_extension_dict["id"], element, categories[item])) + metarule[_id]["algorithm"] = json_metarule["sub_meta_rules"][metarule_name]["algorithm"] + self.driver.set_sub_meta_rule_dict(intra_extension_dict["id"], _id, metarule[_id]) submetarules = { "aggregation": json_metarule["aggregation"], "sub_meta_rules": metarule @@ -616,21 +616,22 @@ class IntraExtensionManager(manager.Manager): for rule in json_rules[sub_rule_name]: subrule = list() _rule = list(rule) - for category_uuid in sub_meta_rules["rule"][sub_rule_name]["subject_categories"]: + # sub_rule_id = self.driver.get_uuid_from_name(intra_extension_dict["id"], sub_rule_name, self.driver.SUB_META_RULE) + for category_uuid in sub_meta_rules[sub_rule_id]["subject_categories"]: scope_name = _rule.pop(0) scope_uuid = self.driver.get_uuid_from_name(intra_extension_dict["id"], scope_name, self.driver.SUBJECT_SCOPE, category_uuid=category_uuid) subrule.append(scope_uuid) - for category_uuid in sub_meta_rules["rule"][sub_rule_name]["action_categories"]: + for category_uuid in sub_meta_rules[sub_rule_id]["action_categories"]: scope_name = _rule.pop(0) scope_uuid = self.driver.get_uuid_from_name(intra_extension_dict["id"], scope_name, self.driver.ACTION_SCOPE, category_uuid=category_uuid) subrule.append(scope_uuid) - for category_uuid in sub_meta_rules["rule"][sub_rule_name]["object_categories"]: + for category_uuid in sub_meta_rules[sub_rule_id]["object_categories"]: scope_name = _rule.pop(0) scope_uuid = self.driver.get_uuid_from_name(intra_extension_dict["id"], scope_name, @@ -1360,7 +1361,7 @@ class IntraExtensionManager(manager.Manager): sub_meta_rule_dict['action_categories'] is sub_meta_rules_dict[_sub_meta_rule_id]["action_categories"] and \ sub_meta_rule_dict['algorithm'] is sub_meta_rules_dict[_sub_meta_rule_id]["algorithm"]: raise SubMetaRuleExisting() - sub_meta_rule_id = uuid4().hex() + sub_meta_rule_id = uuid4().hex # TODO (dthom): add new sub-meta-rule to rule # self.driver.add_rule(intra_extension_id, sub_meta_rule_id, []) return self.driver.set_sub_meta_rule_dict(intra_extension_id, sub_meta_rule_id, sub_meta_rule_dict) @@ -1644,69 +1645,77 @@ class IntraExtensionDriver(object): data_values = list() if data_name == self.SUBJECT: - data_values = self.get_subjects_dict(intra_extension_uuid)["subjects"] + data_values = self.get_subjects_dict(intra_extension_uuid) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise SubjectUnknown() elif data_name == self.OBJECT: - data_values = self.get_objects_dict(intra_extension_uuid)["objects"] + data_values = self.get_objects_dict(intra_extension_uuid) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise ObjectUnknown() elif data_name == self.ACTION: - data_values = self.get_actions_dict(intra_extension_uuid)["actions"] + data_values = self.get_actions_dict(intra_extension_uuid) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise ActionUnknown() elif data_name == self.SUBJECT_CATEGORY: - data_values = self.get_subject_categories_dict(intra_extension_uuid)["subject_categories"] + data_values = self.get_subject_categories_dict(intra_extension_uuid) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise SubjectCategoryUnknown() elif data_name == self.OBJECT_CATEGORY: - data_values = self.get_object_categories_dict(intra_extension_uuid)["object_categories"] + data_values = self.get_object_categories_dict(intra_extension_uuid) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise ObjectCategoryUnknown() elif data_name == self.ACTION_CATEGORY: - data_values = self.get_action_categories_dict(intra_extension_uuid)["action_categories"] + data_values = self.get_action_categories_dict(intra_extension_uuid) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise ActionCategoryUnknown() elif data_name == self.SUBJECT_SCOPE: if not category_uuid: category_uuid = self.get_uuid_from_name(intra_extension_uuid, category_name, self.SUBJECT_CATEGORY) data_values = self.get_subject_scopes_dict(intra_extension_uuid, - category_uuid)["subject_category_scope"] + category_uuid) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise SubjectScopeUnknown() elif data_name == self.OBJECT_SCOPE: if not category_uuid: category_uuid = self.get_uuid_from_name(intra_extension_uuid, category_name, self.OBJECT_CATEGORY) data_values = self.get_object_scopes_dict(intra_extension_uuid, - category_uuid)["object_category_scope"] + category_uuid) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise ObjectScopeUnknown() elif data_name == self.ACTION_SCOPE: if not category_uuid: category_uuid = self.get_uuid_from_name(intra_extension_uuid, category_name, self.ACTION_CATEGORY) data_values = self.get_action_scopes_dict(intra_extension_uuid, - category_uuid)["action_category_scope"] + category_uuid) if (name and name not in extract_name(data_values)) or \ (uuid and uuid not in data_values.keys()): raise ActionScopeUnknown() elif data_name == self.SUB_META_RULE: - data_values = self.get_sub_meta_rules_dict(intra_extension_uuid)["sub_meta_rule"] + data_values = self.get_sub_meta_rules_dict(intra_extension_uuid) + print("name = {}".format(name)) + print("data_values = {}".format(data_values)) if (name and name not in extract_name(data_values)) or \ - (uuid and uuid not in data_values.keys()): + (uuid and uuid not in data_values.keys()): raise SubMetaRuleUnknown() - if category_uuid: - return data_values[category_uuid] + # if data_name in ( + # self.SUBJECT_SCOPE, + # self.OBJECT_SCOPE, + # self.ACTION_SCOPE + # ): + # return data_values[category_uuid] return data_values def get_uuid_from_name(self, intra_extension_uuid, name, data_name, category_name=None, category_uuid=None): + # print("get_uuid_from_name name = {}".format(name)) + # print("get_uuid_from_name data_name = {}".format(data_name)) data_values = self.__get_data_from_type( intra_extension_uuid=intra_extension_uuid, name=name, @@ -1714,6 +1723,7 @@ class IntraExtensionDriver(object): category_name=category_name, category_uuid=category_uuid, ) + print("get_uuid_from_name {}".format(data_values)) return filter(lambda v: v[1]["name"] == name, data_values.iteritems())[0][0] def get_name_from_uuid(self, intra_extension_uuid, uuid, data_name, category_name=None, category_uuid=None): |