Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 9d4ae712 authored by SIMONIN Matthieu's avatar SIMONIN Matthieu
Browse files

cli_auth: extract method

parent 71f06757
No related branches found
No related tags found
No related merge requests found
Pipeline #448001 passed
...@@ -40,10 +40,19 @@ def main(): ...@@ -40,10 +40,19 @@ def main():
IPython.embed(header=motd) IPython.embed(header=motd)
def auth(): def auth(user: str):
import argparse
from getpass import getpass from getpass import getpass
path = pathlib.Path(CONF_PATH)
password = getpass("Grid'5000 password: ")
path.write_text("\n".join([f"username: {user}", f"password: {password}"]))
print(f"{CONF_PATH} created successfully")
def cli_auth():
import argparse
parser = argparse.ArgumentParser(description=f"Check or create {CONF_PATH}") parser = argparse.ArgumentParser(description=f"Check or create {CONF_PATH}")
parser.add_argument("--user", "-u", help="Username on Grid'5000", required=True) parser.add_argument("--user", "-u", help="Username on Grid'5000", required=True)
args = parser.parse_args() args = parser.parse_args()
...@@ -52,11 +61,4 @@ def auth(): ...@@ -52,11 +61,4 @@ def auth():
if path.exists(): if path.exists():
print(f"{CONF_PATH} file already exists, not overwriting") print(f"{CONF_PATH} file already exists, not overwriting")
return return
user = args.user auth(args.user)
password = getpass("Grid'5000 password: ")
path.write_text("\n".join([
f"username: {user}",
f"password: {password}"
]))
print(f"{CONF_PATH} created successfully")
...@@ -35,4 +35,4 @@ exclude = ...@@ -35,4 +35,4 @@ exclude =
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =
grid5000 = grid5000.cli:main grid5000 = grid5000.cli:main
grid5000-auth = grid5000.cli:auth grid5000-auth = grid5000.cli:cli_auth
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment