def iter_umapi_groups(self): try: groups = umapi_client.GroupsQuery(self.connection) for group in groups: yield group['groupName'] except umapi_client.UnavailableError as e: raise AssertionException("Error to query groups from Adobe Console: %s" % e)
def test_list_groups(config): conn, params = config groups = umapi_client.GroupsQuery(connection=conn) group_count = 0 for group in groups: name = group.get("groupName") member_count = group.get("memberCount", -1) logging.info("Group %s has %d members: %s", name, member_count, group) assert member_count >= 0 group_count += 1 logging.info("Found %d groups.", group_count) groups.reload() group_count_2 = len(groups.all_results()) assert group_count == group_count_2
def iter_groups(self): try: for g in umapi_client.GroupsQuery(self.connection): yield g except umapi_client.UnavailableError as e: raise AssertionException("Error contacting UMAPI server: %s" % e)
def scan_umapi(log: logging.Logger, options: Any, output_folder: Path) -> None: """ Call Adobe umapi and serialize results to compressed xml document :param log: :param options: :param output_folder: :return: """ scanned_groups = 0 scanned_users = 0 org_id = config['org_id'] # noinspection SpellCheckingInspection ext = ".scaa" output_file = output_folder.joinpath(options.uuid + ext) start_time = time.time() doc = Document() xml = doc.createElement('octoscan') xml.setAttribute("uuid", options.uuid) xml.setAttribute("timestamp", datetime.utcnow().replace(microsecond=0).isoformat()) xml.setAttribute("build", octoscan_build) doc.appendChild(xml) octoscan_config = doc.createElement('octoscan_config') if len(options.tag) > 0: append_info_element(doc, octoscan_config, 'tag', 'S', options.tag) append_info_element(doc, octoscan_config, 'OutputFolder', 'S', str(output_folder)) xml.appendChild(octoscan_config) meta = doc.createElement('meta') append_info_element(doc, meta, 'org_id', 'S', org_id) append_info_element(doc, meta, 'tech_acct_id', 'S', config['tech_acct_id']) xml.appendChild(meta) conn = None try: conn = umapi_client.Connection(org_id=org_id, auth_dict=config) except Exception as e: log.exception(e) if not conn: log.error("Failed to connect to Adobe cloud") groups = doc.createElement('groups') umapi_groups = umapi_client.GroupsQuery(conn) for umapi_group in umapi_groups: g = doc.createElement('group') g.setAttribute('name', umapi_group['groupName']) append_dict(doc, g, umapi_group) scanned_groups += 1 groups.appendChild(g) xml.appendChild(groups) users = doc.createElement('users') umapi_users = umapi_client.UsersQuery(conn) for umapi_user in umapi_users: u = doc.createElement('user') u.setAttribute('name', umapi_user['username']) append_dict(doc, u, umapi_user) scanned_users += 1 users.appendChild(u) xml.appendChild(users) end_time = time.time() performance = doc.createElement('octoscan_performance') append_info_element(doc, performance, 'seconds', 'I', str(int(end_time - start_time))) xml.appendChild(performance) with gzip.open(output_file, 'w') as f_out: f_out.write(doc.toprettyxml(indent="\t").encode('utf-8')) print(output_file) log.info( f"Adobe umapi {scanned_users} users {scanned_groups} groups scanned output to {output_file}" )