mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-12 05:58:18 +02:00
added logic to bypass prompts if debug is enabled
This commit is contained in:
parent
a7bd6709fa
commit
d5e9e45a2f
1 changed files with 112 additions and 117 deletions
|
@ -237,13 +237,18 @@ class Command(BaseCommand):
|
||||||
if not proceed_execution:
|
if not proceed_execution:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
self.execute_command(command_string)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def execute_command(self, command_string:str):
|
||||||
|
"""Executes the given command string"""
|
||||||
|
|
||||||
logger.info(f"""{TerminalColors.OKCYAN}
|
logger.info(f"""{TerminalColors.OKCYAN}
|
||||||
==== EXECUTING... ====
|
==== EXECUTING... ====
|
||||||
{TerminalColors.ENDC}""")
|
{TerminalColors.ENDC}""")
|
||||||
os.system(f"{command_string}")
|
os.system(f"{command_string}")
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def run_load_transition_domain_script(self,
|
def run_load_transition_domain_script(self,
|
||||||
file_location: str,
|
file_location: str,
|
||||||
domain_contacts_filename: str,
|
domain_contacts_filename: str,
|
||||||
|
@ -252,6 +257,7 @@ class Command(BaseCommand):
|
||||||
sep: str,
|
sep: str,
|
||||||
reset_table: bool,
|
reset_table: bool,
|
||||||
debug_on: bool,
|
debug_on: bool,
|
||||||
|
prompts_enabled: bool,
|
||||||
debug_max_entries_to_parse: int):
|
debug_max_entries_to_parse: int):
|
||||||
"""Runs the load_transition_domain script"""
|
"""Runs the load_transition_domain script"""
|
||||||
# Create the command string
|
# Create the command string
|
||||||
|
@ -269,33 +275,51 @@ class Command(BaseCommand):
|
||||||
command_string += f"--limitParse {debug_max_entries_to_parse} "
|
command_string += f"--limitParse {debug_max_entries_to_parse} "
|
||||||
|
|
||||||
# Execute the command string
|
# Execute the command string
|
||||||
self.prompt_for_execution(command_string, "Running load_transition_domain script")
|
if prompts_enabled:
|
||||||
|
self.prompt_for_execution(command_string, "Running load_transition_domain script")
|
||||||
|
return
|
||||||
|
self.execute_command(command_string)
|
||||||
|
|
||||||
|
|
||||||
def run_transfer_script(self, debug_on:bool):
|
def run_transfer_script(self, debug_on:bool, prompts_enabled: bool):
|
||||||
"""Runs the transfer_transition_domains_to_domains script"""
|
"""Runs the transfer_transition_domains_to_domains script"""
|
||||||
# Create the command string
|
# Create the command string
|
||||||
command_string = "./manage.py transfer_transition_domains_to_domains "
|
command_string = "./manage.py transfer_transition_domains_to_domains "
|
||||||
if debug_on:
|
if debug_on:
|
||||||
command_string += "--debug "
|
command_string += "--debug "
|
||||||
# Execute the command string
|
# Execute the command string
|
||||||
self.prompt_for_execution(command_string, "Running transfer_transition_domains_to_domains script")
|
if prompts_enabled:
|
||||||
|
self.prompt_for_execution(command_string, "Running transfer_transition_domains_to_domains script")
|
||||||
|
return
|
||||||
|
self.execute_command(command_string)
|
||||||
|
|
||||||
|
|
||||||
def run_send_invites_script(self):
|
def run_send_invites_script(self, debug_on: bool, prompts_enabled: bool):
|
||||||
"""Runs the send_domain_invitations script"""
|
"""Runs the send_domain_invitations script"""
|
||||||
# Create the command string...
|
# Create the command string...
|
||||||
command_string = "./manage.py send_domain_invitations -s"
|
command_string = "./manage.py send_domain_invitations -s"
|
||||||
# Execute the command string
|
# Execute the command string
|
||||||
self.prompt_for_execution(command_string, "Running send_domain_invitations script")
|
if prompts_enabled:
|
||||||
|
self.prompt_for_execution(command_string, "Running send_domain_invitations script")
|
||||||
|
return
|
||||||
|
self.execute_command(command_string)
|
||||||
|
|
||||||
|
|
||||||
def run_migration_scripts(self,
|
def run_migration_scripts(self,
|
||||||
|
prompts_enabled: bool,
|
||||||
options):
|
options):
|
||||||
"""Runs the following migration scripts (in order):
|
"""Runs the following migration scripts (in order):
|
||||||
1 - imports for trans domains
|
1 - imports for trans domains
|
||||||
2 - transfer to domain & domain invitation"""
|
2 - transfer to domain & domain invitation"""
|
||||||
|
|
||||||
|
# Get arguments
|
||||||
|
sep = options.get("sep")
|
||||||
|
reset_table = options.get("resetTable")
|
||||||
|
debug_on = options.get("debug")
|
||||||
|
debug_max_entries_to_parse = int(
|
||||||
|
options.get("limitParse")
|
||||||
|
)
|
||||||
|
|
||||||
# Grab filepath information from the arguments
|
# Grab filepath information from the arguments
|
||||||
file_location = options.get("loaderDirectory")+"/"
|
file_location = options.get("loaderDirectory")+"/"
|
||||||
filenames = options.get("loaderFilenames").split()
|
filenames = options.get("loaderFilenames").split()
|
||||||
|
@ -311,56 +335,48 @@ class Command(BaseCommand):
|
||||||
============= TERMINATING =============
|
============= TERMINATING =============
|
||||||
{TerminalColors.ENDC}
|
{TerminalColors.ENDC}
|
||||||
""")
|
""")
|
||||||
return
|
sys.exit()
|
||||||
domain_contacts_filename = filenames[0]
|
domain_contacts_filename = filenames[0]
|
||||||
contacts_filename = filenames[1]
|
contacts_filename = filenames[1]
|
||||||
domain_statuses_filename = filenames[2]
|
domain_statuses_filename = filenames[2]
|
||||||
|
|
||||||
# Allow the user to inspect the filepath
|
if prompts_enabled:
|
||||||
# data given in the arguments, and prompt
|
# Allow the user to inspect the filepath
|
||||||
# the user to verify this info before proceeding
|
# data given in the arguments, and prompt
|
||||||
files_are_correct = TerminalHelper.query_yes_no(
|
# the user to verify this info before proceeding
|
||||||
f"""
|
files_are_correct = TerminalHelper.query_yes_no(
|
||||||
{TerminalColors.OKCYAN}
|
f"""
|
||||||
*** IMPORTANT: VERIFY THE FOLLOWING ***
|
{TerminalColors.OKCYAN}
|
||||||
|
*** IMPORTANT: VERIFY THE FOLLOWING ***
|
||||||
|
|
||||||
The migration scripts are looking in directory....
|
The migration scripts are looking in directory....
|
||||||
{file_location}
|
{file_location}
|
||||||
|
|
||||||
....for the following files:
|
....for the following files:
|
||||||
- domain contacts: {domain_contacts_filename}
|
- domain contacts: {domain_contacts_filename}
|
||||||
- contacts: {contacts_filename}
|
- contacts: {contacts_filename}
|
||||||
- domain statuses: {domain_statuses_filename}
|
- domain statuses: {domain_statuses_filename}
|
||||||
|
|
||||||
{TerminalColors.FAIL}
|
{TerminalColors.FAIL}
|
||||||
Does this look correct?{TerminalColors.ENDC}"""
|
Does this look correct?{TerminalColors.ENDC}"""
|
||||||
)
|
)
|
||||||
|
|
||||||
# If the user rejected the filepath information
|
# If the user rejected the filepath information
|
||||||
# as incorrect, prompt the user to provide
|
# as incorrect, prompt the user to provide
|
||||||
# correct file inputs in their original command
|
# correct file inputs in their original command
|
||||||
# prompt and exit this subroutine
|
# prompt and exit this subroutine
|
||||||
if not files_are_correct:
|
if not files_are_correct:
|
||||||
logger.info(f"""
|
logger.info(f"""
|
||||||
{TerminalColors.YELLOW}
|
{TerminalColors.YELLOW}
|
||||||
PLEASE Re-Run the script with the correct file location and filenames:
|
PLEASE Re-Run the script with the correct file location and filenames:
|
||||||
|
|
||||||
EXAMPLE:
|
EXAMPLE:
|
||||||
docker compose run -T app ./manage.py test_domain_migration --runLoaders --loaderDirectory /app/tmp --loaderFilenames escrow_domain_contacts.daily.gov.GOV.txt escrow_contacts.daily.gov.GOV.txt escrow_domain_statuses.daily.gov.GOV.txt
|
docker compose run -T app ./manage.py test_domain_migration --runLoaders --loaderDirectory /app/tmp --loaderFilenames escrow_domain_contacts.daily.gov.GOV.txt escrow_contacts.daily.gov.GOV.txt escrow_domain_statuses.daily.gov.GOV.txt
|
||||||
|
|
||||||
""")
|
""")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Proceed executing the migration scripts...
|
# Proceed executing the migration scripts
|
||||||
# ...First, Get all the arguments
|
|
||||||
sep = options.get("sep")
|
|
||||||
reset_table = options.get("resetTable")
|
|
||||||
debug_on = options.get("debug")
|
|
||||||
debug_max_entries_to_parse = int(
|
|
||||||
options.get("limitParse")
|
|
||||||
)
|
|
||||||
|
|
||||||
#...Second, Run the migration scripts in order
|
|
||||||
self.run_load_transition_domain_script(file_location,
|
self.run_load_transition_domain_script(file_location,
|
||||||
domain_contacts_filename,
|
domain_contacts_filename,
|
||||||
contacts_filename,
|
contacts_filename,
|
||||||
|
@ -368,8 +384,9 @@ class Command(BaseCommand):
|
||||||
sep,
|
sep,
|
||||||
reset_table,
|
reset_table,
|
||||||
debug_on,
|
debug_on,
|
||||||
|
prompts_enabled,
|
||||||
debug_max_entries_to_parse)
|
debug_max_entries_to_parse)
|
||||||
self.run_transfer_script(debug_on)
|
self.run_transfer_script(debug_on, prompts_enabled)
|
||||||
|
|
||||||
|
|
||||||
def simulate_user_logins(self, debug_on):
|
def simulate_user_logins(self, debug_on):
|
||||||
|
@ -380,52 +397,27 @@ class Command(BaseCommand):
|
||||||
f"{TerminalColors.OKCYAN}"
|
f"{TerminalColors.OKCYAN}"
|
||||||
f"================== SIMULATING LOGINS =================="
|
f"================== SIMULATING LOGINS =================="
|
||||||
f"{TerminalColors.ENDC}")
|
f"{TerminalColors.ENDC}")
|
||||||
for invite in DomainInvitation.objects.all(): #TODO: limit to our stuff
|
|
||||||
#DEBUG:
|
|
||||||
TerminalHelper.print_conditional(debug_on,
|
|
||||||
f"{TerminalColors.OKCYAN}"
|
|
||||||
f"Processing invite: {invite}"
|
|
||||||
f"{TerminalColors.ENDC}")
|
|
||||||
# get a user with this email address
|
|
||||||
user, user_created = User.objects.get_or_create(email=invite.email, username=invite.email)
|
|
||||||
#DEBUG:
|
|
||||||
TerminalHelper.print_conditional(user_created,
|
|
||||||
f"""{TerminalColors.OKCYAN}No user found (creating temporary user object){TerminalColors.ENDC}""")
|
|
||||||
TerminalHelper.print_conditional(debug_on,
|
|
||||||
f"""{TerminalColors.OKCYAN}Executing first-time login for user: {user}{TerminalColors.ENDC}""")
|
|
||||||
user.first_login()
|
|
||||||
if user_created:
|
|
||||||
logger.info(f"""{TerminalColors.YELLOW}(Deleting temporary user object){TerminalColors.ENDC}""")
|
|
||||||
user.delete()
|
|
||||||
|
|
||||||
# get a user with this email address
|
|
||||||
# user_exists = User.objects.filter(email=invite.email).exists()
|
|
||||||
# if user_exists:
|
|
||||||
# user = User.objects.get(email=invite.email)
|
|
||||||
# TerminalHelper.print_conditional(debug_on,
|
|
||||||
# f"""{TerminalColors.OKCYAN}Logging in user: {user}{TerminalColors.ENDC}""")
|
|
||||||
# user.first_login()
|
|
||||||
# else:
|
|
||||||
# logger.info(f"""{TerminalColors.YELLOW}No user found -- creating temp user object...{TerminalColors.ENDC}""")
|
|
||||||
# user = User(email=invite.email)
|
|
||||||
# user.save()
|
|
||||||
# user.first_login()
|
|
||||||
# logger.info(f"""{TerminalColors.YELLOW}(Deleting temporary user object){TerminalColors.ENDC}""")
|
|
||||||
# user.delete()
|
|
||||||
|
|
||||||
# for invite in DomainInvitation.objects.all():
|
|
||||||
|
# for invite in DomainInvitation.objects.all(): #TODO: limit to our stuff
|
||||||
# #DEBUG:
|
# #DEBUG:
|
||||||
# TerminalHelper.print_debug(debug_on,f"""{TerminalColors.OKCYAN}Processing invite: {invite}{TerminalColors.ENDC}""")
|
# TerminalHelper.print_conditional(debug_on,
|
||||||
# # get a user with this email address
|
# f"{TerminalColors.OKCYAN}"
|
||||||
# User = get_user_model()
|
# f"Processing invite: {invite}"
|
||||||
# try:
|
# f"{TerminalColors.ENDC}")
|
||||||
# user = User.objects.get(email=invite.email)
|
# # get a user with this email address
|
||||||
# #DEBUG:
|
# user, user_created = User.objects.get_or_create(email=invite.email, username=invite.email)
|
||||||
# TerminalHelper.print_debug(debug_on,f"""{TerminalColors.OKCYAN}Logging in user: {user}{TerminalColors.ENDC}""")
|
# #DEBUG:
|
||||||
# Client.force_login(user)
|
# TerminalHelper.print_conditional(user_created,
|
||||||
# except User.DoesNotExist:
|
# f"""{TerminalColors.OKCYAN}No user found (creating temporary user object){TerminalColors.ENDC}""")
|
||||||
# #TODO: how should we handle this?
|
# TerminalHelper.print_conditional(debug_on,
|
||||||
# logger.warn(f"""{TerminalColors.FAIL}No user found {invite.email}{TerminalColors.ENDC}""")
|
# f"""{TerminalColors.OKCYAN}Executing first-time login for user: {user}{TerminalColors.ENDC}""")
|
||||||
|
# user.first_login()
|
||||||
|
# if user_created:
|
||||||
|
# logger.info(f"""{TerminalColors.YELLOW}(Deleting temporary user object){TerminalColors.ENDC}""")
|
||||||
|
# user.delete()
|
||||||
|
|
||||||
|
|
||||||
def handle(
|
def handle(
|
||||||
self,
|
self,
|
||||||
|
@ -449,7 +441,8 @@ class Command(BaseCommand):
|
||||||
# the terminal so the user knows what is
|
# the terminal so the user knows what is
|
||||||
# enabled.
|
# enabled.
|
||||||
debug_on = options.get("debug")
|
debug_on = options.get("debug")
|
||||||
run_loaders_on = options.get("runLoaders")
|
prompts_enabled = debug_on #TODO: add as argument?
|
||||||
|
run_loaders_enabled = options.get("runLoaders")
|
||||||
simulate_user_login_enabled = options.get("triggerLogins")
|
simulate_user_login_enabled = options.get("triggerLogins")
|
||||||
TerminalHelper.print_conditional(
|
TerminalHelper.print_conditional(
|
||||||
debug_on,
|
debug_on,
|
||||||
|
@ -460,7 +453,7 @@ class Command(BaseCommand):
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
TerminalHelper.print_conditional(
|
TerminalHelper.print_conditional(
|
||||||
run_loaders_on,
|
run_loaders_enabled,
|
||||||
f"""{TerminalColors.OKCYAN}
|
f"""{TerminalColors.OKCYAN}
|
||||||
----------RUNNING LOADERS ON----------
|
----------RUNNING LOADERS ON----------
|
||||||
All migration scripts will be run before
|
All migration scripts will be run before
|
||||||
|
@ -469,7 +462,7 @@ class Command(BaseCommand):
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
TerminalHelper.print_conditional(
|
TerminalHelper.print_conditional(
|
||||||
run_loaders_on,
|
run_loaders_enabled,
|
||||||
f"""{TerminalColors.OKCYAN}
|
f"""{TerminalColors.OKCYAN}
|
||||||
----------TRIGGER LOGINS ON----------
|
----------TRIGGER LOGINS ON----------
|
||||||
Will be simulating user logins
|
Will be simulating user logins
|
||||||
|
@ -489,8 +482,8 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
# STEP 1 -- RUN LOADERS
|
# STEP 1 -- RUN LOADERS
|
||||||
# Run migration scripts if specified by user
|
# Run migration scripts if specified by user
|
||||||
if run_loaders_on:
|
if run_loaders_enabled:
|
||||||
self.run_migration_scripts(options)
|
self.run_migration_scripts(options, prompts_enabled)
|
||||||
prompt_continuation_of_analysis = True
|
prompt_continuation_of_analysis = True
|
||||||
|
|
||||||
# STEP 2 -- SIMULATE LOGINS
|
# STEP 2 -- SIMULATE LOGINS
|
||||||
|
@ -503,32 +496,34 @@ class Command(BaseCommand):
|
||||||
# automatically execute this as the final step
|
# automatically execute this as the final step
|
||||||
# to ensure Domain Information objects get added
|
# to ensure Domain Information objects get added
|
||||||
# to the database.)
|
# to the database.)
|
||||||
if run_loaders_on:
|
if run_loaders_enabled:
|
||||||
simulate_user_login_enabled = TerminalHelper.query_yes_no(
|
if prompts_enabled:
|
||||||
f"""{TerminalColors.FAIL}
|
simulate_user_login_enabled = TerminalHelper.query_yes_no(
|
||||||
Proceed with simulating user logins?
|
f"""{TerminalColors.FAIL}
|
||||||
{TerminalColors.ENDC}"""
|
Proceed with simulating user logins?
|
||||||
)
|
{TerminalColors.ENDC}"""
|
||||||
if simulate_user_login_enabled:
|
)
|
||||||
|
if not simulate_user_login_enabled:
|
||||||
|
return
|
||||||
self.simulate_user_logins(debug_on)
|
self.simulate_user_logins(debug_on)
|
||||||
prompt_continuation_of_analysis = True
|
prompt_continuation_of_analysis = True
|
||||||
|
|
||||||
|
|
||||||
# STEP 3 -- SEND INVITES
|
# STEP 3 -- SEND INVITES
|
||||||
proceed_with_sending_invites = TerminalHelper.query_yes_no(
|
if prompts_enabled:
|
||||||
f"""{TerminalColors.FAIL}
|
proceed_with_sending_invites = TerminalHelper.query_yes_no(
|
||||||
Proceed with sending user invites?
|
f"""{TerminalColors.FAIL}
|
||||||
{TerminalColors.ENDC}"""
|
Proceed with sending user invites?
|
||||||
)
|
{TerminalColors.ENDC}"""
|
||||||
if proceed_with_sending_invites:
|
)
|
||||||
self.run_send_invites_script()
|
if not proceed_with_sending_invites:
|
||||||
prompt_continuation_of_analysis = True
|
return
|
||||||
|
self.run_send_invites_script(debug_on)
|
||||||
|
prompt_continuation_of_analysis = True
|
||||||
|
|
||||||
# STEP 4 -- ANALYZE TABLES & GENERATE REPORT
|
# STEP 4 -- ANALYZE TABLES & GENERATE REPORT
|
||||||
# Analyze tables for corrupt data...
|
# Analyze tables for corrupt data...
|
||||||
|
if prompt_continuation_of_analysis & prompts_enabled:
|
||||||
# only prompt if we ran steps 1 and/or 2
|
# ^ (only prompt if we ran steps 1 and/or 2)
|
||||||
if prompt_continuation_of_analysis:
|
|
||||||
analyze_tables = TerminalHelper.query_yes_no(
|
analyze_tables = TerminalHelper.query_yes_no(
|
||||||
f"""{TerminalColors.FAIL}
|
f"""{TerminalColors.FAIL}
|
||||||
Proceed with table analysis?
|
Proceed with table analysis?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue