mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-19 02:49:21 +02:00
Template
This commit is contained in:
parent
1550fde832
commit
af852125f8
6 changed files with 1131 additions and 737 deletions
|
@ -26,6 +26,7 @@ boto3 = "*"
|
||||||
typing-extensions ='*'
|
typing-extensions ='*'
|
||||||
django-login-required-middleware = "*"
|
django-login-required-middleware = "*"
|
||||||
fred-epplib = {git = "https://github.com/cisagov/epplib.git", ref = "master"}
|
fred-epplib = {git = "https://github.com/cisagov/epplib.git", ref = "master"}
|
||||||
|
gsocketpool = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
django-debug-toolbar = "*"
|
django-debug-toolbar = "*"
|
||||||
|
|
1712
src/Pipfile.lock
generated
1712
src/Pipfile.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,8 @@
|
||||||
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
|
||||||
|
@ -63,13 +65,22 @@ class EPPLibWrapper:
|
||||||
# prepare a context manager which will connect and login when invoked
|
# prepare a context manager which will connect and login when invoked
|
||||||
# (it will also logout and disconnect when the context manager exits)
|
# (it will also logout and disconnect when the context manager exits)
|
||||||
self._connect = Socket(self._client, self._login)
|
self._connect = Socket(self._client, self._login)
|
||||||
|
options = {
|
||||||
|
# Pool size
|
||||||
|
"size": 10,
|
||||||
|
# Which errors the pool should look out for
|
||||||
|
"exc_classes": (LoginError, RegistryError,),
|
||||||
|
# Should we ping the connection on occassion to keep it alive?
|
||||||
|
"keep_alive": None,
|
||||||
|
}
|
||||||
|
self._pool = EppConnectionPool(client=self._client, login=self._login, options=options)
|
||||||
|
|
||||||
def _send(self, command):
|
def _send(self, command):
|
||||||
"""Helper function used by `send`."""
|
"""Helper function used by `send`."""
|
||||||
try:
|
try:
|
||||||
cmd_type = command.__class__.__name__
|
cmd_type = command.__class__.__name__
|
||||||
with self._connect as wire:
|
with self._pool.get() as connection:
|
||||||
response = wire.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 = "%s failed to execute due to some syntax error."
|
||||||
logger.warning(message, cmd_type, exc_info=True)
|
logger.warning(message, cmd_type, exc_info=True)
|
||||||
|
|
|
@ -20,6 +20,14 @@ class Socket:
|
||||||
self.login = login
|
self.login = login
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
|
"""Runs connect(), which opens a connection with EPPLib."""
|
||||||
|
self.connect()
|
||||||
|
|
||||||
|
def __exit__(self, *args, **kwargs):
|
||||||
|
"""Runs disconnect(), which closes a connection with EPPLib."""
|
||||||
|
self.disconnect()
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
"""Use epplib to connect."""
|
"""Use epplib to connect."""
|
||||||
self.client.connect()
|
self.client.connect()
|
||||||
response = self.client.send(self.login)
|
response = self.client.send(self.login)
|
||||||
|
@ -28,10 +36,21 @@ class Socket:
|
||||||
raise LoginError(response.msg)
|
raise LoginError(response.msg)
|
||||||
return self.client
|
return self.client
|
||||||
|
|
||||||
def __exit__(self, *args, **kwargs):
|
def disconnect(self):
|
||||||
"""Close the connection."""
|
"""Close the connection."""
|
||||||
try:
|
try:
|
||||||
self.client.send(commands.Logout())
|
self.client.send(commands.Logout())
|
||||||
self.client.close()
|
self.client.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning("Connection to registry was not cleanly closed.")
|
logger.warning("Connection to registry was not cleanly closed.")
|
||||||
|
|
||||||
|
def send(self, command):
|
||||||
|
logger.debug(f"command is this: {command}")
|
||||||
|
response = self.client.send(command)
|
||||||
|
# TODO - add some validation
|
||||||
|
"""
|
||||||
|
if response.code >= 2000:
|
||||||
|
self.client.close()
|
||||||
|
raise LoginError(response.msg)
|
||||||
|
"""
|
||||||
|
return response
|
25
src/epplibwrapper/utility/pool.py
Normal file
25
src/epplibwrapper/utility/pool.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
from geventconnpool import ConnectionPool
|
||||||
|
from epplibwrapper.socket import Socket
|
||||||
|
|
||||||
|
class EppConnectionPool(ConnectionPool):
|
||||||
|
def __init__(self, client, login, options):
|
||||||
|
# For storing shared credentials
|
||||||
|
self._client = client
|
||||||
|
self._login = login
|
||||||
|
super().__init__(**options)
|
||||||
|
|
||||||
|
def _new_connection(self):
|
||||||
|
socket = self.create_socket(self._client, self._login)
|
||||||
|
try:
|
||||||
|
connection = socket.connect()
|
||||||
|
return connection
|
||||||
|
except Exception as err:
|
||||||
|
raise err
|
||||||
|
|
||||||
|
def _keepalive(self, connection):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def create_socket(self, client, login) -> Socket:
|
||||||
|
"""Creates and returns a socket instance"""
|
||||||
|
socket = Socket(client, login)
|
||||||
|
return socket
|
|
@ -1,53 +1,61 @@
|
||||||
-i https://pypi.python.org/simple
|
-i https://pypi.python.org/simple
|
||||||
asgiref==3.7.2 ; python_version >= '3.7'
|
annotated-types==0.6.0; python_version >= '3.8'
|
||||||
boto3==1.26.145
|
asgiref==3.7.2; python_version >= '3.7'
|
||||||
botocore==1.29.145 ; python_version >= '3.7'
|
boto3==1.28.62; python_version >= '3.7'
|
||||||
cachetools==5.3.1
|
botocore==1.31.62; python_version >= '3.7'
|
||||||
certifi==2023.7.22 ; python_version >= '3.6'
|
cachetools==5.3.1; python_version >= '3.7'
|
||||||
|
certifi==2023.7.22; python_version >= '3.6'
|
||||||
cfenv==0.5.3
|
cfenv==0.5.3
|
||||||
cffi==1.15.1
|
cffi==1.16.0; python_version >= '3.8'
|
||||||
charset-normalizer==3.1.0 ; python_full_version >= '3.7.0'
|
charset-normalizer==3.3.0; python_full_version >= '3.7.0'
|
||||||
cryptography==41.0.4 ; python_version >= '3.7'
|
cryptography==41.0.4; python_version >= '3.7'
|
||||||
defusedxml==0.7.1 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
defusedxml==0.7.1; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
||||||
dj-database-url==2.0.0
|
dj-database-url==2.1.0
|
||||||
dj-email-url==1.0.6
|
dj-email-url==1.0.6
|
||||||
django==4.2.3
|
django==4.2.6; python_version >= '3.8'
|
||||||
django-allow-cidr==0.6.0
|
django-allow-cidr==0.7.1
|
||||||
django-auditlog==2.3.0
|
django-auditlog==2.3.0; python_version >= '3.7'
|
||||||
django-cache-url==3.4.4
|
django-cache-url==3.4.4
|
||||||
django-csp==3.7
|
django-csp==3.7
|
||||||
django-fsm==2.8.1
|
django-fsm==2.8.1
|
||||||
django-login-required-middleware==0.9.0
|
django-login-required-middleware==0.9.0
|
||||||
django-phonenumber-field[phonenumberslite]==7.1.0
|
django-phonenumber-field[phonenumberslite]==7.2.0; python_version >= '3.8'
|
||||||
django-widget-tweaks==1.4.12
|
django-widget-tweaks==1.5.0; python_version >= '3.8'
|
||||||
environs[django]==9.5.0
|
environs[django]==9.5.0; python_version >= '3.6'
|
||||||
faker==18.10.0
|
faker==19.9.0; python_version >= '3.8'
|
||||||
git+https://github.com/cisagov/epplib.git@d56d183f1664f34c40ca9716a3a9a345f0ef561c#egg=fred-epplib
|
fred-epplib@ git+https://github.com/cisagov/epplib.git@d56d183f1664f34c40ca9716a3a9a345f0ef561c
|
||||||
furl==2.1.3
|
furl==2.1.3
|
||||||
future==0.18.3 ; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
future==0.18.3; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
||||||
gunicorn==20.1.0
|
gevent==23.9.1; python_version >= '3.8'
|
||||||
idna==3.4 ; python_version >= '3.5'
|
greenlet==3.0.0; python_version < '3.11' and platform_python_implementation == 'CPython'
|
||||||
jmespath==1.0.1 ; python_version >= '3.7'
|
gsocketpool==0.1.6
|
||||||
lxml==4.9.2 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
gunicorn==21.2.0; python_version >= '3.5'
|
||||||
mako==1.2.4 ; python_version >= '3.7'
|
idna==3.4; python_version >= '3.5'
|
||||||
markupsafe==2.1.2 ; python_version >= '3.7'
|
jmespath==1.0.1; python_version >= '3.7'
|
||||||
marshmallow==3.19.0 ; python_version >= '3.7'
|
lxml==4.9.3; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
||||||
oic==1.6.0
|
mako==1.2.4; python_version >= '3.7'
|
||||||
|
markupsafe==2.1.3; python_version >= '3.7'
|
||||||
|
marshmallow==3.20.1; python_version >= '3.8'
|
||||||
|
oic==1.6.1; python_version ~= '3.7'
|
||||||
orderedmultidict==1.0.1
|
orderedmultidict==1.0.1
|
||||||
packaging==23.1 ; python_version >= '3.7'
|
packaging==23.2; python_version >= '3.7'
|
||||||
phonenumberslite==8.13.13
|
phonenumberslite==8.13.22
|
||||||
psycopg2-binary==2.9.6
|
psycopg2-binary==2.9.9; python_version >= '3.7'
|
||||||
pycparser==2.21
|
pycparser==2.21
|
||||||
pycryptodomex==3.18.0
|
pycryptodomex==3.19.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'
|
||||||
pydantic==1.10.8 ; python_version >= '3.7'
|
pydantic==2.4.2; python_version >= '3.7'
|
||||||
|
pydantic-core==2.10.1; python_version >= '3.7'
|
||||||
|
pydantic-settings==2.0.3; python_version >= '3.7'
|
||||||
pyjwkest==1.4.2
|
pyjwkest==1.4.2
|
||||||
python-dateutil==2.8.2 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
python-dateutil==2.8.2; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
||||||
python-dotenv==1.0.0 ; python_version >= '3.8'
|
python-dotenv==1.0.0; python_version >= '3.8'
|
||||||
requests==2.31.0
|
requests==2.31.0; python_version >= '3.7'
|
||||||
s3transfer==0.6.1 ; python_version >= '3.7'
|
s3transfer==0.7.0; python_version >= '3.7'
|
||||||
setuptools==67.8.0 ; python_version >= '3.7'
|
setuptools==68.2.2; python_version >= '3.8'
|
||||||
six==1.16.0 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'
|
||||||
sqlparse==0.4.4 ; python_version >= '3.5'
|
sqlparse==0.4.4; python_version >= '3.5'
|
||||||
typing-extensions==4.6.3
|
typing-extensions==4.8.0; python_version >= '3.8'
|
||||||
urllib3==1.26.17 ; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'
|
urllib3==2.0.6; python_version >= '3.7'
|
||||||
whitenoise==6.4.0
|
whitenoise==6.6.0; python_version >= '3.8'
|
||||||
|
zope.event==5.0; python_version >= '3.7'
|
||||||
|
zope.interface==6.1; python_version >= '3.7'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue