Save initial script

This commit is contained in:
Erin 2024-01-09 11:15:54 -08:00
parent f8d2898836
commit 7c87718e2d
No known key found for this signature in database
GPG key ID: 1CAD275313C62460
4 changed files with 67 additions and 9 deletions

View file

@ -246,3 +246,16 @@ class TestConnectionPool(TestCase):
expected = "InfoDomain failed to execute due to a connection error."
result = registry.send(commands.InfoDomain(name="test.gov"), cleaned=True)
self.assertEqual(result, expected)
@patch.object(EPPLibWrapper, "_test_registry_connection_success", patch_success)
def test_retries_on_transport_error(self):
"""A .send is invoked on the pool, but transport error occurs and EPP
retries connection."""
with ExitStack() as stack:
stack.enter_context(patch.object(EPPConnectionPool, "_create_socket", self.fake_socket))
stack.enter_context(patch.object(Socket, "connect", self.fake_client))
# Pool should be running
self.assertEqual(registry.pool_status.connection_success, True)
self.assertEqual(registry.pool_status.pool_running, True)

View file

@ -1,8 +0,0 @@
## Purpose
Use this folder for storing files for the migration process. Should otherwise be empty on local dev environments unless necessary. This folder must exist due to the nature of how data is stored on cloud.gov and the nature of the data we want to send.
## How do I migrate registrar data?
This process is detailed in [data_migration.md](../../docs/operations/data_migration.md)
## What kind of files can I store here?
The intent is for PII data or otherwise, but this can exist in any format. Do note that the data contained in this file will be temporary, so after the app is restaged it will lose it. This is ideal for migration files as they write to our DB, but not for something you need to permanently hold onto.

View file

@ -0,0 +1,53 @@
""""Script description"""
import logging
from django.core.management import BaseCommand
from registrar.models import Domain
logger = logging.getLogger(__name__)
class Command(BaseCommand):
# TODO: write script description here
help = "Description"
def __init__(self):
"""Sets global variables for code tidyness"""
super().__init__()
# this array is used to store domains with errors, which are not
# successfully updated to disclose
domains_with_errors: List[str] = []
def handle(self, **options):
"""
Description for what update_security_email_disclose does
"""
logger.info("Updating security emails to public")
domains = Domain.objects.filter()
# Call security_contact on all domains to trigger saving contact information
for domain in domains:
contact = domain.security_contact
domains_with_contact = Domain.objects.filter(
security_contact_registry_id=True
)
logger.info("Found %d domains with security contact.", len(domains_with_contact))
# Update EPP contact for domains with a security contact
for domain in domains_with_contact:
try:
domain._update_epp_contact(contact=domain.security_contact_registry_id)
logger.info("Updated EPP contact for domain %d to disclose: %d", domain, domain.security_contact.disclose)
except Exception as err:
# error condition if domain not in database
self.domains_with_errors.append(copy.deepcopy(domain.domain_name))
logger.error(f"error retrieving domain {domain.domain_name}: {err}")
domains_disclosed = Domain.objects.filter(
security_contact_registry_id=True,
)
logger.info("Updated %d domains to disclosed.", len(domains_disclosed))

View file

@ -1400,7 +1400,7 @@ class Domain(TimeStampedModel, DomainHelper):
is_security = contact.contact_type == contact.ContactTypeChoices.SECURITY
DF = epp.DiscloseField
fields = {DF.EMAIL}
disclose = is_security and contact.email != PublicContact.get_default_security().email
disclose = is_security
# Will only disclose DF.EMAIL if its not the default
return epp.Disclose(
flag=disclose,