mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 02:49:21 +02:00
parent
47afb0339f
commit
6262a4cf39
4 changed files with 16 additions and 58 deletions
|
@ -4,18 +4,14 @@ import logging
|
||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from gevent import Timeout
|
from gevent import Timeout
|
||||||
from epplibwrapper.utility.pool_error import PoolError, PoolErrorCodes
|
|
||||||
from epplibwrapper.utility.pool_status import PoolStatus
|
from epplibwrapper.utility.pool_status import PoolStatus
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from epplib.client import Client
|
from epplib.client import Client
|
||||||
from epplib import commands
|
from epplib import commands
|
||||||
from epplib.exceptions import TransportError, ParsingError
|
from epplib.exceptions import TransportError, ParsingError
|
||||||
from epplib.transport import SocketTransport
|
from epplib.transport import SocketTransport
|
||||||
except ImportError:
|
except ImportError:
|
||||||
logger.warning("There was an import error {}")
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -25,7 +21,7 @@ from .errors import LoginError, RegistryError
|
||||||
from .socket import Socket
|
from .socket import Socket
|
||||||
from .utility.pool import EPPConnectionPool
|
from .utility.pool import EPPConnectionPool
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Write cert and key to disk
|
# 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
|
# establish a client object with a TCP socket transport
|
||||||
self._client = self._get_default_client()
|
self._client = Client(
|
||||||
logger.warning(f"client is this {self._client}")
|
SocketTransport(
|
||||||
|
settings.SECRET_REGISTRY_HOSTNAME,
|
||||||
|
cert_file=CERT.filename,
|
||||||
|
key_file=KEY.filename,
|
||||||
|
password=settings.SECRET_REGISTRY_KEY_PASSPHRASE,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.pool_options = {
|
self.pool_options = {
|
||||||
# Pool size
|
# Pool size
|
||||||
|
@ -82,16 +82,6 @@ class EPPLibWrapper:
|
||||||
if start_connection_pool:
|
if start_connection_pool:
|
||||||
self.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):
|
def _send(self, command):
|
||||||
"""Helper function used by `send`."""
|
"""Helper function used by `send`."""
|
||||||
cmd_type = command.__class__.__name__
|
cmd_type = command.__class__.__name__
|
||||||
|
@ -227,34 +217,12 @@ class EPPLibWrapper:
|
||||||
credentials are valid, and/or if the Registrar
|
credentials are valid, and/or if the Registrar
|
||||||
can be contacted
|
can be contacted
|
||||||
"""
|
"""
|
||||||
socket = self._create_default_socket()
|
socket = Socket(self._login, self._client)
|
||||||
can_login = True
|
can_login = False
|
||||||
# Something went wrong if this doesn't exist
|
# Something went wrong if this doesn't exist
|
||||||
if not hasattr(socket, "test_connection_success"):
|
if hasattr(socket, "test_connection_success"):
|
||||||
return can_login
|
|
||||||
|
|
||||||
try:
|
|
||||||
can_login = socket.test_connection_success()
|
can_login = socket.test_connection_success()
|
||||||
except PoolError as err:
|
return can_login
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -86,5 +86,3 @@ class RegistryError(Exception):
|
||||||
|
|
||||||
class LoginError(RegistryError):
|
class LoginError(RegistryError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
import logging
|
import logging
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from epplibwrapper.utility.pool_error import PoolError, PoolErrorCodes
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from epplib import commands
|
from epplib import commands
|
||||||
from epplib.client import Client
|
from epplib.client import Client
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from .errors import LoginError, SocketError
|
from .errors import LoginError
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -48,9 +46,8 @@ class Socket:
|
||||||
Tries 3 times"""
|
Tries 3 times"""
|
||||||
# Something went wrong if this doesn't exist
|
# Something went wrong if this doesn't exist
|
||||||
if not hasattr(self.client, "connect"):
|
if not hasattr(self.client, "connect"):
|
||||||
message = "self.client does not have a connect method"
|
logger.warning("self.client does not have a connect method")
|
||||||
logger.warning(message)
|
return False
|
||||||
raise PoolError(code=PoolErrorCodes.INVALID_CLIENT_TYPE)
|
|
||||||
|
|
||||||
counter = 0 # we'll try 3 times
|
counter = 0 # we'll try 3 times
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -9,13 +9,11 @@ class PoolErrorCodes(IntEnum):
|
||||||
- 2000 KILL_ALL_FAILED
|
- 2000 KILL_ALL_FAILED
|
||||||
- 2001 NEW_CONNECTION_FAILED
|
- 2001 NEW_CONNECTION_FAILED
|
||||||
- 2002 KEEP_ALIVE_FAILED
|
- 2002 KEEP_ALIVE_FAILED
|
||||||
- 2003 INVALID_CLIENT_TYPE
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
KILL_ALL_FAILED = 2000
|
KILL_ALL_FAILED = 2000
|
||||||
NEW_CONNECTION_FAILED = 2001
|
NEW_CONNECTION_FAILED = 2001
|
||||||
KEEP_ALIVE_FAILED = 2002
|
KEEP_ALIVE_FAILED = 2002
|
||||||
INVALID_CLIENT_TYPE = 2003
|
|
||||||
|
|
||||||
|
|
||||||
class PoolError(Exception):
|
class PoolError(Exception):
|
||||||
|
@ -24,19 +22,16 @@ class PoolError(Exception):
|
||||||
- 2000 KILL_ALL_FAILED
|
- 2000 KILL_ALL_FAILED
|
||||||
- 2001 NEW_CONNECTION_FAILED
|
- 2001 NEW_CONNECTION_FAILED
|
||||||
- 2002 KEEP_ALIVE_FAILED
|
- 2002 KEEP_ALIVE_FAILED
|
||||||
- 2003 INVALID_CLIENT_TYPE
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# For linter
|
# For linter
|
||||||
kill_failed = "Could not kill all connections."
|
kill_failed = "Could not kill all connections."
|
||||||
conn_failed = "Failed to execute due to a registry error."
|
conn_failed = "Failed to execute due to a registry error."
|
||||||
alive_failed = "Failed to keep the connection alive."
|
alive_failed = "Failed to keep the connection alive."
|
||||||
invalid_client = "Invalid client type."
|
|
||||||
_error_mapping = {
|
_error_mapping = {
|
||||||
PoolErrorCodes.KILL_ALL_FAILED: kill_failed,
|
PoolErrorCodes.KILL_ALL_FAILED: kill_failed,
|
||||||
PoolErrorCodes.NEW_CONNECTION_FAILED: conn_failed,
|
PoolErrorCodes.NEW_CONNECTION_FAILED: conn_failed,
|
||||||
PoolErrorCodes.KEEP_ALIVE_FAILED: alive_failed,
|
PoolErrorCodes.KEEP_ALIVE_FAILED: alive_failed,
|
||||||
PoolErrorCodes.INVALID_CLIENT_TYPE: invalid_client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, code=None, **kwargs):
|
def __init__(self, *args, code=None, **kwargs):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue