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
New endpoint returning all collections unpaginated #488
Conversation
Attached issue: https://pulp.plan.io/issues/7940 Attached issue: https://pulp.plan.io/issues/7941 |
CHANGES/7941.feature
Outdated
@@ -0,0 +1,2 @@ | |||
Introduce a new ``v3/metadata/<str:namespace>/<str:name>/versions/`` endpoint returning |
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.
Is this what it actually does? I though for 7941 it would list an unpaginated view of all CollectionVersions, but it would be v3/metadata/collection_versions/
not v3/metadata/<str:namespace>/<str:name>/versions/
.
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 was unsure about this endpoint,
if it was all collections versions for a given collection, or all collection versions.
So I coded the first approach, thinking I had to mimic what we already have but unpaginated.
I'll work on it and change the endpoint!
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.
Thank you!
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.
This changelog entry needs updating.
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.
requested change to the implementation of metadata/collection_versions/
.
86e0fa4
to
cffd018
Compare
artifact = ContentArtifact.objects.get(content=instance) | ||
|
||
context = self.get_serializer_context() | ||
context["content_artifact"] = artifact |
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.
@bmbouter CollectionVersionViewSet
only presented artifact
data on retrieve
, so the strategy was getting the ContentArtifact
and injecting it into the context.
For UnpaginatedCollectionVersionViewSet
we need to present artifact
data on list
, so I changed the query to select related ContentArtifact
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.
This is pretty slick. 👍
serializer = CollectionVersionSerializer(page, many=True, context=context) | ||
return self.get_paginated_response(serializer.data) | ||
|
||
serializer = CollectionVersionSerializer(queryset, many=True, context=context) |
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.
the original endpoint for collections versions don't show all info we need for the unpaginated one:
{
"meta":{
"count":1
},
"links":{
"first":"/api/automation-hub/v3/collections/vmware/vmware_rest/versions/?limit=10&offset=0",
"previous":null,
"next":null,
"last":"/api/automation-hub/v3/collections/vmware/vmware_rest/versions/?limit=10&offset=0"
},
"data":[
{
"version":"1.0.1",
"href":"/api/automation-hub/v3/collections/vmware/vmware_rest/versions/1.0.1/",
"created_at":"2020-10-09T23:10:13.142203Z",
"updated_at":"2020-10-09T23:10:13.142234Z"
}
]
}
vs
[{
"version": "string",
"href": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"artifact": "string",
"collection": {
"id": "string",
"name": "string",
"href": "string"
},
"download_url": "string",
"name": "string",
"namespace": {
"name": "string"
},
"metadata": {
"authors": [],
"contents": {},
"dependencies": {},
"description": "string",
"documentation": "string",
"homepage": "string",
"issues": "string",
"license": [],
"repository": "string",
"tags": []
}
},
...,
{
"version": "string",
"href": "string",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"artifact": "string",
"collection": {
"id": "string",
"name": "string",
"href": "string"
},
"download_url": "string",
"name": "string",
"namespace": {
"name": "string"
},
"metadata": {
"authors": [],
"contents": {},
"dependencies": {},
"description": "string",
"documentation": "string",
"homepage": "string",
"issues": "string",
"license": [],
"repository": "string",
"tags": []
}
}]
So I use the CollectionVersionSerializer
instead of CollectionVersionListSerializer
, and CollectionVersionSerializer
needs the ContentArtifact
to get artifact
data
@@ -182,15 +182,15 @@ def get_artifact(self, obj): | |||
""" | |||
Get atrifact summary. | |||
""" | |||
return ArtifactRefSerializer(self.context["content_artifact"]).data | |||
return ArtifactRefSerializer(obj.contentartifact_set.first()).data |
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.
Since this is replacing the removed line artifact = ContentArtifact.objects.get(content=instance)
I think this could be
return ArtifactRefSerializer(obj.contentartifact_set.first()).data | |
return ArtifactRefSerializer(obj.contentartifact_set.get()).data |
|
||
def get_download_url(self, obj) -> str: | ||
""" | ||
Get artifact download URL. | ||
""" | ||
host = settings.ANSIBLE_CONTENT_HOSTNAME.strip("/") | ||
distro_base_path = self.context["path"] | ||
filename_path = self.context["content_artifact"].relative_path.lstrip("/") | ||
filename_path = obj.contentartifact_set.first().relative_path.lstrip("/") |
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.
Similar here to above ^
CHANGES/7940.feature
Outdated
@@ -0,0 +1 @@ | |||
Introduce a new ``v3/metadata/collections/`` endpoint returning all collections unpaginated |
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.
nitpick:
Introduce a new ``v3/metadata/collections/`` endpoint returning all collections unpaginated | |
Introduces a new ``v3/metadata/collections/`` endpoint returning all collections unpaginated. |
CHANGES/7941.feature
Outdated
Introduce a new ``v3/metadata/collection_versions/`` endpoint returning all collections versions | ||
unpaginated |
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.
niptick:
Introduce a new ``v3/metadata/collection_versions/`` endpoint returning all collections versions | |
unpaginated | |
Introduces a new ``v3/metadata/collection_versions/`` endpoint returning all collections versions | |
unpaginated. |
So I've been testing this PR and it's working great. I'm strugglng to remember why we made two endpoints though.... @fao89 do you remember? |
I realize we need deprecation status, and collection_versions endpoint does not provide it |
https://pulp.plan.io/issues/7941 closes #7941 (cherry picked from commit 0db524e)
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.
Thank you!
https://pulp.plan.io/issues/7940
closes #7940