From 46fd5b4a15f5046508ee723dc7ce5e58afed54ea Mon Sep 17 00:00:00 2001 From: Jeff Kala Date: Tue, 23 Apr 2024 14:17:12 -0500 Subject: [PATCH 1/3] fix config context overrides for secrets --- .../plugins/credentials/nautobot_secrets.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py b/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py index 04ef1fa..b70e80e 100644 --- a/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py +++ b/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py @@ -24,7 +24,7 @@ import json from nautobot.extras.choices import SecretsGroupAccessTypeChoices, SecretsGroupSecretTypeChoices -from nautobot_plugin_nornir.constants import PLUGIN_CFG +from nautobot_plugin_nornir.constants import NORNIR_SETTINGS from .nautobot_orm import MixinNautobotORMCredentials @@ -38,7 +38,7 @@ def _get_access_type_value(device_obj): Returns: SecretsGroupAccessTypeChoices: Choice """ - if PLUGIN_CFG.get("use_config_context", {}).get("secrets"): + if NORNIR_SETTINGS.get("use_config_context", {}).get("secrets"): access_type_str = device_obj.get_config_context()["nautobot_plugin_nornir"]["secret_access_type"].upper() access_type = getattr(SecretsGroupAccessTypeChoices, f"TYPE_{access_type_str}") else: From a11a19a1e18b00d0b7aeac14e6d475b6b38d93fe Mon Sep 17 00:00:00 2001 From: Jeff Kala Date: Tue, 23 Apr 2024 15:38:30 -0500 Subject: [PATCH 2/3] fixes secrets group access type overrides and fixes https access type application --- changes/155.fixed | 1 + .../plugins/credentials/nautobot_secrets.py | 9 ++++++--- pyproject.toml | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) create mode 100755 changes/155.fixed diff --git a/changes/155.fixed b/changes/155.fixed new file mode 100755 index 0000000..7d73995 --- /dev/null +++ b/changes/155.fixed @@ -0,0 +1 @@ +Fixed secrets group access type overrides not working. diff --git a/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py b/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py index b70e80e..926a438 100644 --- a/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py +++ b/nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py @@ -40,6 +40,8 @@ def _get_access_type_value(device_obj): """ if NORNIR_SETTINGS.get("use_config_context", {}).get("secrets"): access_type_str = device_obj.get_config_context()["nautobot_plugin_nornir"]["secret_access_type"].upper() + if access_type_str == "HTTP(S)": + access_type_str = "HTTP" access_type = getattr(SecretsGroupAccessTypeChoices, f"TYPE_{access_type_str}") else: access_type = SecretsGroupAccessTypeChoices.TYPE_GENERIC @@ -128,12 +130,13 @@ def get_device_creds(self, device): self.secret = None for sec in device.secrets_group.secrets.all(): secret_value = self.creds_cache.get(self._get_or_cache_secret_key(device, sec)) + sec_access_type = f"TYPE_{sec.secretsgroupassociation_set.first().access_type.upper()}" + if sec_access_type == "TYPE_HTTP(S)": + sec_access_type = "TYPE_HTTP" current_secret_type = getattr( SecretsGroupSecretTypeChoices, f"TYPE_{sec.secretsgroupassociation_set.first().secret_type.upper()}" ) - current_access_type = getattr( - SecretsGroupAccessTypeChoices, f"TYPE_{sec.secretsgroupassociation_set.first().access_type.upper()}" - ) + current_access_type = getattr(SecretsGroupAccessTypeChoices, sec_access_type) configured_access_type = _get_access_type_value(device) if ( current_secret_type == SecretsGroupSecretTypeChoices.TYPE_USERNAME diff --git a/pyproject.toml b/pyproject.toml index 505b7bb..d3c0d36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nautobot-plugin-nornir" -version = "1.0.4" +version = "1.0.5" description = "Nautobot Nornir plugin." authors = ["Network to Code, LLC "] license = "Apache-2.0" From b86b02da3d2da890def3e8dc3532add4beef5dce Mon Sep 17 00:00:00 2001 From: itdependsnetworks Date: Tue, 23 Apr 2024 22:18:18 -0400 Subject: [PATCH 3/3] Move changelog fragment to release notes --- changes/155.fixed | 1 - docs/admin/release_notes/version_1.0.md | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) delete mode 100755 changes/155.fixed diff --git a/changes/155.fixed b/changes/155.fixed deleted file mode 100755 index 7d73995..0000000 --- a/changes/155.fixed +++ /dev/null @@ -1 +0,0 @@ -Fixed secrets group access type overrides not working. diff --git a/docs/admin/release_notes/version_1.0.md b/docs/admin/release_notes/version_1.0.md index a789923..235082b 100644 --- a/docs/admin/release_notes/version_1.0.md +++ b/docs/admin/release_notes/version_1.0.md @@ -5,6 +5,11 @@ - Add provider class for Nautobot Secrets Functionality +## [v1.0.5] - 2024-04 + +### Fixed + +- [#155](https://github.com/nautobot/nautobot-plugin-nornir/issues/155) - Fixed secrets group access type overrides not working. ## [v1.0.4] - 2024-04