From 02b795c9283bba868292741103c4f535eee16f07 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Tue, 14 Mar 2023 09:07:43 -0500 Subject: [PATCH 01/11] Modify connection URIs The 'mongomock://' URI is deprecated, so the connection URIs now start with 'mongodb://'. --- tests/data/valid_config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/data/valid_config.yml b/tests/data/valid_config.yml index 45769dd..d747d8e 100644 --- a/tests/data/valid_config.yml +++ b/tests/data/valid_config.yml @@ -1,6 +1,6 @@ --- connections: local: - uri: mongomock://local-user:example@mongo:27017/local + uri: mongodb://local-user:example@mongo:27017/local production: - uri: mongomock://production-user:example@mongo:27017/production + uri: mongodb://production-user:example@mongo:27017/production From a324bdb03a480240e7f415f6497f5895960bbc84 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Tue, 14 Mar 2023 09:11:29 -0500 Subject: [PATCH 02/11] Specify mongomock in connection --- tests/cert_model_test.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/cert_model_test.py b/tests/cert_model_test.py index 2af9ebd..48f23da 100644 --- a/tests/cert_model_test.py +++ b/tests/cert_model_test.py @@ -7,6 +7,8 @@ # Third-Party Libraries import dateutil.tz as tz import mongoengine +from mongoengine import connect +from mongomock import MongoClient import pytest # cisagov Libraries @@ -48,11 +50,7 @@ @pytest.fixture(scope="class", autouse=True) def connection(): """Create connections for tests to use.""" - # Third-Party Libraries - from mongoengine import connect - - # TODO: Update this connection method. See #50 for more details. - connect(host="mongomock://localhost", alias="default") + connect(host="mongodb://localhost", mongo_client_class=MongoClient, alias="default") class TestCerts: From fd0e99843519232ebc4a73d8e6374d5d335af980 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Tue, 14 Mar 2023 09:12:30 -0500 Subject: [PATCH 03/11] Update valid configuration test This test broke once the 'mongomock://' URI was no longer supported. I had to rewrite the test to use the new connection method. --- tests/test_util.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index 1365729..63851f8 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,6 +1,8 @@ """Test the functionality of the util sub-module.""" # Third-Party Libraries +from mongoengine import connect +from mongomock import MongoClient import pytest # cisagov Libraries @@ -32,5 +34,8 @@ def test_load_config_valid(): def test_connect_from_config_valid(valid_config): """Test that a valid configuration connects to appropriate connections.""" - # TODO: Update this connection method. See #50 for more details. - util.connect_from_config(valid_config) + connections = valid_config["connections"] + for alias in connections.keys(): + connect( + host=connections[alias]["uri"], mongo_client_class=MongoClient, alias=alias + ) From 478c35fbb0ae67a37ae6f016269d10f194882c5e Mon Sep 17 00:00:00 2001 From: Alexander King Date: Thu, 16 Mar 2023 10:33:58 -0500 Subject: [PATCH 04/11] Drop support for Python 3.6 The mongomock connection method introduced in MongoEngine 0.27.0 is not recognized in Python 3.6. --- .github/workflows/build.yml | 9 --------- setup.py | 7 ++----- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 49781ed..cc6da71 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -119,9 +119,6 @@ jobs: - "3.9" - "3.10" - "3.11" - include: - - os: ubuntu-20.04 - python-version: "3.6" steps: - uses: actions/checkout@v3 - id: setup-python @@ -215,9 +212,6 @@ jobs: - "3.9" - "3.10" - "3.11" - include: - - os: ubuntu-20.04 - python-version: "3.6" steps: - uses: actions/checkout@v3 - id: setup-python @@ -268,9 +262,6 @@ jobs: - "3.9" - "3.10" - "3.11" - include: - - os: ubuntu-20.04 - python-version: "3.6" steps: - uses: actions/checkout@v3 - id: setup-python diff --git a/setup.py b/setup.py index 0dcea36..b028149 100644 --- a/setup.py +++ b/setup.py @@ -75,7 +75,6 @@ def get_version(version_file): # that you indicate whether you support Python 2, Python 3 or both. "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", @@ -83,7 +82,7 @@ def get_version(version_file): "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation :: CPython", ], - python_requires=">=3.6", + python_requires=">=3.7", # What does your project relate to? keywords="celery certificate-transparency cisa-directives", packages=find_packages(where="src"), @@ -96,9 +95,7 @@ def get_version(version_file): "defusedxml", "dnspython", "docopt", - # MongoEngine 0.27.0 introduces a breaking change to the mongomock - # connection method. See #50 for more details. - "mongoengine >= 0.16.3,<0.27.0", + "mongoengine >= 0.16.3", "python-dateutil >= 2.7.5", "PyYAML >=4.2b1", "redis >= 3.2.0", From bf710bd12cbf90df8803bdd2cdded65c76221a6a Mon Sep 17 00:00:00 2001 From: Alexander King Date: Tue, 27 Jun 2023 10:17:57 -0500 Subject: [PATCH 05/11] Require MongoEngine v0.27.0 or higher --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b028149..a73baef 100644 --- a/setup.py +++ b/setup.py @@ -95,7 +95,7 @@ def get_version(version_file): "defusedxml", "dnspython", "docopt", - "mongoengine >= 0.16.3", + "mongoengine >= 0.27.0", "python-dateutil >= 2.7.5", "PyYAML >=4.2b1", "redis >= 3.2.0", From e8ef436e61d59a9b1d08a6e699195807c33ce107 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Thu, 29 Jun 2023 12:56:29 -0500 Subject: [PATCH 06/11] Make the client class a connection argument This commit augments `connect_from_config()` with a `client` argument to determine which client class to use when called. The default client class for MongoEngine (`pymongo.MongoClient`) is explicitly made the default value so alternative client classes can be specified where necessary. --- src/admiral/util/config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/admiral/util/config.py b/src/admiral/util/config.py index 65d412c..2ea3cc4 100644 --- a/src/admiral/util/config.py +++ b/src/admiral/util/config.py @@ -2,6 +2,7 @@ # Third-Party Libraries from mongoengine import connect +import pymongo import yaml @@ -13,10 +14,10 @@ def load_config(filename="/run/secrets/config.yml"): return config -def connect_from_config(config=None): +def connect_from_config(config=None, client=pymongo.MongoClient): """Create connections from a confguration.""" if not config: config = load_config() connections = config["connections"] for alias in connections.keys(): - connect(host=connections[alias]["uri"], alias=alias) + connect(host=connections[alias]["uri"], mongo_client_class=client, alias=alias) From 13e08b661f165e1fa9b12f227b6b91371b2c0b27 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Thu, 29 Jun 2023 13:09:06 -0500 Subject: [PATCH 07/11] Use mock mongo client Connect MongoEngine with mongomock to test connections from a configuration. --- tests/test_util.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/tests/test_util.py b/tests/test_util.py index 63851f8..458cb1b 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,8 +1,7 @@ """Test the functionality of the util sub-module.""" # Third-Party Libraries -from mongoengine import connect -from mongomock import MongoClient +import mongomock import pytest # cisagov Libraries @@ -34,8 +33,4 @@ def test_load_config_valid(): def test_connect_from_config_valid(valid_config): """Test that a valid configuration connects to appropriate connections.""" - connections = valid_config["connections"] - for alias in connections.keys(): - connect( - host=connections[alias]["uri"], mongo_client_class=MongoClient, alias=alias - ) + util.connect_from_config(valid_config, mongomock.MongoClient) From 46dedcb4b2031660e707a09e49ed4bb12064c8a7 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Wed, 16 Aug 2023 08:34:33 -0500 Subject: [PATCH 08/11] Upgrade PyYAML The 6.0 release contains a temporary workaround to a regression in Cython 3.10.0a10 that throws an attribute error. See more details upstream at https://github.com/yaml/pyyaml/issues/601 and https://github.com/yaml/pyyaml/pull/702. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a73baef..c208059 100644 --- a/setup.py +++ b/setup.py @@ -97,7 +97,7 @@ def get_version(version_file): "docopt", "mongoengine >= 0.27.0", "python-dateutil >= 2.7.5", - "PyYAML >=4.2b1", + "PyYAML >= 6.0.0", "redis >= 3.2.0", "requests <2.21,>=2.6.1", "schedule >= 0.4.2", From 1780c1f0bbb8ce419530b00b2eac14c5da307f65 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Wed, 16 Aug 2023 09:07:21 -0500 Subject: [PATCH 09/11] Add test subject This fabricated subject covers domains that end in "fed.us" to boost test coverage. --- tests/cert_model_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/cert_model_test.py b/tests/cert_model_test.py index 48f23da..8037d41 100644 --- a/tests/cert_model_test.py +++ b/tests/cert_model_test.py @@ -66,8 +66,8 @@ def test_empty_creation(self): def test_subjects(self): """Validate that subjects and trimmed_subjects are calulcated correctly.""" cert = Cert() - cert.subjects = ["cisa.gov", "cyber.dhs.gov"] - assert set(cert.trimmed_subjects) == {"cisa.gov", "dhs.gov"} + cert.subjects = ["cisa.gov", "cyber.dhs.gov", "cisa.dhs.fed.us"] + assert set(cert.trimmed_subjects) == {"cisa.gov", "dhs.gov", "dhs.fed.us"} def test_simple_creation(self): """Create a new user, and save it.""" From a24c345c4d362524586fee6febf32687e1c24284 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Wed, 16 Aug 2023 08:51:06 -0500 Subject: [PATCH 10/11] Remove Docker Compose dependency The Docker Compose package is causing a dependency conflict. And with respect to #40, the package no longer belongs in this project. --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f073e44..8b75fe9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ # Note: Add any additional requirements to setup.py's install_requires field --editable . -docker-compose wheel From 194fb7fb010c8478ab02e1e34957a716e16878d7 Mon Sep 17 00:00:00 2001 From: Alexander King Date: Mon, 21 Aug 2023 11:31:10 -0500 Subject: [PATCH 11/11] Bump version from 1.3.3 to 1.4.0 --- src/admiral/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/admiral/_version.py b/src/admiral/_version.py index 4208ce3..39b2a5c 100644 --- a/src/admiral/_version.py +++ b/src/admiral/_version.py @@ -1,2 +1,2 @@ """This file defines the version of this module.""" -__version__ = "1.3.3" +__version__ = "1.4.0"