-
Notifications
You must be signed in to change notification settings - Fork 370
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
[JENKINS-33318] GHE server validation with private mode enabled #27
Conversation
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
Thank you for this pull request! Please check this document for how the Jenkins project handles pull requests. |
} catch (MalformedURLException mue) { | ||
return FormValidation.error("This does not look like a GitHub Enterprise API URL"); | ||
// For example: https:/api.github.com | ||
LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri); |
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 would add the exception in the log call
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. 🐛 for the combination of this + JsonParseException both logging the same error message; each should indicate what is wrong in the log line, and the form validation errors should be different.
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.
Suggestions?
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.
For the warning: "Failed trying to configure a GitHub Enterprise server, malformed URL: " + apiUri
For the form error: "This does not look like a GitHub Enterprise API endpoint (malformed URL)"
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.
Sure. I'll do it now.
I added several comments. More broadly, why don't we add the credentials to validate the connection? It seems acceptable to me. |
I guess this code would work, but I agree with Cyrille and Oleg in the But in any case, as mentioned by myself, Jesse, and Patrick in JENKINS-33228, it does not make sense for this plugin to try and reimplement the existing working functionality from |
@orrc please note that my comments and PRs do not imply that I favor an "isolated approach" in the I like the approach of integrating |
@cyrille-leclerc I propose to go forward with this PR. It is not the perfect solution but better than the current validation. In parallel, I offer to work with @KostyaSha on this proposal. |
@recena I'm fine with this plan. 👍 |
Error:
Do not forget to deploy snapshots. |
@jglick Looking for a way to deploy |
@jglick Deployed. |
} catch (FileNotFoundException fnt) { | ||
// For example: https://github.mycompany.com/server/api/v3/ gets a FileNotFoundException | ||
LOGGER.log(Level.WARNING, "Getting HTTP Error 404 for " + apiUri); | ||
return FormValidation.error("This does not look like a GitHub Enterprise API 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.
FormValidation error here also could be more explicit.
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.
Suggestions? Here we want only to validate an GitHub API 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.
There are three scenarios:
- It is a valid URL, for example,
https://api.github.com
orhttps://github.mycompany.com/api/v3/
(with private mode disabled). - It is not a valid URL, for example,
http://www.google.com
,http:/api.github.com
, etc... - It is a GitHub Enterprise server in private mode, hence the form validation can not validate.
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.
Yes, I understood that; each one of these error cases should give a different formvalidation error and a different log message, so that the user/Jenkins administrator knows which thing is the problem. For the 404 case, you just need to say: "This does not look like a GitHub Enterprise API endpoint: page not found (error 404)" + apiUrl
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.
In this case I prefer to keep a more generic message because you can get a 404 due to different reasons. Explanation here.
LOGGER.log(Level.WARNING, e.getMessage()); | ||
return FormValidation.error("This does not look like a GitHub Enterprise API URL"); | ||
return FormValidation.error("This does not look like a GitHub Enterprise API 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.
Again: log why it does not look right.
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 disagree with using verbose validation messages the UI. The Jenkins log file there will be more detailed info.
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 doesn't need to be verbose. Short is fine, but what's the point in showing a validation message in the UI if they don't know why the input is invalid?
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.
@recena That commit addresses the log, but what about the form validation? I feel that may actually be more important, since users are more likely to see it than the logs.
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.
@svanoort This was seen in a real environment 😄
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 trivial, and could be done in less time than it takes to reply to one of these comments.
I prefer to close this PR (motivated to improve the current behavior) before to do something I disagree with.
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.
@recena Sorry if I was not clear:
- For JsonParseException: FormValidation can get the line "Invalid JSON response" - if you want to, you could also add "(possibly wrong endpoint or server issue?)
- For IOException we don't actually do the retry, just suggest the user "verify network and/or try again later" or similar.
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.
As I mentioned before, I disagree with this kind of technical messages. But I'll do it in order to go forward with this PR.
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.
🐝 |
@andresrc Thanks. |
🐝 |
🐝 as of the latest commit. Good to see that we are now returning a reason for validation failure (helpful to user), not just saying it does not look right (not so helpful). |
JENKINS-33318
downstream of hub4j/github-api#251
@reviewbybees