def add_trusted_host(arguments): if len(arguments) < 3: cli_error('You must pass at least the user name, password digest ' 'and the host UUID!') else: username = str(arguments.popleft()) digest = str(arguments.popleft()) host_uuid = try_parse_uuid(arguments.popleft()) node_map = proceed_with_node() if node_map is not None: # Finally, add user NodeApp.add_user(UserGroupUUID.safe_cast_uuid(gen_uuid()), username=str(username), digest=digest, is_trusted=True) _for_storage = True _for_restore = False NodeApp.add_host(username=username, hostname='Trusted: {}'.format(host_uuid), host_uuid=host_uuid, trusted_host_tuple=(_for_storage, _for_restore)) NodeApp.change_user(username, digest) print(u'Added Trusted Host {!r}'.format(username))
def __add_new_regular_user(username, arguments): if not arguments: cli_error('No digest string passed!') else: # Parse digest digest_str = arguments.popleft() try: digest = '{:040x}'.format(int(digest_str, 16)) except: cli_error('The argument \"{}\" is not a valid hexadecimal digest!' .format(digest_str)) if len(digest) != 40: cli_error('The digest argument should be a hexadecimal number ' 'up to 40 hexadigits long rather than {}!' .format(digest)) # Parse group UUID (optional) try: group_uuid = UUID(arguments[0]) # Parsed successfully arguments.popleft() except (IndexError, ValueError): group_uuid = gen_uuid() # Finally, add user NodeApp.add_user(UserGroupUUID.safe_cast_uuid(group_uuid), username=str(username), digest=digest, is_trusted=False) print(u'Added user "{}"'.format(username))