def do_add_user(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) input_file = resolve_input_file(args.file_name) location_string = 'corp' if args.site_name: api.site = args.site_name location_string = args.site_name user_list = [] if args.email_id: user_list.append([args.email_id, args.role_name]) if input_file: user_list = get_users_from_file(input_file, 2) added_users = 0 for entry in user_list: user_role = entry[1] if args.role_name and len(entry[1]) >= 0: user_role = args.role_name data = resolve_user_data_role(api, user_role) if args.dry_run: print("Adding %s to %s with %s role" % (entry[0], location_string, data['role'])) add_new_user(api, entry[0], data['role'], args.api_user) added_users += 1 print("Added %d users" % added_users)
def do_list_users(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) if args.site_name: api.site = args.site_name users = api.get_site_members() else: users = api.get_corp_users() cols = ['email', 'role', 'status', 'name'] colFormat = "%45s %10s %10s %30s" if users: line_entries = [] if args.site_name: print('Site: %s' % args.site_name) print(colFormat % (cols[0], 'site-' + cols[1], cols[2], cols[3])) for user in users['data']: line_entries.append( colFormat % (user['user'][cols[0]], user[cols[1]], user['user'][cols[2]], user['user'][cols[3]])) else: print(colFormat % (cols[0], 'corp' + cols[1], cols[2], cols[3])) for user in users['data']: line_entries.append(colFormat % (user[cols[0]], user[cols[1]], user[cols[2]], user[cols[3]])) print_sorted_array(line_entries)
def do_list(args): print('Listing sites for "%s":' % args.corp) api = init_api(args.username, args.password, args.token, args.corp) resp = api.get_corp_sites() sites = ['%s [%s]' % (site['displayName'], site['name']) for site in resp['data']] sites.sort() for name in sites: print(' %s' % name) print('(%d sites)' % len(sites))
def do_list(args): print('Listing sites for "%s"%s:' % (args.corp, ' matching "%s"' % args.filter if args.filter != '*' else '')) api = init_api(args.username, args.password, args.token, args.corp) resp = api.get_corp_sites() sites = [] for site in resp['data']: if fnmatch.fnmatch(site['name'], args.filter): # Only include sites that match the filter pattern sites.append('%s [%s]' % (site['displayName'], site['name'])) sites.sort() for name in sites: print(' %s' % name) print('(%d sites)' % len(sites))
def do_list_membership(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) if args.email_id: memberships = api.get_memberships(args.email_id) cols = ['role', 'site'] colFormat = "%10s %s" if memberships: line_entries = [] for member in memberships['data']: line_entries.append(colFormat % ( member[cols[0]], "%s [%s]" % (member[cols[1]]['displayName'], member[cols[1]]['name']))) if len(line_entries) > 0: print(colFormat % (cols[0], cols[1])) print_sorted_array(line_entries)
def do_merge(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) # Get the current sites resp = api.get_corp_sites() # Filter the sites based on the provided destination pattern sites = [] for site in resp['data']: if fnmatch.fnmatch(site['name'], args.dst_site): sites.append(site['name']) # If the user provided an exact match name we don't want to change the # existing behavior of the merge command exact_match = False if len(sites) == 1 and sites[0] == args.dst_site: exact_match = True # Get confirmation of merge action if the name wasn't an exact match if not exact_match: # If no sites matched the filter print an error and return if not sites: print("No sites match '%s'" % args.dst_site) return print('Merging %s with %d site%s:' % (args.src_site, len(sites), 's' if len(sites) > 1 else '')) for site in sites: print(' %s' % site) str_input = 'Do you want to continue [y/N]? ' if args.yes: # If user specified --yes print the confirmation string with 'y' to # give positive feedback of the action print('%sy' % str_input) else: cont = input(str_input) # If confirmed, merge with identified sites if exact_match or args.yes or cont.lower() in ['y', 'yes']: for site in sites: merge(api, site, args.src_site, args.file_name, build_category_list(args.include, args.exclude), args.overwrite_templated_rules)
def do_remove_user(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) input_file = resolve_input_file(args.file_name) location_string = 'corp' if args.site_name: api.site = args.site_name location_string = args.site_name user_list = [] if args.email_id: user_list.append([args.email_id]) if input_file: user_list = get_users_from_file(input_file, 1) removed_users = 0 for entry in user_list: if args.dry_run: print("Removing %s from %s" % (entry[0], location_string)) remove_user(api, entry[0]) removed_users += 1 print("Removed %d users" % removed_users)
def do_backup(args): api = init_api(args.username, args.password, args.token, args.corp) backup(api, args.site_name, args.file_name)
def do_clone(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) clone(api, args.src_site, args.dst_site, args.display_name, build_category_list(args.include, args.exclude))
def do_deploy(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) deploy(api, args.site_name, args.file_name, args.display_name, build_category_list(args.include, args.exclude))
def do_migrate(args): api = init_api(args.username, args.password, args.token, args.corp) migrate(api, args.file_name, args.output_file, args.dest_corp, args.strip, args.keep_users)
def do_validate(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) validate(api, args.site_name, args.target, args.dry_run)
def do_merge(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) merge(api, args.dst_site, args.src_site, args.file_name)
def do_clone(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) clone(api, args.src_site, args.dst_site, args.display_name)
def do_deploy(args): api = init_api(args.username, args.password, args.token, args.corp, args.dry_run) deploy(api, args.site_name, args.file_name, args.display_name)