def prepare_user(username, password): """ Create a new user account (admin) for Cloudera Director Server :param username: Username for the new account :param password: Password for the new account :return: API exit code """ # Cloudera Director server runs at http://127.0.0.1:7189 try: logging.info('Creating new admin user for Cloudera Director Server') client = ApiClient("http://localhost:7189") AuthenticationApi(client).login( Login(username="******", password="******")) # create new login base on user input users_api = UsersApi(client) # Admin user by default has both roles users_api.create( User(username=username, password=password, enabled=True, roles=["ROLE_ADMIN", "ROLE_READONLY"])) logging.info('Successfully created new admin user %s.' % dirUsername) except HTTPError, e: logging.error("Failed to create user '%s'. %s" % (username, e.msg)) return ExitCodes.ERROR
def add_user(args): """ Create a new user account @param args: dict of parsed command line arguments that include an username and a password for the new account @return: script exit code """ try: users_api = UsersApi(get_authenticated_client(args)) users_api.create(User(username=args.username, password=args.password, enabled=True, roles=["ROLE_ADMIN"])) return ExitCodes.OK except HTTPError, e: if e.code == 302: # found sys.stderr.write("Cannot create duplicate user '%s'.\n" % (args.username,)) return ExitCodes.DUPLICATE_USER else: raise e
def add_user(args): """ Create a new user account @param args: dict of parsed command line arguments that include an username and a password for the new account @return: script exit code """ try: users_api = UsersApi(get_authenticated_client(args)) users_api.create(User(username=args.username, password=args.password, enabled=True, roles=["ROLE_ADMIN"])) return ExitCodes.OK except ApiException as exc: if exc.status == 409: # conflict sys.stderr.write("Cannot create duplicate user '%s'.\n" % (args.username,)) return ExitCodes.DUPLICATE_USER else: raise exc
def prepare_user(username, password): """ Create a new user account (admin) for Cloudera Director Server :param username: Username for the new account :param password: Password for the new account :return: API exit code """ # Cloudera Director server runs at http://127.0.0.1:7189 try: logging.info('Creating new admin user for Cloudera Director Server') client = ApiClient("http://localhost:7189") AuthenticationApi(client).login( Login(username="******", password="******")) # create new login base on user input users_api = UsersApi(client) # Admin user by default has both roles users_api.create(User(username=username, password=password, enabled=True, roles=["ROLE_ADMIN", "ROLE_READONLY"])) logging.info('Successfully created new admin user %s.' % dirUsername) except HTTPError, e: logging.error("Failed to create user '%s'. %s" % (username, e.msg)) return ExitCodes.ERROR