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

[JENKINS-33318] GHE server validation with private mode enabled #27

Merged
merged 8 commits into from
Apr 18, 2016

Conversation

recena
Copy link
Contributor

@recena recena commented Mar 5, 2016

JENKINS-33318

downstream of hub4j/github-api#251

@reviewbybees

@ghost
Copy link

ghost commented Mar 5, 2016

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.

@jenkinsadmin
Copy link
Member

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);
Copy link
Contributor

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

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggestions?

Copy link
Member

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)"

Copy link
Contributor Author

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.

@cyrille-leclerc
Copy link
Contributor

I added several comments. More broadly, why don't we add the credentials to validate the connection? It seems acceptable to me.

@orrc
Copy link
Member

orrc commented Mar 6, 2016

I guess this code would work, but I agree with Cyrille and Oleg in the github-api PR that the GitHub server check looks too fragile.

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 github-plugin.

@cyrille-leclerc
Copy link
Contributor

@orrc please note that my comments and PRs do not imply that I favor an "isolated approach" in the github-branch-source-plugin instead of integrating github-branch-source-plugin with github-plugin .

I like the approach of integrating github-branch-source-plugin with github-plugin as you and @KostyaSha have suggested in GitHub server configuration undocumented / duplicated but I also wanted to fix the existing "weakness" waiting for the long term fix.

@recena recena closed this Mar 6, 2016
@recena recena reopened this Mar 7, 2016
@recena
Copy link
Contributor Author

recena commented Mar 7, 2016

@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.

@cyrille-leclerc
Copy link
Contributor

@recena I'm fine with this plan. 👍

@jglick
Copy link
Member

jglick commented Mar 7, 2016

Error:

Could not resolve dependencies for project org.jenkins-ci.plugins:github-branch-source:hpi:1.4-SNAPSHOT: Could not find artifact org.kohsuke:github-api:jar:1.74-SNAPSHOT in repo.jenkins-ci.org

Do not forget to deploy snapshots.

@recena recena closed this Mar 7, 2016
@recena recena reopened this Mar 7, 2016
@recena
Copy link
Contributor Author

recena commented Mar 7, 2016

@jglick Looking for a way to deploy org.kohsuke:github-api:jar:1.74-SNAPSHOT

@recena recena closed this Mar 7, 2016
@recena recena reopened this Mar 7, 2016
@recena
Copy link
Contributor Author

recena commented Mar 7, 2016

@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");
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

@recena recena Apr 18, 2016

Choose a reason for hiding this comment

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

There are three scenarios:

  1. It is a valid URL, for example, https://api.github.com or https://github.mycompany.com/api/v3/ (with private mode disabled).
  2. It is not a valid URL, for example, http://www.google.com, http:/api.github.com, etc...
  3. It is a GitHub Enterprise server in private mode, hence the form validation can not validate.

Copy link
Member

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

Copy link
Contributor Author

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");
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@svanoort Addressed e32e694

Copy link
Member

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.

Copy link
Contributor Author

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 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@svanoort

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@svanoort Your comments were addressed here. Note I changed the message in order to get sentences shorter.

@andresrc
Copy link

🐝

@recena
Copy link
Contributor Author

recena commented Apr 18, 2016

@andresrc Thanks.

@andresrc
Copy link

🐝

@svanoort
Copy link
Member

🐝 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).

@recena recena merged commit af04b02 into jenkinsci:master Apr 18, 2016
@recena recena deleted the JENKINS-33318 branch April 18, 2016 15:37
@recena recena restored the JENKINS-33318 branch April 18, 2016 15:40
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.

8 participants