def main(): """Create a new user or update an existing one. This requires a valid JWT token which you can get with `odin-auth`, or if it doesnt exist, it will prompt you for these """ signal.signal(signal.SIGINT, lambda *args, **kwargs: exit(0)) parser = argparse.ArgumentParser(description='Create or update an odin user') parser.add_argument('--host', default=ODIN_URL, type=str) parser.add_argument('--port', default=ODIN_PORT) parser.add_argument('--token', help="File where JWT token can reside", default=os.path.expanduser("~/.odin.token")) parser.add_argument('--username', '-u', help="Create or update a username") parser.add_argument('--password', '-p', help="New or updated password") parser.add_argument('--firstname', '-f', help="First name") parser.add_argument('--lastname', '-l', help="Last name") parser.add_argument('--scheme', choices={'http', 'https'}, default=ODIN_SCHEME, help='The protocol to communicate over') args = parser.parse_args() if not args.username: args.username = prompt('create username: '******'new password: '******'{args.scheme}://{args.host}:{args.port}' jwt_token = get_jwt_token(url, args.token, None, None) try: create_user_http(url, jwt_token, args.username, args.password, args.firstname, args.lastname) except ValueError: # Try deleting the token file and start again if os.path.exists(args.token): os.remove(args.token) jwt_token = get_jwt_token(url, args.token, None, None) create_user_http(url, jwt_token, args.username, args.password, args.firstname, args.lastname)
def main(): """Websocket client for pinging odin.""" parser = argparse.ArgumentParser(description='Create a job') parser.add_argument('job', help="The name of the job you are creating") parser.add_argument('--host', default=ODIN_URL, type=str) parser.add_argument('--port', default=ODIN_PORT) parser.add_argument('--token', help="File where JWT token can reside", default=os.path.expanduser("~/.odin.token")) parser.add_argument('--username', '-u', help="Username", default=getuser()) parser.add_argument('--password', '-p', help="Password") parser.add_argument('--scheme', choices={'http', 'https'}, default='https', help='Connection protocol, use `http` for REST.') args = parser.parse_args() url = f'{args.scheme}://{args.host}:{args.port}' jwt_token = get_jwt_token(url, args.token, args.username, args.password) try: create_job_http(url, jwt_token, args.job) except ValueError: if os.path.exists(args.token): os.remove(args.token) jwt_token = get_jwt_token(url, args.token, args.username, args.password) create_job_http(url, jwt_token, args.job)
def main(): """A websocket client to request a job cleanup.""" parser = argparse.ArgumentParser(description="Websocket-based job clean-up") parser.add_argument('work', help='Job') parser.add_argument('--host', default=ODIN_URL, type=str) parser.add_argument('--port', default=ODIN_PORT) parser.add_argument('--token', help="File where JWT token can reside", default=os.path.expanduser("~/.odin.token")) parser.add_argument('--username', '-u', help="Username", default=getuser()) parser.add_argument('--password', '-p', help="Password") parser.add_argument( '--scheme', choices={'wss', 'ws', 'http', 'https'}, default=ODIN_SCHEME, help='Connection protocol, use `http` for REST, use `wss` for remote connections and `ws` for localhost', ) parser.add_argument('--db', '-d', action='store_true', help="Also remove from the job db") parser.add_argument('--fs', '-f', action='store_true', help="Also remove from the filesystem") args = parser.parse_args() url = f'{args.scheme}://{args.host}:{args.port}' if args.scheme.startswith('ws'): asyncio.get_event_loop().run_until_complete(request_cleanup(url, args.work, args.db, args.fs)) else: jwt_token = get_jwt_token(url, args.token, args.username, args.password) try: request_cleanup_http(url, jwt_token, args.work, args.db, args.fs) except ValueError: # Try deleting the token file and start again if os.path.exists(args.token): os.remove(args.token) jwt_token = get_jwt_token(url, args.token, args.username, args.password) request_cleanup_http(url, jwt_token, args.work, args.db, args.fs)
def main(): """This should have auth around it.""" parser = argparse.ArgumentParser(description="Upload a file to odin") parser.add_argument('job', help='The Job to push the file to') parser.add_argument('file', help='The data to upload') parser.add_argument( '--file_name', help='The name for the file on remote, defaults to the local file name' ) parser.add_argument('--host', default=ODIN_URL, type=str, help="The odin http host") parser.add_argument('--port', default=ODIN_PORT, help="The odin http port") parser.add_argument('--token', help="File where JWT token can reside", default=os.path.expanduser("~/.odin.token")) parser.add_argument( '--create', '-c', action='store_true', help="If this is given, we will attempt to create a job with this name" ) parser.add_argument('--username', '-u', help="Username", default=getuser()) parser.add_argument('--password', '-p', help="Password") parser.add_argument( '--scheme', choices={'https', 'http'}, default=ODIN_SCHEME, help="Use https for remote connections and http for local", ) args = parser.parse_args() url = f'{args.scheme}://{args.host}:{args.port}' file_name = args.file_name if args.file_name is not None else args.file with open(args.file) as rf: file_contents = rf.read() jwt_token = get_jwt_token(url, args.token, args.username, args.password) try: push_file_maybe_create_job(url, jwt_token, args.job, file_name, file_contents, args.create) except ValueError: # Try deleting the token file and start again if os.path.exists(args.token): os.remove(args.token) jwt_token = get_jwt_token(url, args.token, args.username, args.password) push_file_maybe_create_job(url, jwt_token, args.job, file_name, file_contents, args.create)
def main(): """Use `asyncio` to connect to a websocket and request a pipeline, wait. """ signal.signal(signal.SIGINT, lambda *args, **kwargs: exit(0)) parser = argparse.ArgumentParser( description='HTTP or Websocket-based Pipeline scheduler') parser.add_argument('work', help='Job') parser.add_argument('--host', default=ODIN_URL, type=str) parser.add_argument('--port', default=ODIN_PORT) parser.add_argument('--token', help="File where JWT token can reside", default=os.path.expanduser("~/.odin.token")) parser.add_argument('--username', '-u', help="Username", default=getuser()) parser.add_argument('--password', '-p', help="Password") parser.add_argument( '--scheme', choices={'http', 'wss', 'ws', 'https'}, default=ODIN_SCHEME, help= 'Connection protocol, use `http` for REST, use `wss` for remote connections and `ws` for localhost', ) args, overrides = parser.parse_known_args() context = parse_and_merge_overrides({}, overrides, pre='x') url = f'{args.scheme}://{args.host}:{args.port}' if args.scheme.startswith('ws'): if context: LOGGER.warning("Context is ignored by web-socket tier") asyncio.get_event_loop().run_until_complete( schedule_pipeline(url, args.work)) else: jwt_token = get_jwt_token(url, args.token, args.username, args.password) try: schedule_pipeline_http(url, jwt_token, args.work, context) except ValueError: # Try deleting the token file and start again if os.path.exists(args.token): os.remove(args.token) jwt_token = get_jwt_token(url, args.token, args.username, args.password) schedule_pipeline_http(url, jwt_token, args.work, context)
def authenticate_user(url: str, token_path: str, username: str, password: str) -> None: """Authenticate a user over HTTP :param url: the base URL :param token_path: The file location of the JWT token :param username: The user ID :param password: The password """ if os.path.exists(token_path): os.remove(token_path) jwt_token = get_jwt_token(url, token_path, username, password) LOGGER.info(jwt_token)