This additional secrets-tool command can be used to run the database bootsrapping script (`script/database_setup.py`) inside an ATAT docker container against the Azure database. It sources the necessary keys from Key Vault.
55 lines
1.3 KiB
Python
Executable File
55 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# CLI
|
|
import click
|
|
|
|
import config
|
|
import logging
|
|
|
|
from commands.secrets import secrets
|
|
from commands.terraform import terraform
|
|
from commands.database import database
|
|
|
|
config.setup_logging()
|
|
logger = logging.getLogger(__name__)
|
|
|
|
PROCESS='terraform'
|
|
|
|
# Define core command group
|
|
@click.group()
|
|
def cli():
|
|
pass
|
|
|
|
# Add additional command groups
|
|
cli.add_command(secrets)
|
|
cli.add_command(terraform)
|
|
cli.add_command(database)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
cli()
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
'''
|
|
try:
|
|
keyvault = secrets(vault_url="https://cloudzero-dev-keyvault.vault.azure.net/")
|
|
keyvault.set_secret('dbuser','foo')
|
|
#print(keyvault.get_secret('db-user').value)
|
|
|
|
# Set env variables for TF
|
|
for secret in keyvault.list_secrets():
|
|
name = 'TF_VAR_' + secret
|
|
val = keyvault.get_secret(secret)
|
|
#print(val)
|
|
os.environ[name] = val
|
|
env = os.environ.copy()
|
|
command = "{} {}".format(PROCESS, sys.argv[1])
|
|
with subprocess.Popen(command, env=env, stdout=subprocess.PIPE, shell=True) as proc:
|
|
for line in proc.stdout:
|
|
logging.info(line.decode("utf-8") )
|
|
|
|
except Exception as e:
|
|
print(e, traceback.print_stack)
|
|
'''
|