diff --git a/stackspin/__main__.py b/stackspin/__main__.py index 14baaec7ca0a922c7e586b63502cd739bbf461a2..272623b2ae879a930e6e03c0f86db756750ba2d5 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 fd9f8fdd539a8354c469126569c97906211e038f..482d757fc9a9c4dfc4d77f79154bb9252453cbe1 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): """