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

Don't try to sort SecretsProvider class objects in plugin config features registry #1065

Merged
merged 2 commits into from Nov 11, 2021

Conversation

jathanism
Copy link
Contributor

@jathanism jathanism commented Nov 10, 2021

Fixes: n/a

This fixes a TypeError that is occurring when more than a single SecretsProvider instance is processed at once such as the case with the unreleased nautobot-plugin-secrets-providers plugin that is bundling two providers.

This is the traceback that occurs:

Traceback (most recent call last):
  File "/Users/jathan/Library/Caches/pypoetry/virtualenvs/nautobot-secrets-providers-UI3Itdc9-py3.9/bin/nautobot-server", line 8, in <module>
    sys.exit(main())
  File "/Users/jathan/Library/Caches/pypoetry/virtualenvs/nautobot-secrets-providers-UI3Itdc9-py3.9/lib/python3.9/site-packages/nautobot/core/cli.py", line 54, in main
    run_app(
  File "/Users/jathan/Library/Caches/pypoetry/virtualenvs/nautobot-secrets-providers-UI3Itdc9-py3.9/lib/python3.9/site-packages/nautobot/core/runner/runner.py", line 266, in run_app
    management.execute_from_command_line([runner_name, command] + command_args)
  File "/Users/jathan/Library/Caches/pypoetry/virtualenvs/nautobot-secrets-providers-UI3Itdc9-py3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/jathan/Library/Caches/pypoetry/virtualenvs/nautobot-secrets-providers-UI3Itdc9-py3.9/lib/python3.9/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/Users/jathan/Library/Caches/pypoetry/virtualenvs/nautobot-secrets-providers-UI3Itdc9-py3.9/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/jathan/Library/Caches/pypoetry/virtualenvs/nautobot-secrets-providers-UI3Itdc9-py3.9/lib/python3.9/site-packages/django/apps/registry.py", line 122, in populate
    app_config.ready()
  File "/Users/jathan/Library/Caches/pypoetry/virtualenvs/nautobot-secrets-providers-UI3Itdc9-py3.9/lib/python3.9/site-packages/nautobot/extras/plugins/__init__.py", line 172, in ready
    self.features["secrets_providers"] = sorted(secrets_providers)
TypeError: '<' not supported between instances of 'ABCMeta' and 'ABCMeta'
  • Updated PluginConfig.ready() base method to not try to sort list of incoming SecretsProvider classes
  • Added a __repr__ to SecretsProvider so that instances look prettier when debugging.

- Added `@total_ordering` and an `__lt__` method to `SecretsProvider`
- Updated `PluginConfig.ready()` base method to instantiate `SecretsProvider` classes before sorting them
@jathanism jathanism changed the title Fix TypeError when trying to sort SecretsProvider class objects Don't try to sort SecretsProvider class objects in plugin config features registry Nov 10, 2021
@jathanism
Copy link
Contributor Author

WHY BLACK FAIL 🪨

@glennmatthews
Copy link
Contributor

The short answer is python/typed_ast#169.

@glennmatthews glennmatthews merged commit 03bb07c into gfm-secrets Nov 11, 2021
@jathanism jathanism deleted the jathanism-fix-secrets_providers-sort branch November 11, 2021 17:36
glennmatthews added a commit that referenced this pull request Nov 15, 2021
… Groups (#868)

* Initial model, UI, and REST API for Secrets

* Secrets providers API, initial TextFile and EnvironmentVariable provider implementations (#887)

* Add Secret.value property, add EnvironmentVariable provider, add dummy-plugin Constant provider, add tests

* Add TextFileSecretProvider

* Add docs

* Improve display of secret providers in the UI

* Refactor SecretsProvider registration to use the Nautobot registry instead of python entry_points

* Refactor slightly

* Add ability for secrets providers to define an HTML form for parameter inputs

* Fix default value for JSONField and add error handling in JS

* Add username_secret and token_secret support to GitRepository

* Docs updates

* Review feedback - add description field, etc.

* Revise secrets docs; add SecretError exceptions instead of returning None on various failures

* One of these days I'll remember to run flake8 before pushing

* Review comments

* SecretsGroup feature (#1042)

* WIP

* More WIP

* WIP remove SecretType model

* Such WIP. Wow

* WIP: working secretsgroup-edit UI

* More WIP

* Change Category/Meaning to Access Type/Secret Type

* Add SecretsGroup key to Device model; get tests passing

* Add test coverage for REST API and filters

* Add SecretsGroup view tests

* Linting fixes

* Docs updates

* Cleanup leftover SecretType cruft

* Update nautobot/docs/user-guides/git-data-source.md

Co-authored-by: Jathan McCollum <jathan@gmail.com>

* Fix egregious issues

Co-authored-by: Jathan McCollum <jathan@gmail.com>

* Support Jinja2 templating of secret parameters (#1058)

* Support Jinja2 templating of secret parameters

* Add secrets providers to plugin detail view

* Doc updates

* Include SecretsGroupAssociation in GraphQL

* Move 'Secrets' to a top-level menu

* Don't try to sort `SecretsProvider` class objects in plugin config features registry (#1065)

* Fix TypeError when trying to sort `SecretsProvider` class objects
* Don't sort `secrets_providers` when added to features.

* Add release-note content for Secrets

* Update nautobot/extras/views.py

Co-authored-by: John Anderson <lampwins@gmail.com>

* Change FK to SecretsGroup behavior to SET_NULL

* Use render_jinja2() in rendered_parameters()

Co-authored-by: Jathan McCollum <jathan@gmail.com>
Co-authored-by: John Anderson <lampwins@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants