From b14488d04073e280760d45f21781d47136073448 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Sun, 23 Jul 2023 22:24:12 -0600 Subject: [PATCH] Generate jwt --- app/data/stacks/mainnet-eth/deploy/commands.py | 8 +++++++- app/deployment_create.py | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/data/stacks/mainnet-eth/deploy/commands.py b/app/data/stacks/mainnet-eth/deploy/commands.py index 28964073..194c970d 100644 --- a/app/data/stacks/mainnet-eth/deploy/commands.py +++ b/app/data/stacks/mainnet-eth/deploy/commands.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from secrets import token_hex + def init(ctx): return None @@ -22,4 +24,8 @@ def setup(ctx): def create(ctx): - print("Yay it worked") + # Generate the JWT secret and save to its config file + secret = token_hex(16) + jwt_file_path = ctx.deployment_dir.joinpath("data", "mainnet_eth_config_data", "jwtsecret") + with open(jwt_file_path, 'w+') as jwt_file: + jwt_file.write(secret) diff --git a/app/deployment_create.py b/app/deployment_create.py index 6d41e8d6..652bbdba 100644 --- a/app/deployment_create.py +++ b/app/deployment_create.py @@ -14,6 +14,7 @@ # along with this program. If not, see . import click +from dataclasses import dataclass from importlib import util import os from pathlib import Path @@ -21,6 +22,11 @@ from shutil import copyfile, copytree import sys from app.util import get_stack_file_path, get_parsed_deployment_spec, get_parsed_stack_config, global_options, get_yaml +@dataclass +class DeploymentContext: + stack: str + deployment_dir: Path + def _make_default_deployment_dir(): return "deployment-001" @@ -112,15 +118,15 @@ def call_stack_deploy_setup(stack): # TODO: fold this with function above -def call_stack_deploy_create(stack): +def call_stack_deploy_create(deployment_context): # Link with the python file in the stack # Call a function in it # If no function found, return None - python_file_path = get_stack_file_path(stack).parent.joinpath("deploy", "commands.py") + python_file_path = get_stack_file_path(deployment_context.stack).parent.joinpath("deploy", "commands.py") spec = util.spec_from_file_location("commands", python_file_path) imported_stack = util.module_from_spec(spec) spec.loader.exec_module(imported_stack) - return imported_stack.create(None) + return imported_stack.create(deployment_context) # Inspect the pod yaml to find config files referenced in subdirectories @@ -210,6 +216,9 @@ def create(ctx, spec_file, deployment_dir): # If the same config dir appears in multiple pods, it may already have been copied if not os.path.exists(destination_config_dir): copytree(source_config_dir, destination_config_dir) + # Delegate to the stack's Python code + deployment_context = DeploymentContext(stack_name, Path(deployment_dir)) + call_stack_deploy_create(deployment_context) @click.command() @@ -222,4 +231,3 @@ def create(ctx, spec_file, deployment_dir): def setup(ctx, node_moniker, key_name, initialize_network, join_network, create_network): stack = global_options(ctx).stack call_stack_deploy_setup(stack) -