Skip to content

Commit

Permalink
Add client configuration api endpoint
Browse files Browse the repository at this point in the history
fixes #740
  • Loading branch information
newswangerd authored and mdellweg committed Sep 15, 2022
1 parent 0e26381 commit a4424fd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES/740.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Implement v3/plugin/client-configuration/ endpoint to communicate to the ansible galaxy client
which distribution to use.
6 changes: 6 additions & 0 deletions pulp_ansible/app/galaxy/v3/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,9 @@ class RepoMetadataSerializer(serializers.ModelSerializer):
class Meta:
fields = ("published",)
model = RepositoryVersion


class ClientConfigurationSerializer(serializers.Serializer):
"""Configuration settings for the ansible-galaxy client."""

default_distribution_path = serializers.CharField(allow_null=True)
21 changes: 21 additions & 0 deletions pulp_ansible/app/galaxy/v3/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
CollectionVersionListSerializer,
RepoMetadataSerializer,
UnpaginatedCollectionVersionSerializer,
ClientConfigurationSerializer,
)
from pulp_ansible.app.models import (
AnsibleCollectionDeprecated,
Expand Down Expand Up @@ -981,3 +982,23 @@ def update(self, request, *args, **kwargs):
return self._get(request, *args, **kwargs)

return GeneratedRedirectView.as_view(actions, url=url)


class ClientConfigurationView(views.APIView):
"""Return configurations for the ansible-galaxy client."""

DEFAULT_ACCESS_POLICY = _PERMISSIVE_ACCESS_POLICY

@extend_schema(responses=ClientConfigurationSerializer)
def get(self, request, *args, **kwargs):
"""Get the client configs."""

data = ClientConfigurationSerializer(
{
"default_distribution_path": self.kwargs.get(
"path", settings.ANSIBLE_DEFAULT_DISTRIBUTION_PATH
)
}
)

return Response(data.data)
5 changes: 5 additions & 0 deletions pulp_ansible/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@
views_v3.CollectionImportViewSet.as_view({"get": "retrieve"}),
name="collection-imports-detail",
),
path(
"client-configuration/",
views_v3.ClientConfigurationView.as_view(),
name="client-configuration-viewset",
),
]

v3_urls = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
def test_client_config_distro(
ansible_repo, ansible_distribution_factory, ansible_client_configuration_api_client
):
distro = ansible_distribution_factory(ansible_repo)
res = ansible_client_configuration_api_client.get(path=distro.base_path)
assert res.default_distribution_path == distro.base_path


def test_client_config_default_distro(
ansible_repo, ansible_distribution_factory, ansible_client_default_configuration_api_client
):
res = ansible_client_default_configuration_api_client.get()
assert res.default_distribution_path is None
14 changes: 14 additions & 0 deletions pulp_ansible/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
RemotesCollectionApi,
RemotesGitApi,
RemotesRoleApi,
PulpAnsibleApiV3PluginAnsibleClientConfigurationApi,
PulpAnsibleDefaultApiV3PluginAnsibleClientConfigurationApi,
)


Expand All @@ -39,6 +41,18 @@ def ansible_collections_api_client(ansible_bindings_client):
return AnsibleCollectionsApi(ansible_bindings_client)


@pytest.fixture
def ansible_client_configuration_api_client(ansible_bindings_client):
"""Provides the Ansible Collections API client object."""
return PulpAnsibleApiV3PluginAnsibleClientConfigurationApi(ansible_bindings_client)


@pytest.fixture
def ansible_client_default_configuration_api_client(ansible_bindings_client):
"""Provides the Ansible Collections API client object."""
return PulpAnsibleDefaultApiV3PluginAnsibleClientConfigurationApi(ansible_bindings_client)


@pytest.fixture
def ansible_collection_signatures_client(ansible_bindings_client):
"""Provides the Ansible Collection Signatures API client object."""
Expand Down

0 comments on commit a4424fd

Please sign in to comment.