-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add entrypoints for moved modules #17
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,15 @@ dependencies = [ # runtime deps # https://packaging.python.org/en/latest/guide | |
# GUIDANCE: only add things that this project imports directly | ||
# GUIDANCE: only set lower version bounds | ||
# "awx_plugins.base_interface.api", # keep `__init__.py` empty | ||
"Django", # <- credentials.injectors (and inventory.plugins indirectly) | ||
"PyYAML", # credentials.injectors, inventory.plugins | ||
"azure-identity", # credentials.azure_kv | ||
"azure-keyvault", # credentials.azure_kv | ||
"boto3", # credentials.awx_secretsmanager | ||
"msrestazure", # credentials.azure_kv | ||
"python-dsv-sdk >= 1.0.4", # credentials.thycotic_dsv | ||
"python-tss-sdk >= 1.2.1", # credentials.thycotic_tss | ||
"requests", # credentials.aim, credentials.centrify_vault, credentials.conjur, credentials.hashivault | ||
] | ||
classifiers = [ # Allowlist: https://pypi.org/classifiers/ | ||
"Development Status :: 1 - Planning", | ||
|
@@ -65,12 +74,29 @@ name = "Ansible maintainers and contributors" | |
# PLUGIN ACTIVATION GUIDANCE (UX): | ||
# `pip install awx_plugins.credentials.x` would auto-activate any plugins the packaged project ships | ||
[project.entry-points."awx_plugins.credentials"] # new entry points group name | ||
x = "awx_plugins.credentials.x.api:XPlugin" | ||
|
||
# awx calls `importlib.metadata.entry_points(group='awx.credential_plugins')` to discover and later enable any plugins present in the same env | ||
[project.entry-points."awx.credential_plugins"] # pre-existing entry points group name | ||
x = "awx_plugins.credentials.x.api:XPlugin" | ||
# conjur = awx.main.credential_plugins.conjur:conjur_plugin | ||
conjur = "awx_plugins.credentials.conjur:conjur_plugin" | ||
hashivault_kv = "awx_plugins.credentials.hashivault:hashivault_kv_plugin" | ||
webknjaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hashivault_ssh = "awx_plugins.credentials.hashivault:hashivault_ssh_plugin" | ||
azure_kv = "awx_plugins.credentials.azure_kv:azure_keyvault_plugin" | ||
aim = "awx_plugins.credentials.aim:aim_plugin" | ||
centrify_vault_kv = "awx_plugins.credentials.centrify_vault:centrify_plugin" | ||
thycotic_dsv = "awx_plugins.credentials.dsv:dsv_plugin" | ||
thycotic_tss = "awx_plugins.credentials.tss:tss_plugin" | ||
aws_secretsmanager_credential = "awx_plugins.credentials.aws_secretsmanager:aws_secretmanager_plugin" | ||
Comment on lines
+77
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the inventory plugin missing from here? |
||
|
||
[project.entry-points."awx_plugins.inventory"] # new entry points group name | ||
azure-rm = "awx_plugins.inventory.plugins:azure_rm" | ||
ec2 = "awx_plugins.inventory.plugins:ec2" | ||
gce = "awx_plugins.inventory.plugins:gce" | ||
vmware = "awx_plugins.inventory.plugins:vmware" | ||
openstack = "awx_plugins.inventory.plugins:openstack" | ||
rhv = "awx_plugins.inventory.plugins:rhv" | ||
satellite6 = "awx_plugins.inventory.plugins:satellite6" | ||
terraform = "awx_plugins.inventory.plugins:terraform" | ||
controller = "awx_plugins.inventory.plugins:controller" | ||
insights = "awx_plugins.inventory.plugins:insights" | ||
openshift_virtualization = "awx_plugins.inventory.plugins:openshift_virtualization" | ||
constructed = "awx_plugins.inventory.plugins:constructed" | ||
|
||
[project.license] | ||
file = "LICENSE" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,190 @@ | ||
"""Smoke tests related to loading entry points.""" | ||
|
||
from dataclasses import dataclass | ||
from importlib.metadata import entry_points as _discover_entry_points | ||
|
||
import pytest | ||
|
||
from awx_plugins.inventory.plugins import PluginFileInjector | ||
|
||
@pytest.mark.parametrize( | ||
'entry_points_group', | ||
( | ||
'awx.credential_plugins', | ||
|
||
@dataclass(frozen=True) | ||
class EntryPointParam: | ||
"""Data structure representing a single exposed plugin.""" | ||
|
||
group: str | ||
name: str | ||
spec: str | ||
|
||
def __str__(self): | ||
"""Render an entry-point parameter as a string. | ||
|
||
To be used as a part of parametrized test ID. | ||
""" | ||
return f'{self.name}={self.spec}@{self.group}' | ||
|
||
|
||
credential_plugins = ( | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'aim', | ||
'awx_plugins.credentials.aim:aim_plugin', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'conjur', | ||
'awx_plugins.credentials.conjur:conjur_plugin', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'hashivault_kv', | ||
'awx_plugins.credentials.hashivault:hashivault_kv_plugin', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'hashivault_ssh', | ||
'awx_plugins.credentials.hashivault:hashivault_ssh_plugin', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'azure_kv', | ||
'awx_plugins.credentials.azure_kv:azure_keyvault_plugin', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'centrify_vault_kv', | ||
'awx_plugins.credentials.centrify_vault:centrify_plugin', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'thycotic_dsv', | ||
'awx_plugins.credentials.dsv:dsv_plugin', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'thycotic_tss', | ||
'awx_plugins.credentials.tss:tss_plugin', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.credentials', | ||
'aws_secretsmanager_credential', | ||
'awx_plugins.credentials.aws_secretsmanager:aws_secretmanager_plugin', | ||
), | ||
) | ||
def test_entry_points_exposed(entry_points_group: str) -> None: | ||
"""Verify the plugin entry point is discoverable. | ||
|
||
|
||
inventory_plugins = ( | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'azure-rm', | ||
'awx_plugins.inventory.plugins:azure_rm', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'ec2', | ||
'awx_plugins.inventory.plugins:ec2', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'gce', | ||
'awx_plugins.inventory.plugins:gce', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'vmware', | ||
'awx_plugins.inventory.plugins:vmware', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'openstack', | ||
'awx_plugins.inventory.plugins:openstack', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'rhv', | ||
'awx_plugins.inventory.plugins:rhv', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'satellite6', | ||
'awx_plugins.inventory.plugins:satellite6', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'terraform', | ||
'awx_plugins.inventory.plugins:terraform', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'controller', | ||
'awx_plugins.inventory.plugins:controller', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'insights', | ||
'awx_plugins.inventory.plugins:insights', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'openshift_virtualization', | ||
'awx_plugins.inventory.plugins:openshift_virtualization', | ||
), | ||
EntryPointParam( | ||
'awx_plugins.inventory', | ||
'constructed', | ||
'awx_plugins.inventory.plugins:constructed', | ||
), | ||
) | ||
|
||
|
||
with_credential_plugins = pytest.mark.parametrize( | ||
'entry_point', | ||
credential_plugins, | ||
ids=str, | ||
) | ||
|
||
|
||
with_inventory_plugins = pytest.mark.parametrize( | ||
'entry_point', | ||
inventory_plugins, | ||
ids=str, | ||
) | ||
|
||
|
||
with_all_plugins = pytest.mark.parametrize( | ||
'entry_point', | ||
credential_plugins + inventory_plugins, | ||
ids=str, | ||
) | ||
|
||
|
||
@with_all_plugins | ||
def test_entry_points_exposed(entry_point: str) -> None: | ||
"""Verify the plugin entry points are discoverable. | ||
|
||
This check relies on the plugin-declaring distribution package to be | ||
pre-installed. | ||
""" | ||
entry_points = _discover_entry_points(group=entry_points_group) | ||
assert 'x' in entry_points.names | ||
entry_points = _discover_entry_points(group=entry_point.group) | ||
|
||
assert entry_point.name in entry_points.names | ||
assert entry_points[entry_point.name].value == entry_point.spec | ||
|
||
|
||
@with_credential_plugins | ||
def test_entry_points_are_credential_plugin(entry_point: str) -> None: | ||
"""Ensure all exposed credential plugins are of the same class.""" | ||
entry_points = _discover_entry_points(group=entry_point.group) | ||
loaded_plugin_class = entry_points[entry_point.name].load() | ||
|
||
loaded_plugin_class_name = type(loaded_plugin_class).__name__ | ||
assert loaded_plugin_class_name == 'CredentialPlugin' | ||
|
||
|
||
assert entry_points['x'].value == 'awx_plugins.credentials.x.api:XPlugin' | ||
@with_inventory_plugins | ||
def test_entry_points_are_inventory_plugin(entry_point: str) -> None: | ||
"""Ensure all exposed inventory plugins are of the same class.""" | ||
entry_points = _discover_entry_points(group=entry_point.group) | ||
loaded_plugin_class = entry_points[entry_point.name].load() | ||
|
||
assert callable(entry_points['x'].load()) | ||
chrismeyersfsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert issubclass(loaded_plugin_class, PluginFileInjector) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few things to say here:
optional-dependencies
rather than unconditional ones.awx
dependency is missing. It should be listed somewhere. Perhaps, in an extra, depending on what's decided above.