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 an error when rendering a SecretsError with an unknown provider to string #2962

Merged
merged 2 commits into from
Dec 7, 2022

Conversation

glennmatthews
Copy link
Contributor

@glennmatthews glennmatthews commented Dec 7, 2022

Closes: #TBD

What's Changed

Fix a user-reported issue from public Slack:

   File "/usr/local/lib/python3.9/site-packages/nautobot/extras/secrets/exceptions.py", line 16, in __str__
     f'Secret "{self.secret}" (provider "{self.provider_class.__name__}"): {self.message}'
 AttributeError: 'NoneType' object has no attribute '__name__'

This happens in the case where a Secret has a configured provider string that doesn't correspond to any registered SecretsProvider class; when attempting to get the value of this Secret, a SecretProviderError is raised with a None value for its provider_class attribute; when Nautobot attempts to log this error, the SecretError.__str__() function attempts to dereference self.provider_class.__name__ which throws the above AttributeError.

To fix this issue, I've made the following changes:

  • To make for slightly better string representation, allow a SecretError to store either a provider_class class reference (as before) or a raw provider string, and let the __str__() representation of the SecretError use either.
  • Change the exception raised in the "no registered provider" case to pass the unknown provider string instead of None when constructing the SecretProviderError.

Additionally:

  • Update the various test cases that test for SecretError to be raised so that they also now check the string representation of each such exception.

TODO

  • Explanation of Change(s)
  • Added change log fragment(s) (for more information see the documentation)
  • n/a Attached Screenshots, Payload Example
  • Unit, Integration Tests
  • n/a Documentation Updates (when adding/changing features)
  • n/a Example Plugin Updates (when adding/changing features)
  • Outline Remaining Work, Constraints from Design

@glennmatthews glennmatthews self-assigned this Dec 7, 2022
@bryanculver bryanculver self-requested a review December 7, 2022 16:06
Copy link
Contributor

@jathanism jathanism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@glennmatthews glennmatthews merged commit 76b4b60 into develop Dec 7, 2022
@glennmatthews glennmatthews deleted the gfm-fix-secretserror-str branch December 7, 2022 22:02
@bryanculver bryanculver added the type: bug Something isn't working as expected label Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants