Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix config context overrides for secrets #155

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading