Skip to content

Commit

Permalink
fix config context overrides for secrets (#155)
Browse files Browse the repository at this point in the history
* fix config context overrides for secrets

---------

Co-authored-by: itdependsnetworks <ken@celenza.org>
  • Loading branch information
jeffkala and itdependsnetworks authored Apr 24, 2024
1 parent e3b7d86 commit 19614c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/admin/release_notes/version_1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 8 additions & 5 deletions nautobot_plugin_nornir/plugins/credentials/nautobot_secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -38,8 +38,10 @@ 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()
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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <info@networktocode.com>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 19614c8

Please sign in to comment.