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

Build collections URL according to requirements.yml #353

Merged
merged 1 commit into from
Sep 8, 2020
Merged

Build collections URL according to requirements.yml #353

merged 1 commit into from
Sep 8, 2020

Conversation

fao89
Copy link
Member

@fao89 fao89 commented Sep 2, 2020

@fao89 fao89 requested a review from a team September 2, 2020 20:34
@pulpbot
Copy link
Member

pulpbot commented Sep 2, 2020

Attached issue: https://pulp.plan.io/issues/7412

@fao89 fao89 marked this pull request as ready for review September 3, 2020 17:45
@fao89 fao89 requested a review from bmbouter September 3, 2020 17:45
@bmbouter
Copy link
Member

bmbouter commented Sep 3, 2020

@fao89 I looked at this problem and I think we should do something like this: https://pulp.plan.io/issues/7412#note-5 instead. wdyt?

result = re.findall(r"/v(\d)/collections", url)
if not result:
raise serializers.ValidationError(
_("Invalid URL {url}".format(url=data["url"]))
Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't think a better error message

Copy link
Member

Choose a reason for hiding this comment

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

Maybe Inavlid URL {url}. Ensure the URL ends in either '/v2/collections/' or '/v3/collections/'.

@fao89
Copy link
Member Author

fao89 commented Sep 3, 2020

@fao89 I looked at this problem and I think we should do something like this: https://pulp.plan.io/issues/7412#note-5 instead. wdyt?

this is much better now, thank you!

@@ -132,7 +133,18 @@ def validate(self, data):
data = super().validate(data)

if data.get("requirements_file"):
parse_collections_requirements_file(data["requirements_file"])
parsed_file = parse_collections_requirements_file(data["requirements_file"])
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused, I didn't think we would be validating the requirements file since it doesn't contain urls typically. https://docs.ansible.com/ansible/devel/galaxy/user_guide.html#install-multiple-collections-with-a-requirements-file

I thought when a requirements file is being used, the remote.url would be validated.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm validating source which is a URL

@@ -82,7 +82,7 @@
collections:
- name: testing.ansible_testing_content
version: ">=1.0.0,<=2.0.0"
source: https://galaxy-dev.ansible.com
source: https://galaxy-dev.ansible.com/api/v2/collections
Copy link
Member Author

Choose a reason for hiding this comment

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

@bmbouter see this URL would break

@@ -324,7 +324,7 @@ def _get_url(page, api_version):
name, version, source = collection_info[page - 1]
namespace, name = name.split(".")
root = source or remote.url
url = f"{root}/api/v2/collections/{namespace}/{name}"
url = f"{root}/{namespace}/{name}"
Copy link
Member Author

Choose a reason for hiding this comment

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

it picks source or the remote.url, so I had to validate it

Copy link
Member

Choose a reason for hiding this comment

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

I see how this correctly handles the case of forming the url for the requirements file, but in the case of no requirements file, where does it form those urls from?

Copy link
Member Author

Choose a reason for hiding this comment

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

if it does not have a requirements file, it does not fall on this if

Copy link
Member

Choose a reason for hiding this comment

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

Cool, so to confirm, we are able to form the right urls when not using a requirements file?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, we are, we have lots of tests doing that

@fao89 fao89 requested a review from bmbouter September 8, 2020 14:52
urls_to_validate.append(source)

for url in urls_to_validate:
result = re.findall(r"/v(\d)/collections", url)
Copy link
Member

Choose a reason for hiding this comment

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

What do we do about the optional trailing slash or not? I think we either need to require it or not, but not allow both.

Copy link
Member

Choose a reason for hiding this comment

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

Also what about cases where it's something like /something/api/v2/collection/more/stuff/v2/collectionmine/. This would also validate. So I think validating at the end is key.

Copy link
Member

@bmbouter bmbouter Sep 8, 2020

Choose a reason for hiding this comment

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

So maybe this check would instead be:

if url.endswith('/v2/collections/) or url.endswith('/v3/collections/):

or possibly if url.endswith('/v2/collections) or url.endswith('/v3/collections')` depending on how the trailing slash is handled.

Copy link
Member

@bmbouter bmbouter left a comment

Choose a reason for hiding this comment

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

This looks right to me, thanks @fao89 !

@fao89 fao89 merged commit 22aa73b into pulp:master Sep 8, 2020
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

3 participants