diff --git a/src/epplibwrapper/client.py b/src/epplibwrapper/client.py index f068bfad4..6fafb2fd6 100644 --- a/src/epplibwrapper/client.py +++ b/src/epplibwrapper/client.py @@ -4,18 +4,14 @@ import logging from time import sleep from gevent import Timeout -from epplibwrapper.utility.pool_error import PoolError, PoolErrorCodes from epplibwrapper.utility.pool_status import PoolStatus -logger = logging.getLogger(__name__) - try: from epplib.client import Client from epplib import commands from epplib.exceptions import TransportError, ParsingError from epplib.transport import SocketTransport except ImportError: - logger.warning("There was an import error {}") pass from django.conf import settings @@ -25,7 +21,7 @@ from .errors import LoginError, RegistryError from .socket import Socket from .utility.pool import EPPConnectionPool - +logger = logging.getLogger(__name__) try: # Write cert and key to disk @@ -59,11 +55,15 @@ class EPPLibWrapper: ], ) - # TODO - if client is none, send signal up and set it - # back to this # establish a client object with a TCP socket transport - self._client = self._get_default_client() - logger.warning(f"client is this {self._client}") + self._client = Client( + SocketTransport( + settings.SECRET_REGISTRY_HOSTNAME, + cert_file=CERT.filename, + key_file=KEY.filename, + password=settings.SECRET_REGISTRY_KEY_PASSPHRASE, + ) + ) self.pool_options = { # Pool size @@ -82,16 +82,6 @@ class EPPLibWrapper: if start_connection_pool: self.start_connection_pool() - def _get_default_client(self): - return Client( - SocketTransport( - settings.SECRET_REGISTRY_HOSTNAME, - cert_file=CERT.filename, - key_file=KEY.filename, - password=settings.SECRET_REGISTRY_KEY_PASSPHRASE, - ) - ) - def _send(self, command): """Helper function used by `send`.""" cmd_type = command.__class__.__name__ @@ -227,34 +217,12 @@ class EPPLibWrapper: credentials are valid, and/or if the Registrar can be contacted """ - socket = self._create_default_socket() - can_login = True + socket = Socket(self._login, self._client) + can_login = False # Something went wrong if this doesn't exist - if not hasattr(socket, "test_connection_success"): - return can_login - - try: + if hasattr(socket, "test_connection_success"): can_login = socket.test_connection_success() - except PoolError as err: - logger.error(err) - # If the client isn't the right type, - # recreate it. - if err.code == PoolErrorCodes.INVALID_CLIENT_TYPE: - # Try to recreate the socket - self._client = self._get_default_client() - socket = self._create_default_socket() - - # Test it again - can_login = socket.test_connection_success() - return can_login - else: - return can_login - - def _create_default_socket(self): - """Creates a default socket. - Uses self._login and self._client - """ - return Socket(self._login, self._client) + return can_login try: diff --git a/src/epplibwrapper/errors.py b/src/epplibwrapper/errors.py index 96188750c..dba5f328c 100644 --- a/src/epplibwrapper/errors.py +++ b/src/epplibwrapper/errors.py @@ -86,5 +86,3 @@ class RegistryError(Exception): class LoginError(RegistryError): pass - - diff --git a/src/epplibwrapper/socket.py b/src/epplibwrapper/socket.py index 63fab9743..00cad80af 100644 --- a/src/epplibwrapper/socket.py +++ b/src/epplibwrapper/socket.py @@ -1,15 +1,13 @@ import logging from time import sleep -from epplibwrapper.utility.pool_error import PoolError, PoolErrorCodes - try: from epplib import commands from epplib.client import Client except ImportError: pass -from .errors import LoginError, SocketError +from .errors import LoginError logger = logging.getLogger(__name__) @@ -48,9 +46,8 @@ class Socket: Tries 3 times""" # Something went wrong if this doesn't exist if not hasattr(self.client, "connect"): - message = "self.client does not have a connect method" - logger.warning(message) - raise PoolError(code=PoolErrorCodes.INVALID_CLIENT_TYPE) + logger.warning("self.client does not have a connect method") + return False counter = 0 # we'll try 3 times while True: diff --git a/src/epplibwrapper/utility/pool_error.py b/src/epplibwrapper/utility/pool_error.py index 2febcaaa0..70312f32e 100644 --- a/src/epplibwrapper/utility/pool_error.py +++ b/src/epplibwrapper/utility/pool_error.py @@ -9,13 +9,11 @@ class PoolErrorCodes(IntEnum): - 2000 KILL_ALL_FAILED - 2001 NEW_CONNECTION_FAILED - 2002 KEEP_ALIVE_FAILED - - 2003 INVALID_CLIENT_TYPE """ KILL_ALL_FAILED = 2000 NEW_CONNECTION_FAILED = 2001 KEEP_ALIVE_FAILED = 2002 - INVALID_CLIENT_TYPE = 2003 class PoolError(Exception): @@ -24,19 +22,16 @@ class PoolError(Exception): - 2000 KILL_ALL_FAILED - 2001 NEW_CONNECTION_FAILED - 2002 KEEP_ALIVE_FAILED - - 2003 INVALID_CLIENT_TYPE """ # For linter kill_failed = "Could not kill all connections." conn_failed = "Failed to execute due to a registry error." alive_failed = "Failed to keep the connection alive." - invalid_client = "Invalid client type." _error_mapping = { PoolErrorCodes.KILL_ALL_FAILED: kill_failed, PoolErrorCodes.NEW_CONNECTION_FAILED: conn_failed, PoolErrorCodes.KEEP_ALIVE_FAILED: alive_failed, - PoolErrorCodes.INVALID_CLIENT_TYPE: invalid_client } def __init__(self, *args, code=None, **kwargs):