formatting

This commit is contained in:
Karsten Gorskowski 2023-11-26 22:46:35 +01:00
parent 437caa437e
commit 9d867dd420
5 changed files with 49 additions and 10 deletions

View File

@ -1,10 +1,16 @@
# tenant/commands/certrenew.py # tenant/commands/certrenew.py
from tenant.utils.common import get_secure_password from tenant.utils.common import get_secure_password
def add_subparser(subparsers): def add_subparser(subparsers):
certrenew_parser = subparsers.add_parser("certrenew", help="Renew certificates for a tenant") certrenew_parser = subparsers.add_parser(
"certrenew", help="Renew certificates for a tenant"
)
certrenew_parser.add_argument("tenant_name", help="Name of the tenant") certrenew_parser.add_argument("tenant_name", help="Name of the tenant")
certrenew_parser.add_argument("--force", action="store_true", help="Force certificate renewal") certrenew_parser.add_argument(
"--force", action="store_true", help="Force certificate renewal"
)
def execute(args): def execute(args):
tenant_name = args.tenant_name tenant_name = args.tenant_name

View File

@ -2,13 +2,31 @@
import os import os
from tenant.utils.common import get_secure_password from tenant.utils.common import get_secure_password
def add_subparser(subparsers): def add_subparser(subparsers):
init_parser = subparsers.add_parser("init", help="Initialize a new tenant") init_parser = subparsers.add_parser("init", help="Initialize a new tenant")
init_parser.add_argument("tenant_name", help="Name of the tenant") default_tenant_name = os.getenv("TENANT_NAME", None)
init_parser.add_argument("--target", default=".", help="Target directory (default: current directory)") init_parser.add_argument(
"tenant_name", help="Name of the tenant", default=default_tenant_name, nargs="?"
)
init_parser.add_argument(
"--target", default=".", help="Target directory (default: current directory)"
)
def execute(args): def execute(args):
tenant_name = args.tenant_name # If tenant_name is not provided and TENANT_NAME is not set, prompt the user
if args.tenant_name is None and os.getenv("TENANT_NAME") is None:
tenant_name = input("Please enter the tenant name: ")
# Ask the user to confirm the tenant name if the environment variable is set
if os.getenv("TENANT_NAME") and args.tenant_name is not None:
user_confirmation = input(
f"Use '{os.getenv('TENANT_NAME')}' as the tenant name? (yes/no): "
).lower()
if user_confirmation in ("yes", "y"):
tenant_name = os.getenv("TENANT_NAME")
target_directory = args.target target_directory = args.target
tenant_directory = os.path.join(target_directory, tenant_name) tenant_directory = os.path.join(target_directory, tenant_name)
@ -19,7 +37,9 @@ def execute(args):
return return
# Prompt the user for the GitSync password securely # Prompt the user for the GitSync password securely
git_sync_password = get_secure_password(prompt="Please insert known password for GitSync: ") git_sync_password = get_secure_password(
prompt="Please insert known password for GitSync: "
)
terraform_directory = os.path.join(tenant_directory, "terraform") terraform_directory = os.path.join(tenant_directory, "terraform")
kubernetes_directory = os.path.join(tenant_directory, "kubernetes") kubernetes_directory = os.path.join(tenant_directory, "kubernetes")
@ -42,5 +62,9 @@ def execute(args):
relative_path = os.path.relpath(source_path, target_tf_dir) relative_path = os.path.relpath(source_path, target_tf_dir)
os.symlink(relative_path, target_path) os.symlink(relative_path, target_path)
else: else:
print(f"Warning: Source file '{filename}' not found in '{source_tf_dir}'.") print(
print(f"Tenant '{tenant_name}' initialized in '{tenant_directory}' with GitSync password provided.") f"Warning: Source file '{filename}' not found in '{source_tf_dir}'."
)
print(
f"Tenant '{tenant_name}' initialized in '{tenant_directory}' with GitSync password provided."
)

View File

@ -1,11 +1,15 @@
# tenant/commands/resize.py # tenant/commands/resize.py
from tenant.utils.common import get_secure_password from tenant.utils.common import get_secure_password
def add_subparser(subparsers): def add_subparser(subparsers):
resize_parser = subparsers.add_parser("resize", help="Resize resources for a tenant") resize_parser = subparsers.add_parser(
"resize", help="Resize resources for a tenant"
)
resize_parser.add_argument("tenant_name", help="Name of the tenant") resize_parser.add_argument("tenant_name", help="Name of the tenant")
resize_parser.add_argument("--new-size", type=int, help="New size for resources") resize_parser.add_argument("--new-size", type=int, help="New size for resources")
def execute(args): def execute(args):
tenant_name = args.tenant_name tenant_name = args.tenant_name
new_size = args.new_size new_size = args.new_size

View File

@ -2,8 +2,11 @@
import argparse import argparse
from tenant.commands import init, certrenew, resize from tenant.commands import init, certrenew, resize
def main(): def main():
parser = argparse.ArgumentParser(description="TenantGenerator - Generate tenant folder structure") parser = argparse.ArgumentParser(
description="TenantGenerator - Generate tenant folder structure"
)
subparsers = parser.add_subparsers(dest="command", help="Available commands") subparsers = parser.add_subparsers(dest="command", help="Available commands")
# Add subparsers for each command # Add subparsers for each command
@ -22,5 +25,6 @@ def main():
else: else:
print("Unknown command") print("Unknown command")
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,6 +1,7 @@
# tenant/utils/common.py # tenant/utils/common.py
import getpass import getpass
def get_secure_password(prompt="Enter password: "): def get_secure_password(prompt="Enter password: "):
# Use getpass to securely input a password without displaying it # Use getpass to securely input a password without displaying it
return getpass.getpass(prompt=prompt) return getpass.getpass(prompt=prompt)