2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: AGPL-3.0
12 print("%s <path/to/config.yaml> <clusterid> add <username> <email> [pass]" % (sys.argv[0]))
13 print("%s <path/to/config.yaml> <clusterid> remove <username>" % (" " * len(sys.argv[0])))
14 print("%s <path/to/config.yaml> <clusterid> list" % (" " * len(sys.argv[0])))
24 if op == "remove" and len(sys.argv) < 5:
26 if op == "add" and len(sys.argv) < 6:
29 if op in ("add", "remove"):
32 if not os.path.exists(fn):
35 with open(fn, "r") as f:
36 conf = ruamel.yaml.round_trip_load(f)
41 conf["Clusters"] = conf.get("Clusters", {})
42 conf["Clusters"][cl] = conf["Clusters"].get(cl, {})
43 conf["Clusters"][cl]["Login"] = conf["Clusters"][cl].get("Login", {})
44 conf["Clusters"][cl]["Login"]["Test"] = conf["Clusters"][cl]["Login"].get("Test", {})
45 conf["Clusters"][cl]["Login"]["Test"]["Users"] = conf["Clusters"][cl]["Login"]["Test"].get("Users", {})
47 users_obj = conf["Clusters"][cl]["Login"]["Test"]["Users"]
51 if len(sys.argv) == 7:
54 p = getpass.getpass("Password for %s: " % user)
60 print("Added %s" % user)
63 print("Removed %s" % user)
65 print(ruamel.yaml.round_trip_dump(users_obj))
67 print("Operations are 'add', 'remove' and 'list'")
69 with open(fn, "w") as f:
70 f.write(ruamel.yaml.round_trip_dump(conf))