-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Migrates [Nexus] service to new service model #2520
Conversation
|
|
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.
Thanks so much for this!
services/nexus/nexus.service.js
Outdated
const LegacyService = require('../legacy-service') | ||
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data') | ||
const BaseJsonService = require('../base-json') | ||
const Joi = require('joi') | ||
const { isSnapshotVersion: isNexusSnapshotVersion } = require('./nexus-version') |
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.
Not necessary for this PR, though for future reference I've been trying to remove these renames as services are rewritten. (The renames are legacy too.)
services/nexus/nexus.service.js
Outdated
}) | ||
const json = await this._requestJson(requestParams) | ||
if (json.data.length === 0) { | ||
return this.constructor.render({ version: 'no-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.
This is not really a version, it's an error. Maybe it would be better to handle this by throwing either NotFound
or InvalidResponse
with a custom prettyMessage
.
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.
Agreed. This is the part I was referencing in my comment above on the Joi schema (not adding a min(1)
) to maintain consistency with the existing implementation.
A NotFound
seems like the most logical error to me. Sounds like I can throw that with a custom message of no-artifact
to maintain the same behavior (which currently is nexus | no-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.
It seems like a strangely formatted message; feel free to change it.
services/nexus/nexus.service.js
Outdated
message = versionText(version) | ||
color = versionColor(version) | ||
} else { | ||
message = 'undefined' |
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 seems like an invalid response. Could it be handled with Joi instead? ^^
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 honestly don't know on this one (relying on the LegacyService implementation) 😄
Based on a quick mental walkthrough of the Legacy implementation, I think this could happen under two circumstances:
- snapshot badge is requested, but the specified group/artifact has no snapshot versions.
- repository badge is requested, response has no value for
baseVersion
field (which I am assuming can/does happen in real life based on this line from the legacy service), nor does the response have a value for theversion
field.
The first one feels a lot like the above scenario where throwing NotFound
could be used. It could be covered with a schema (although it would get a little complex), but I think a pretty message conveying no snapshot versions found
might be more helpful for the user than invalid
. Thoughts?
The second one would be much more manageable with Joi than the first IMO, but I'm not sure what Nexus guarantees in the response. For example is baseVersion
optional while version
is guaranteed? Or is it that one value is guaranteed, but it could be either version
or baseVersion
, or neither?
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'm familiar with what Nexus is, but haven't used it, so I'm gonna have to think about this when I'm a little fresher. If anyone else has another opinion meanwhile, please feel free to respond!
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 added some links below to the Neuxs API docs, but they didn't offer much assistance IMO. I updated the service impl. to throw InvalidResponse
errors in each of those 2 circumstances while leaving the Joi schema a bit more flexible
services/nexus/nexus.service.js
Outdated
if (repo === 'r') { | ||
version = json.data[0].latestRelease | ||
} else if (repo === 's') { | ||
json.data.every(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.
This is fine, though for future reference you should know about another pattern we use, which is transform
. If you delegate this part of the responsibility to a transform
method, you can use a for
loop with a return
statement which is easier to read.
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 was another copy/paste from the original implementation. I'm not familiar with transform
but happy to optimize!
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 an example of the transform
you are referring to?
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.
Yea, that's a good example. We should probably link that from the service-rewriting docs if there isn't already an example of a transform()
function.
options.qs.v = 'LATEST' | ||
} | ||
|
||
if (queryOpt) { |
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.
It's not obvious from reading this what it's supposed to do. For future reference, stuff like this probably should be its own static method (or function) with a unit test.
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.
Good idea. The original implementation was plugging the query params directly into the url
, but that was a lot more readable.
I'll extract this out into its own function with a comment. 🤦♂️ on the test. Not sure how I forgot that one!
}) | ||
) | ||
|
||
t.create('search release version of an inexistent artifact') | ||
t.create('live: search release version of an inexistent 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.
This comes up a lot. Maybe we should add something to the test runner which includes [mock]
next to all the ones which use mocks (or vice versa).
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.
Makes sense. I saw the live:
prefix convention somewhere the other day and started using it too without thinking about it.
Thanks for the feedback! I think I fixed each of the line items but let me know if I missed any |
services/nexus/nexus.service.js
Outdated
}) | ||
} | ||
|
||
getRequestParams({ repo, scheme, host, groupId, artifactId, queryOpt }) { |
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 probably would be a bit more direct if it invoked _requestJson
and was renamed to fetch
. "Fetch" is another pattern we use a lot.
services/nexus/nexus.service.js
Outdated
} | ||
|
||
if (!version) { | ||
throw new InvalidResponse({ prettyMessage: 'invalid artifact version' }) |
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.
It's not necessary to change this, though if you move the error-checking bit back to handle()
, you can use return
statements above.
r: 'fs-public-snapshots', | ||
v: 'LATEST', | ||
c: 'agent-apple-osx', | ||
p: 'tar.gz', |
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.
👍
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.
All looks good!
Only thing that needs more discussion is this item: #2520 (comment)
I can't find anything definitive in the Nexus API docs (for 2.x) on the response formats either: On the On the |
Thanks! This was a beast! |
Ports the Nexus service to the new service model. Some related/relevant conversation in #2347 (and closes #2347). Also adds support for authentication which resolves #1699
I also added some thoughts/comments inline