From eb6f573d84b0760e3bba770bd4663c8dd05033e8 Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 26 Mar 2024 19:33:10 -0500 Subject: [PATCH 1/6] Adds token to status, version and openapi calls --- pynautobot/core/api.py | 13 ++++++++----- pynautobot/core/query.py | 12 ++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/pynautobot/core/api.py b/pynautobot/core/api.py index 6d2bfce..864c396 100644 --- a/pynautobot/core/api.py +++ b/pynautobot/core/api.py @@ -15,6 +15,7 @@ This file has been modified by NetworktoCode, LLC. """ + from packaging import version import requests from requests.adapters import HTTPAdapter @@ -140,10 +141,12 @@ def version(self): '1.0' >>> """ - version = Request( - base=self.base_url, http_session=self.http_session, api_version=self.api_version + return Request( + base=self.base_url, + http_session=self.http_session, + api_version=self.api_version, + token=self.token, ).get_version() - return version def openapi(self): """Returns the OpenAPI spec. @@ -166,6 +169,7 @@ def openapi(self): base=self.base_url, http_session=self.http_session, api_version=self.api_version, + token=self.token, ).get_openapi() def status(self): @@ -196,10 +200,9 @@ def status(self): 'rq-workers-running': 1} >>> """ - status = Request( + return Request( base=self.base_url, token=self.token, http_session=self.http_session, api_version=self.api_version, ).get_status() - return status diff --git a/pynautobot/core/query.py b/pynautobot/core/query.py index 5cda7a2..f412760 100644 --- a/pynautobot/core/query.py +++ b/pynautobot/core/query.py @@ -15,6 +15,7 @@ This file has been modified by NetworktoCode, LLC. """ + try: import concurrent.futures as cf except ImportError: @@ -162,6 +163,7 @@ def get_openapi(self): """Gets the OpenAPI Spec""" headers = { "Content-Type": "application/json;", + "Authorization": f"Token {self.token}", } if self.api_version: @@ -190,7 +192,10 @@ def get_version(self): :Returns: Version number as a string. Empty string if version is not present in the headers. """ - headers = {"Content-Type": "application/json;"} + headers = { + "Content-Type": "application/json;", + "Authorization": f"Token {self.token}", + } if self.api_version: headers["accept"] = f"application/json; version={self.api_version}" @@ -213,7 +218,10 @@ def get_status(self): :Returns: Dictionary as returned by Nautobot. :Raises: RequestError if request is not successful. """ - headers = {"Content-Type": "application/json;"} + headers = { + "Content-Type": "application/json;", + "Authorization": f"Token {self.token}", + } if self.token: headers["authorization"] = "Token {}".format(self.token) From 30ad305cf8c56718248691d6c301ca011a530d9f Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 26 Mar 2024 19:33:16 -0500 Subject: [PATCH 2/6] Fixes test --- tests/unit/test_request.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_request.py b/tests/unit/test_request.py index 313bbc2..263b840 100644 --- a/tests/unit/test_request.py +++ b/tests/unit/test_request.py @@ -6,9 +6,9 @@ class RequestTestCase(unittest.TestCase): def test_get_openapi(self): - test = Request("http://localhost:8080/api", Mock()) + test = Request("http://localhost:8080/api", Mock(), token="1234") test.get_openapi() test.http_session.get.assert_called_with( "http://localhost:8080/api/docs/?format=openapi", - headers={"Content-Type": "application/json;"}, + headers={"Content-Type": "application/json;", "Authorization": "Token 1234"}, ) From 4a34a46eb11580b7a802992a29ade9ac092ab6f6 Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 26 Mar 2024 19:33:26 -0500 Subject: [PATCH 3/6] Updates CI versions --- .github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7354e11..ec2f914 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,11 +10,8 @@ jobs: strategy: fail-fast: true matrix: - python-version: ["3.8", "3.9", "3.10"] - nautobot-version: ["2.0"] - exclude: - - python-version: 3.10 - nautobot-version: 1.2 + python-version: ["3.8", "3.9", "3.10", "3.11"] + nautobot-version: ["2.0", "2.1"] env: PYTHON_VER: "${{ matrix.python-version }}" NAUTOBOT_VER: "${{ matrix.nautobot-version }}" From 2a1519755e56fad368d4165daf4045f6d77fa71c Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 26 Mar 2024 19:33:57 -0500 Subject: [PATCH 4/6] Disables black for temporary testing files --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 667cd22..db46296 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,7 @@ exclude = ''' | dist )/ | settings.py # This is where you define files that should not be stylized by black - # the root of the project + | .devicetype-library/ ) ''' From 7a4a2f5ec10220d941a020932be15bc29db41d2b Mon Sep 17 00:00:00 2001 From: Joe Wesch Date: Tue, 26 Mar 2024 19:40:48 -0500 Subject: [PATCH 5/6] Adds stable to nautobot version tests --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec2f914..7828edc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: fail-fast: true matrix: python-version: ["3.8", "3.9", "3.10", "3.11"] - nautobot-version: ["2.0", "2.1"] + nautobot-version: ["2.0", "2.1", "stable"] env: PYTHON_VER: "${{ matrix.python-version }}" NAUTOBOT_VER: "${{ matrix.nautobot-version }}" From afffb92c09501892b85c3793bb5978555fe5cedf Mon Sep 17 00:00:00 2001 From: Josh VanDeraa Date: Wed, 27 Mar 2024 07:56:39 -0500 Subject: [PATCH 6/6] Release for auth change in Nautobot. --- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab0f289..a03a0c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v2.1.1 + +- (#173) Fixes for authentication change in Nautobot. + ## v2.1.0 ### New Features @@ -41,6 +45,10 @@ New release for nautobot 2.0 Release Candidate. New release train for nautobot 2.X +## v1.5.2 + +- (#174) Fixes for authentication change in Nautobot. + ## v1.5.0 ### New Features diff --git a/pyproject.toml b/pyproject.toml index db46296..530b07c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ [tool.poetry] name = "pynautobot" -version = "2.1.0" +version = "2.1.1" description = "Nautobot API client library" authors = ["Network to Code, LLC "] readme = "README.md"