From 6f05b77165988f8204765cad5c0ecfc2e18e7349 Mon Sep 17 00:00:00 2001 From: Al Finkelstein Date: Fri, 28 Aug 2020 07:58:12 -0500 Subject: [PATCH] ComplianceFetcher.session is resettable (#57) --- CHANGES.md | 6 +++++- CONTRIBUTING.md | 2 +- compliance/__init__.py | 2 +- compliance/fetch.py | 7 ++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 55e9abd1..079de2a9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ +# 1.2.6 + +- [FIXED] ComplianceFetcher.session can now be reset. + # 1.2.5 -- [FIXED] Credentials section bug affecting the Slack notifier. +- [FIXED] Credentials section bug affecting the Slack notifier is squashed. # 1.2.4 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d4040b49..412a6772 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,7 @@ There are some guidelines to follow when making a common fetcher or check: - The sub-document structure to adhere to for a common module is one where the root of the sub-document is the org. Under the org there should be a name field which would refer to the organization’s name. Each common module configuration sub-document should also be under the org sub-document. For example: -```json +``` { ... "org": { diff --git a/compliance/__init__.py b/compliance/__init__.py index f029117e..efd7bc20 100644 --- a/compliance/__init__.py +++ b/compliance/__init__.py @@ -14,4 +14,4 @@ # limitations under the License. """Compliance automation package.""" -__version__ = '1.2.5' +__version__ = '1.2.6' diff --git a/compliance/fetch.py b/compliance/fetch.py index afa8c9e8..8b27342f 100644 --- a/compliance/fetch.py +++ b/compliance/fetch.py @@ -35,12 +35,17 @@ def session(cls, url=None, creds=None, **headers): """ Provide a requests session object with User-Agent header. - :param url: optional base URL for the session requests to use. + :param url: optional base URL for the session requests to use. A url + argument triggers a new session object to be created whereas no url + argument will return the current session object if one exists. :param creds: optional authentication credentials. :param headers: optional kwargs to add to session headers. :returns: a requests Session object. """ + if url is not None and hasattr(cls, '_session'): + cls._session.close() + delattr(cls, '_session') if not hasattr(cls, '_session'): if url: cls._session = BaseSession(url)