Generate jwt

This commit is contained in:
David Boreham 2023-07-23 22:24:12 -06:00
parent ed0cc4bb37
commit b14488d040
2 changed files with 19 additions and 5 deletions

View File

@ -13,6 +13,8 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http:#www.gnu.org/licenses/>. # along with this program. If not, see <http:#www.gnu.org/licenses/>.
from secrets import token_hex
def init(ctx): def init(ctx):
return None return None
@ -22,4 +24,8 @@ def setup(ctx):
def create(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)

View File

@ -14,6 +14,7 @@
# along with this program. If not, see <http:#www.gnu.org/licenses/>. # along with this program. If not, see <http:#www.gnu.org/licenses/>.
import click import click
from dataclasses import dataclass
from importlib import util from importlib import util
import os import os
from pathlib import Path from pathlib import Path
@ -21,6 +22,11 @@ from shutil import copyfile, copytree
import sys import sys
from app.util import get_stack_file_path, get_parsed_deployment_spec, get_parsed_stack_config, global_options, get_yaml 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(): def _make_default_deployment_dir():
return "deployment-001" return "deployment-001"
@ -112,15 +118,15 @@ def call_stack_deploy_setup(stack):
# TODO: fold this with function above # 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 # Link with the python file in the stack
# Call a function in it # Call a function in it
# If no function found, return None # 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) spec = util.spec_from_file_location("commands", python_file_path)
imported_stack = util.module_from_spec(spec) imported_stack = util.module_from_spec(spec)
spec.loader.exec_module(imported_stack) 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 # 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 the same config dir appears in multiple pods, it may already have been copied
if not os.path.exists(destination_config_dir): if not os.path.exists(destination_config_dir):
copytree(source_config_dir, 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() @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): def setup(ctx, node_moniker, key_name, initialize_network, join_network, create_network):
stack = global_options(ctx).stack stack = global_options(ctx).stack
call_stack_deploy_setup(stack) call_stack_deploy_setup(stack)