diff --git a/grid5000/cli.py b/grid5000/cli.py index 2c7edda4a2294bd42293c8e945513cf903538821..f553e4d55377ad2f104a9825386e9d9c2e5ce529 100644 --- a/grid5000/cli.py +++ b/grid5000/cli.py @@ -38,3 +38,25 @@ def main(): gk = Grid5000.from_yaml(CONF_PATH) motd = MOTD % (CONF_PATH, gk.username) IPython.embed(header=motd) + + +def auth(): + import argparse + from getpass import getpass + + parser = argparse.ArgumentParser(description=f"Check or create {CONF_PATH}") + parser.add_argument("--user", "-u", help="Username on Grid'5000", required=True) + args = parser.parse_args() + + path = pathlib.Path(CONF_PATH) + if path.exists(): + print(f"{CONF_PATH} file already exists, not overwriting") + return + user = args.user + + password = getpass("Grid'5000 password: ") + path.write_text("\n".join([ + f"username: {user}", + f"password: {password}" + ])) + print(f"{CONF_PATH} created successfully") diff --git a/setup.cfg b/setup.cfg index de5c8349041db92cdc9b8f4a6b1ef513f9e30973..b31e401daaecc2e30e3ad13abb35331cde0e144a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,3 +33,4 @@ exclude = [options.entry_points] console_scripts = grid5000 = grid5000.cli:main + grid5000-auth = grid5000.cli:auth \ No newline at end of file