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

Return packages.json if packages/list.json does not exist #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

marioja
Copy link

@marioja marioja commented Mar 21, 2024

If you go to the drupal 7 repository https://packages.drupal.org/7/ you will find that it does not support the packages/list.json url. In that case we just return the packages.json that was returned. This was making retrieving packages.json from a nexus proxy for drupal 7 return a status 500 error.

(brief, plain english overview of your changes here)

instead of failing a get for packages.json from a proxy which does not support the packages/list.json url, this change will instead return the original information from the target repository packages.json response.

This pull request makes the following changes:

  • when requesting packages.json
  • if the target repository does not support the url packages/list.json, return the content from packages.json
  • if the target repository supports the ur packages/list.json, return the information from packages/list.json. This is how previous version (0.0.29 and below) are working

(If there are changes to the UI, please include a screenshot so we
know what to look for!)
no change

(If there are changes to user behavior in general, please make sure to
update the docs, as well)
no change

It relates to the following issue #s:
none

If you go to the drupal 7 repository https://packages.drupal.org/7/ you
will find that it does not support the packages/list.json url.  In that
case we just return the packages.json that was returned.  This was
making retrieving packages.json from a nexus proxy for drupal 7 return a
status 500 error.
In the process to merge the packages json, it was returning a
nullpointerexception when the PROVIDERS_KEY was not found.  Now it will
simply to add the provider to the merged packages json.
@@ -351,7 +351,7 @@ public Content mergePackagesJson(final Repository repository, final List<Payload
for (Payload payload : payloads) {
Map<String, Object> json = parseJson(payload);
Map<String, Object> providers = (Map<String, Object>) json.get(PROVIDERS_KEY);
names.addAll(providers.keySet());
Optional.ofNullable(providers).ifPresent(pv -> names.addAll(pv.keySet()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using a simple old-school but cheap null check instead of creating an Optional instance and an non-static instance lambda?

Suggested change
Optional.ofNullable(providers).ifPresent(pv -> names.addAll(pv.keySet()));
if (providers != null) {
names.addAll(providers.keySet());
}

If you insist on functional style, even this would be more efficient:

Optional.ofNullable(providers).map(Map::keySet).ifPresent(names::addAll);

try {
returnedContent = generatePackagesJson(context);
} catch (NullPointerException e) {
returnedContent=content;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
returnedContent=content;
returnedContent = content;

Copy link
Contributor

Choose a reason for hiding this comment

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

Service the original package.json as cached artifact might work, if the upstream repository uses the same absolute paths, e.g /p2/%package%.json.

Otherwise this pass-through of the original package.json might lead to broken repositories, e.g. proxying packages.drupal.org with a /files/packages/8/p2/%package%.json pattern. This path won't resolve on our Nexus instance.

The URLs should be rewritten in any case.

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.

2 participants