This commit is contained in:
Karsten Gorskowski 2023-11-26 15:19:34 +01:00
parent 4affe05863
commit aad4500107
9 changed files with 103 additions and 1 deletions

View File

@ -8,7 +8,7 @@ setup(
install_requires=[],
entry_points={
'console_scripts': [
'tenant=tenantgenerator.main:main.py',
'tenant=tenant.main:main',
],
},
)

0
tenant/__init__.py Normal file
View File

View File

View File

@ -0,0 +1,19 @@
# tenant/commands/certrenew.py
from tenant.utils.common import get_secure_password
def add_subparser(subparsers):
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("--force", action="store_true", help="Force certificate renewal")
def execute(args):
tenant_name = args.tenant_name
force_renewal = args.force
# Use the shared function
# shared_function()
# Your logic for certificate renewal
# ...
print(f"Renewing certificates for tenant '{tenant_name}'.")

32
tenant/commands/init.py Normal file
View File

@ -0,0 +1,32 @@
# tenant/commands/init.py
import os
from tenant.utils.common import get_secure_password
def add_subparser(subparsers):
init_parser = subparsers.add_parser("init", help="Initialize a new tenant")
init_parser.add_argument("tenant_name", help="Name of the tenant")
init_parser.add_argument("--target", default=".", help="Target directory (default: current directory)")
def execute(args):
tenant_name = args.tenant_name
target_directory = args.target
tenant_directory = os.path.join(target_directory, "tenants", tenant_name)
# Check if the tenant directory already exists
if os.path.exists(tenant_directory):
print(f"Error: Tenant directory '{tenant_directory}' already exists.")
return
# Prompt the user for the GitSync password securely
git_sync_password = get_secure_password(prompt="Please insert known password for GitSync: ")
terraform_directory = os.path.join(tenant_directory, "terraform")
kubernetes_directory = os.path.join(tenant_directory, "kubernetes")
certificates_directory = os.path.join(tenant_directory, "certificates")
os.makedirs(terraform_directory)
os.makedirs(kubernetes_directory)
os.makedirs(certificates_directory)
print(f"Tenant '{tenant_name}' initialized in '{tenant_directory}' with GitSync password provided.")

19
tenant/commands/resize.py Normal file
View File

@ -0,0 +1,19 @@
# tenant/commands/resize.py
from tenant.utils.common import get_secure_password
def add_subparser(subparsers):
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("--new-size", type=int, help="New size for resources")
def execute(args):
tenant_name = args.tenant_name
new_size = args.new_size
# Use the shared function
# shared_function()
# Your logic for resizing resources
# ...
print(f"Resizing resources for tenant '{tenant_name}' to size {new_size}.")

26
tenant/main.py Normal file
View File

@ -0,0 +1,26 @@
# TenantGenerator/main.py
import argparse
from tenant.commands import init, certrenew, resize
def main():
parser = argparse.ArgumentParser(description="TenantGenerator - Generate tenant folder structure")
subparsers = parser.add_subparsers(dest="command", help="Available commands")
# Add subparsers for each command
init.add_subparser(subparsers)
certrenew.add_subparser(subparsers)
resize.add_subparser(subparsers)
args = parser.parse_args()
if args.command == "init":
init.execute(args)
elif args.command == "certrenew":
certrenew.execute(args)
elif args.command == "resize":
resize.execute(args)
else:
print("Unknown command")
if __name__ == "__main__":
main()

0
tenant/utils/__init__.py Normal file
View File

6
tenant/utils/common.py Normal file
View File

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