33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
# 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.")
|