From 2d0dbb65c4a32acedcd93207c3fffaf70164d0e9 Mon Sep 17 00:00:00 2001 From: Maarten de Waard <maarten@greenhost.nl> Date: Thu, 13 Jan 2022 17:13:32 +0100 Subject: [PATCH] add "admin-credentials" subcommand for getting your login credentials after you set up Stackspin --- stackspin/__main__.py | 12 ++++++++++++ stackspin/cluster.py | 22 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/stackspin/__main__.py b/stackspin/__main__.py index 14baaec7c..272623b2a 100755 --- a/stackspin/__main__.py +++ b/stackspin/__main__.py @@ -208,6 +208,10 @@ def main(): # pylint: disable=too-many-statements,too-many-branches,too-many-lo 'secrets', help=("Show Stackspin cluster secrets")) secrets_parser.set_defaults(func=secrets) + admin_credentials_parser = subparsers.add_parser( + 'admin-credentials', + help=("Show Stackspin admin username and password")) + admin_credentials_parser.set_defaults(func=admin_credentials) args = parser.parse_args() loglevel = logging.DEBUG if args.verbose else logging.INFO @@ -254,6 +258,14 @@ def secrets(clus, args): clus.load_data() clus.dump_secrets() +def admin_credentials(clus, args): + """ + Dumps admin username and password and then exists + + :param cluster.Cluster clus: cluster to show information about + """ + clus.load_data() + clus.dump_admin_credentials() def create(clus, args): # pylint: disable=too-many-branches """ diff --git a/stackspin/cluster.py b/stackspin/cluster.py index fd9f8fdd5..482d757fc 100644 --- a/stackspin/cluster.py +++ b/stackspin/cluster.py @@ -230,7 +230,27 @@ KUBECONFIG={cluster_dir}/kube_config_cluster.yml app, app_secret, namespace) - print(f'{namespace}/{app}: {app_secret}={secret}') + print(f'{namespace}/{app}: {app_secret} = {secret}') + + def dump_admin_credentials(self): + """ + Shows admin credentials + """ + admin_email = self.get_password_from_kubernetes( + "stackspin-cluster-variables", + "admin_email", + "flux-system") + admin_password = self.get_password_from_kubernetes( + "stackspin-single-sign-on-variables", + "userbackend_admin_password", + "flux-system") + print("You can log into applications with the following credentials:\n") + print(f'Admin email address: {admin_email}') + print(f'Admin password: {admin_password}') + print("\nNote that if you manually changed the admin password, these" + " credentials will be outdated. You can always request a" + " password reset from the SSO login screen, using this admin" + " email address") def get_password_from_kubernetes(self, secret, key, namespace): """ -- GitLab