Signed-off-by: CocoByte <nicolle.leclair@gmail.com>
This commit is contained in:
CocoByte 2023-10-03 00:13:42 -06:00
parent e9c3c30ccc
commit 688b5742c9
No known key found for this signature in database
GPG key ID: BBFAA2526384C97F
3 changed files with 54 additions and 45 deletions

View file

@ -1,11 +1,9 @@
"""Load domain invitations for existing domains and their contacts.""" """Load domain invitations for existing domains and their contacts."""
import csv
import logging import logging
import argparse import argparse
from collections import defaultdict from django_fsm import TransitionNotAllowed # type: ignore
from django_fsm import TransitionNotAllowed # type: ignore
from django.core.management import BaseCommand from django.core.management import BaseCommand
@ -30,28 +28,26 @@ class termColors:
UNDERLINE = "\033[4m" UNDERLINE = "\033[4m"
BackgroundLightYellow = "\033[103m" BackgroundLightYellow = "\033[103m"
#----------------------------------------
# ----------------------------------------
# MAIN SCRIPT # MAIN SCRIPT
#---------------------------------------- # ----------------------------------------
class Command(BaseCommand): class Command(BaseCommand):
help = """Load data from transition domain tables help = """Load data from transition domain tables
into main domain tables.""" into main domain tables."""
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument("--debug", action=argparse.BooleanOptionalAction) parser.add_argument("--debug", action=argparse.BooleanOptionalAction)
parser.add_argument( parser.add_argument(
"--limitParse", default=0, help="Sets max number of entries to load" "--limitParse", default=0, help="Sets max number of entries to load"
) )
def handle( # noqa: C901 def handle( # noqa: C901
self, self,
**options, **options,
): ):
"""Load the data files and create the DomainInvitations.""" """Load the data files and create the DomainInvitations."""
sep = options.get("sep")
# grab command line arguments and store locally... # grab command line arguments and store locally...
debug_on = options.get("debug") debug_on = options.get("debug")
@ -71,12 +67,13 @@ class Command(BaseCommand):
# track of total rows parsed) # track of total rows parsed)
total_rows_parsed = 0 total_rows_parsed = 0
logger.info(f"""{termColors.OKGREEN} logger.info(
========================== f"""{termColors.OKGREEN}
Beginning Data Transfer
========================== ==========================
{termColors.ENDC}""") Beginning Data Transfer
==========================
{termColors.ENDC}"""
)
for transition_entry in TransitionDomain.objects.all(): for transition_entry in TransitionDomain.objects.all():
transition_domain_name = transition_entry.domain_name transition_domain_name = transition_entry.domain_name
@ -86,21 +83,29 @@ Beginning Data Transfer
try: try:
# DEBUG: # DEBUG:
if debug_on: if debug_on:
logger.info(f"""{termColors.WARNING} logger.info(
Processing Transition Domain: {transition_domain_name}, {transition_domain_status}{termColors.ENDC}""") f"""{termColors.WARNING}
Processing Transition Domain: {transition_domain_name}, {transition_domain_status}
{termColors.ENDC}"""
)
# for existing entry, update the status to the transition domain status # for existing entry, update the status to
existingEntry = Domain.objects.get( # the transition domain status
name=transition_domain_name existingEntry = Domain.objects.get(name=transition_domain_name)
)
current_state = existingEntry.state current_state = existingEntry.state
# DEBUG: # DEBUG:
if debug_on: if debug_on:
logger.info(f"""{termColors.WARNING} logger.info(
> Found existing domain entry for: {transition_domain_name}, {current_state}{termColors.ENDC}""") f"""{termColors.WARNING}
> Found existing domain entry for: {transition_domain_name}, {current_state}
{termColors.ENDC}"""
)
if transition_domain_status != current_state: if transition_domain_status != current_state:
if transition_domain_status == TransitionDomain.StatusChoices.ON_HOLD: if (
transition_domain_status
== TransitionDomain.StatusChoices.ON_HOLD
):
existingEntry.place_client_hold(ignoreEPP=True) existingEntry.place_client_hold(ignoreEPP=True)
else: else:
existingEntry.revert_client_hold(ignoreEPP=True) existingEntry.revert_client_hold(ignoreEPP=True)
@ -108,13 +113,15 @@ Processing Transition Domain: {transition_domain_name}, {transition_domain_statu
updated_domain_entries.append(existingEntry) updated_domain_entries.append(existingEntry)
# DEBUG: # DEBUG:
if debug_on: if debug_on:
logger.info(f"""{termColors.WARNING} logger.info(
>> Updated {transition_domain_name} state from '{current_state}' to '{existingEntry.state}{termColors.ENDC}'""") f"""{termColors.WARNING}
>> Updated {transition_domain_name} state from
'{current_state}' to '{existingEntry.state}{termColors.ENDC}'"""
)
except Domain.DoesNotExist: except Domain.DoesNotExist:
# no matching entry, make one # no matching entry, make one
newEntry = Domain( newEntry = Domain(
name = transition_domain_name, name=transition_domain_name, state=transition_domain_status
state = transition_domain_status
) )
to_create.append(newEntry) to_create.append(newEntry)
@ -131,8 +138,9 @@ Processing Transition Domain: {transition_domain_name}, {transition_domain_statu
Domain table for domain: Domain table for domain:
{transition_domain_name} {transition_domain_name}
----------TERMINATING----------""" ----------TERMINATING----------"""
) )
import sys import sys
sys.exit() sys.exit()
except TransitionNotAllowed as err: except TransitionNotAllowed as err:
skipped_domain_entries.append(transition_domain_name) skipped_domain_entries.append(transition_domain_name)
@ -142,7 +150,7 @@ Unable to change state for {transition_domain_name}
TRANSITION NOT ALLOWED error message (internal): TRANSITION NOT ALLOWED error message (internal):
{err} {err}
----------SKIPPING----------""" ----------SKIPPING----------"""
) )
# DEBUG: # DEBUG:
if debug_on or debug_max_entries_to_parse > 0: if debug_on or debug_max_entries_to_parse > 0:
@ -164,28 +172,28 @@ Unable to change state for {transition_domain_name}
total_updated_domain_entries = len(updated_domain_entries) total_updated_domain_entries = len(updated_domain_entries)
logger.info( logger.info(
f"""{termColors.OKGREEN} f"""{termColors.OKGREEN}
============= FINISHED =============== ============= FINISHED ===============
Created {total_new_entries} transition domain entries, Created {total_new_entries} transition domain entries,
updated {total_updated_domain_entries} transition domain entries updated {total_updated_domain_entries} transition domain entries
{termColors.ENDC} {termColors.ENDC}
""" """
) )
if len(skipped_domain_entries) > 0: if len(skipped_domain_entries) > 0:
logger.info( logger.info(
f"""{termColors.FAIL} f"""{termColors.FAIL}
============= SKIPPED DOMAINS (ERRORS) =============== ============= SKIPPED DOMAINS (ERRORS) ===============
{skipped_domain_entries} {skipped_domain_entries}
{termColors.ENDC} {termColors.ENDC}
""" """
) )
# DEBUG: # DEBUG:
if debug_on: if debug_on:
logger.info( logger.info(
f"""{termColors.WARNING} f"""{termColors.WARNING}
Created Domains: Created Domains:
{to_create} {to_create}
@ -195,12 +203,11 @@ Updated Domains:
{termColors.ENDC} {termColors.ENDC}
""" """
) )
# ----------------------------------------
# ---------------------------------------- # HELPER FUNCTIONS
# HELPER FUNCTIONS # ----------------------------------------
# ----------------------------------------
def print_debug_mode_statements(self, debug_on, debug_max_entries_to_parse): def print_debug_mode_statements(self, debug_on, debug_max_entries_to_parse):
if debug_on: if debug_on:
@ -210,7 +217,7 @@ Updated Domains:
Detailed print statements activated. Detailed print statements activated.
{termColors.ENDC} {termColors.ENDC}
""" """
) )
if debug_max_entries_to_parse > 0: if debug_max_entries_to_parse > 0:
logger.info( logger.info(
f"""{termColors.OKCYAN} f"""{termColors.OKCYAN}
@ -219,4 +226,4 @@ Data transfer will be limited to
{debug_max_entries_to_parse} entries.") {debug_max_entries_to_parse} entries.")
{termColors.ENDC} {termColors.ENDC}
""" """
) )

View file

@ -785,7 +785,8 @@ class Domain(TimeStampedModel, DomainHelper):
) )
def place_client_hold(self, ignoreEPP=False): def place_client_hold(self, ignoreEPP=False):
"""place a clienthold on a domain (no longer should resolve) """place a clienthold on a domain (no longer should resolve)
ignoreEPP (boolean) - set to true to by-pass EPP (used for transition domains)""" ignoreEPP (boolean) - set to true to by-pass EPP (used for transition domains)
"""
# TODO - ensure all requirements for client hold are made here # TODO - ensure all requirements for client hold are made here
# (check prohibited statuses) # (check prohibited statuses)
logger.info("clientHold()-> inside clientHold") logger.info("clientHold()-> inside clientHold")
@ -799,7 +800,8 @@ class Domain(TimeStampedModel, DomainHelper):
@transition(field="state", source=[State.READY, State.ON_HOLD], target=State.READY) @transition(field="state", source=[State.READY, State.ON_HOLD], target=State.READY)
def revert_client_hold(self, ignoreEPP=False): def revert_client_hold(self, ignoreEPP=False):
"""undo a clienthold placed on a domain """undo a clienthold placed on a domain
ignoreEPP (boolean) - set to true to by-pass EPP (used for transition domains)""" ignoreEPP (boolean) - set to true to by-pass EPP (used for transition domains)
"""
logger.info("clientHold()-> inside clientHold") logger.info("clientHold()-> inside clientHold")
if not ignoreEPP: if not ignoreEPP:

View file

@ -13,7 +13,7 @@ class TransitionDomain(TimeStampedModel):
state of a domain upon transition between registry state of a domain upon transition between registry
providers""" providers"""
# This is necessary to expose the enum to external # This is necessary to expose the enum to external
# classes that import TransitionDomain # classes that import TransitionDomain
StatusChoices = StatusChoices StatusChoices = StatusChoices