def add_right(ctx, role_name, rights, org_name): try: client = ctx.obj['client'] if org_name is not None: org_href = client.get_org_by_name(org_name).get('href') else: org_href = ctx.obj['profiles'].get('org_href') org = Org(client, href=org_href) role_record = org.get_role_record(role_name) role = Role(client, href=role_record.get('href')) role.add_rights(list(rights), org) stdout('Rights added successfully to the role \'%s\'' % role_name, ctx) except Exception as e: stderr(e, ctx)
def add_right(ctx, role_name, rights, org_name): try: restore_session(ctx) client = ctx.obj['client'] if org_name is not None: org_href = client.get_org_by_name(org_name).get('href') else: org_href = ctx.obj['profiles'].get('org_href') org = Org(client, href=org_href) role_record = org.get_role_record(role_name) role = Role(client, href=role_record.get('href')) role.add_rights(list(rights), org) stdout('Rights added successfully to the role \'%s\'' % role_name, ctx) except Exception as e: stderr(e, ctx)
def assign_native_rights(role_name, right_list=None, logger=NULL_LOGGER): logger.debug(f"Assigning rights {right_list} to the role {role_name}") if not right_list: logger.debug(f"Skipping assigning native rights to role {role_name}") return try: test_org = Org(CLIENT, href=TEST_ORG_HREF) role_resource = test_org.get_role_resource(role_name) role = Role(CLIENT, resource=role_resource) initial_right_set = set([r['name'] for r in role.list_rights()]) right_set = set(right_list) initial_right_set.update(right_set) role.add_rights(list(initial_right_set), test_org) except Exception as e: logger.warning(f"Failed to assign native rights " f"{right_list} to role {role_name}: {e} ")
def test_09_add_rights_to_Role(self): org_in_use = self.config['vcd']['org_in_use'] org = Org(self.client, href=self.client.get_org_by_name(org_in_use).get('href')) role_name = self.config['vcd']['role_name'] right_name = self.config['vcd']['right_name'] role_record = org.get_role_record(role_name) role = Role(self.client, href=role_record.get('href')) updated_role_resource = role.add_rights([right_name], org) success = False if hasattr(updated_role_resource, 'RightReferences') and \ hasattr(updated_role_resource.RightReferences, 'RightReference'): for right in updated_role_resource.RightReferences.RightReference: if right.get('name') == right_name: success = True break assert success