mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-16 15:55:58 +02:00
Fix pool locally, cleanup
This commit is contained in:
parent
a82f3c5ce9
commit
c4d2950ac9
2 changed files with 18 additions and 15 deletions
|
@ -3,8 +3,6 @@
|
||||||
import logging
|
import logging
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from epplibwrapper.utility.pool import EppConnectionPool
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from epplib.client import Client
|
from epplib.client import Client
|
||||||
from epplib import commands
|
from epplib import commands
|
||||||
|
@ -17,6 +15,7 @@ from django.conf import settings
|
||||||
|
|
||||||
from .cert import Cert, Key
|
from .cert import Cert, Key
|
||||||
from .errors import LoginError, RegistryError
|
from .errors import LoginError, RegistryError
|
||||||
|
from .utility.pool import EppConnectionPool
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -78,25 +77,32 @@ class EPPLibWrapper:
|
||||||
|
|
||||||
def _send(self, command):
|
def _send(self, command):
|
||||||
"""Helper function used by `send`."""
|
"""Helper function used by `send`."""
|
||||||
try:
|
|
||||||
cmd_type = command.__class__.__name__
|
cmd_type = command.__class__.__name__
|
||||||
|
try:
|
||||||
|
# We won't have an EPP connection locally,
|
||||||
|
# shortcut this and raise an err
|
||||||
|
# TODO - implement a timeout in _pool.get()
|
||||||
|
if settings.DEBUG:
|
||||||
|
raise LoginError
|
||||||
with self._pool.get() as connection:
|
with self._pool.get() as connection:
|
||||||
response = connection.send(command)
|
response = connection.send(command)
|
||||||
except (ValueError, ParsingError) as err:
|
except (ValueError, ParsingError) as err:
|
||||||
message = "%s failed to execute due to some syntax error."
|
message = f"{cmd_type} failed to execute due to some syntax error."
|
||||||
logger.warning(message, cmd_type, exc_info=True)
|
logger.warning(message, exc_info=True)
|
||||||
raise RegistryError(message) from err
|
raise RegistryError(message) from err
|
||||||
except TransportError as err:
|
except TransportError as err:
|
||||||
message = "%s failed to execute due to a connection error."
|
message = f"{cmd_type} failed to execute due to a connection error."
|
||||||
logger.warning(message, cmd_type, exc_info=True)
|
logger.warning(message, exc_info=True)
|
||||||
raise RegistryError(message) from err
|
raise RegistryError(message) from err
|
||||||
except LoginError as err:
|
except LoginError as err:
|
||||||
message = "%s failed to execute due to a registry login error."
|
# For linter
|
||||||
logger.warning(message, cmd_type, exc_info=True)
|
text = "failed to execute due to a registry login error."
|
||||||
|
message = f"{cmd_type} {text}"
|
||||||
|
logger.warning(message, exc_info=True)
|
||||||
raise RegistryError(message) from err
|
raise RegistryError(message) from err
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
message = "%s failed to execute due to an unknown error." % err
|
message = f"{cmd_type} failed to execute due to an unknown error."
|
||||||
logger.warning(message, cmd_type, exc_info=True)
|
logger.warning(message, exc_info=True)
|
||||||
raise RegistryError(message) from err
|
raise RegistryError(message) from err
|
||||||
else:
|
else:
|
||||||
if response.code >= 2000:
|
if response.code >= 2000:
|
||||||
|
|
|
@ -45,12 +45,9 @@ class Socket:
|
||||||
logger.warning("Connection to registry was not cleanly closed.")
|
logger.warning("Connection to registry was not cleanly closed.")
|
||||||
|
|
||||||
def send(self, command):
|
def send(self, command):
|
||||||
logger.debug(f"command is this: {command}")
|
|
||||||
response = self.client.send(command)
|
response = self.client.send(command)
|
||||||
# TODO - add some validation
|
|
||||||
"""
|
|
||||||
if response.code >= 2000:
|
if response.code >= 2000:
|
||||||
self.client.close()
|
self.client.close()
|
||||||
raise LoginError(response.msg)
|
raise LoginError(response.msg)
|
||||||
"""
|
|
||||||
return response
|
return response
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue