init
This commit is contained in:
parent
4affe05863
commit
aad4500107
2
setup.py
2
setup.py
|
|
@ -8,7 +8,7 @@ setup(
|
||||||
install_requires=[],
|
install_requires=[],
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'tenant=tenantgenerator.main:main.py',
|
'tenant=tenant.main:main',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -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}'.")
|
||||||
|
|
@ -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.")
|
||||||
|
|
@ -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}.")
|
||||||
|
|
@ -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,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)
|
||||||
Loading…
Reference in New Issue