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))
def add_user(arguments): node_map = proceed_with_node() if node_map is not None: if not arguments: cli_error('No user name passed') else: username_str = arguments.popleft() if arguments and arguments[0] == '--to-group': dummy = arguments.popleft() if not arguments: cli_error('Attempt to add user to group, ' 'but no group specified!') else: username = str(username_str) group_uuid = try_parse_uuid(arguments.popleft()) # Let's add the user to group NodeApp.add_user_to_group( username=username, group_uuid=UserGroupUUID.safe_cast_uuid(group_uuid)) print(u'Added user "{}" to the group "{}"' .format(username, group_uuid)) else: # Let's add the user to the system __add_new_regular_user(username_str, arguments)
def add_group(arguments): node_map = proceed_with_node() if node_map is not None: if len(arguments) < 1: cli_error('You must pass at least 1 argument to this command: ' 'the name of the group.') else: groupname_str = arguments.popleft() # Parse group UUID (optional) try: group_uuid = UUID(arguments[0]) # Parsed successfully arguments.popleft() except (IndexError, ValueError): group_uuid = gen_uuid() user_group = UserGroup(uuid=UserGroupUUID.safe_cast_uuid( group_uuid), name=str(groupname_str), private=False, enc_key=gen_rand_key()) NodeApp.add_ugroup(user_group) print(u'Added group "{}" with UUID {}' .format(groupname_str, group_uuid))
def add_host(arguments): if len(arguments) < 2: cli_error('You must pass at least the user name ' 'and the host UUID!') else: username = str(arguments.popleft()) host_uuid = try_parse_uuid(arguments.popleft()) node_map = proceed_with_node() if node_map is not None: NodeApp.add_host(username=username, hostname=str(host_uuid), host_uuid=host_uuid, trusted_host_tuple=None) print(u'Added host {} to "{}"'.format(host_uuid, username))
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 launch_node(arguments): node_map = proceed_with_node() if node_map is not None: node_app = NodeApp(node_map) node_app.first_start() # But it is not yet started, until the reactor is launched as well. # Launch reactor node_app.start_reactor()