From fad71a54a45c28b8daacc3e336ff5eaa6a8a6a5b Mon Sep 17 00:00:00 2001 From: Manuel Recena Date: Sat, 5 Mar 2016 23:17:49 +0100 Subject: [PATCH 1/7] [JENKINS-33318] GHE server validation with private mode enabled --- pom.xml | 3 ++- .../plugins/github_branch_source/Endpoint.java | 17 +++++++++++++---- .../github_branch_source/GitHubSCMSource.java | 1 - .../Endpoint/help-apiUri.html | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 7e53dd472..9241513ee 100644 --- a/pom.xml +++ b/pom.xml @@ -48,9 +48,10 @@ + org.jenkins-ci.plugins github-api - 1.71 + 1.74-SNAPSHOT org.jenkins-ci.plugins diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java index 46dbfae3a..87e56546c 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java @@ -115,14 +115,23 @@ public FormValidation doCheckApiUri(@QueryParameter String apiUri) { URL api = new URL(apiUri); GitHub github = GitHub.connectToEnterpriseAnonymously(api.toString()); github.checkApiUrlValidity(); - return FormValidation.ok(); + LOGGER.log(Level.FINE, "Trying to configure a GitHub Enterprise server"); + return FormValidation.ok("GitHub Enterprise server verified"); } 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); + return FormValidation.error("This does not look like a GitHub Enterprise API endpoint"); } catch (JsonParseException jpe) { - return FormValidation.error("This does not look like a GitHub Enterprise API URL"); + LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri); + return FormValidation.error("This does not look like a GitHub Enterprise API endpoint"); } catch (IOException e) { + if (e.getMessage().contains("private mode enabled")) { + LOGGER.log(Level.FINE, "Trying to configure a GitHub Enterprise server with private mode enabled"); + return FormValidation.ok("GitHub Enterprise server verified"); + } + // For example: https://github.mycompany.com/api gets a FileNotFoundException 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"); } } diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java index 8f8e1be87..fe375f4b7 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java @@ -417,7 +417,6 @@ public FormValidation doCheckScanCredentialsId(@AncestorInPath SCMSourceOwner co return FormValidation.error("Invalid credentials"); } } catch (IOException e) { - // ignore, never thrown LOGGER.log(Level.WARNING, "Exception validating credentials " + CredentialsNameProvider.name(credentials) + " on " + apiUri); return FormValidation.error("Exception validating credentials"); } diff --git a/src/main/resources/org/jenkinsci/plugins/github_branch_source/Endpoint/help-apiUri.html b/src/main/resources/org/jenkinsci/plugins/github_branch_source/Endpoint/help-apiUri.html index 5520c511f..72fce8569 100644 --- a/src/main/resources/org/jenkinsci/plugins/github_branch_source/Endpoint/help-apiUri.html +++ b/src/main/resources/org/jenkinsci/plugins/github_branch_source/Endpoint/help-apiUri.html @@ -1,3 +1,3 @@

- GitHub API endpoint such as https://github.example.com/api/v3. + GitHub API endpoint such as https://github.example.com/api/v3/.

\ No newline at end of file From 074859900436a9b1b2d425737f164f9053e91087 Mon Sep 17 00:00:00 2001 From: recena Date: Mon, 18 Apr 2016 15:35:34 +0200 Subject: [PATCH 2/7] [JENKINS-33318] Reviewed --- .../plugins/github_branch_source/Endpoint.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java index 87e56546c..240bd0621 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java @@ -31,6 +31,7 @@ import hudson.model.Descriptor; import hudson.util.FormValidation; +import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; @@ -124,12 +125,16 @@ public FormValidation doCheckApiUri(@QueryParameter String apiUri) { } catch (JsonParseException jpe) { LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri); return FormValidation.error("This does not look like a GitHub Enterprise API endpoint"); + } 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"); } catch (IOException e) { + // For example: https://github.mycompany.com/api/v3/ or https://github.mycompany.com/api/v3/mypath if (e.getMessage().contains("private mode enabled")) { - LOGGER.log(Level.FINE, "Trying to configure a GitHub Enterprise server with private mode enabled"); - return FormValidation.ok("GitHub Enterprise server verified"); + LOGGER.log(Level.FINE, e.getMessage()); + return FormValidation.warning("Private mode enabled, validation disabled"); } - // For example: https://github.mycompany.com/api gets a FileNotFoundException LOGGER.log(Level.WARNING, e.getMessage()); return FormValidation.error("This does not look like a GitHub Enterprise API endpoint"); } From 643c7cd60ae48c4781ebaf17b5ad7bcafe1c06f8 Mon Sep 17 00:00:00 2001 From: recena Date: Mon, 18 Apr 2016 15:47:09 +0200 Subject: [PATCH 3/7] [JENKINS-33318] Added a comment --- .../org/jenkinsci/plugins/github_branch_source/Endpoint.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java index 240bd0621..df40a9eb1 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java @@ -117,6 +117,7 @@ public FormValidation doCheckApiUri(@QueryParameter String apiUri) { GitHub github = GitHub.connectToEnterpriseAnonymously(api.toString()); github.checkApiUrlValidity(); LOGGER.log(Level.FINE, "Trying to configure a GitHub Enterprise server"); + // For example: https://api.github.com/ or https://github.mycompany.com/api/v3/ (with private mode disabled). return FormValidation.ok("GitHub Enterprise server verified"); } catch (MalformedURLException mue) { // For example: https:/api.github.com From e32e6946dde44fe66f6b14fc54e764c88ddb3489 Mon Sep 17 00:00:00 2001 From: recena Date: Mon, 18 Apr 2016 15:59:52 +0200 Subject: [PATCH 4/7] [JENKINS-33318] @svanoort's comment was addressed --- .../jenkinsci/plugins/github_branch_source/Endpoint.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java index df40a9eb1..ea6cfb267 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java @@ -121,10 +121,10 @@ public FormValidation doCheckApiUri(@QueryParameter String apiUri) { return FormValidation.ok("GitHub Enterprise server verified"); } catch (MalformedURLException mue) { // For example: https:/api.github.com - LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri); - return FormValidation.error("This does not look like a GitHub Enterprise API endpoint"); + LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri, mue.getCause()); + return FormValidation.error("This does not look like a GitHub Enterprise API endpoint (malformed URL)"); } catch (JsonParseException jpe) { - LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri); + LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri, jpe.getCause()); return FormValidation.error("This does not look like a GitHub Enterprise API endpoint"); } catch (FileNotFoundException fnt) { // For example: https://github.mycompany.com/server/api/v3/ gets a FileNotFoundException From 6f511f42b44a8b6da99c5e17b32fea2662990424 Mon Sep 17 00:00:00 2001 From: recena Date: Mon, 18 Apr 2016 16:13:09 +0200 Subject: [PATCH 5/7] [JENKINS-33318] @svanoort's comment was addressed --- .../org/jenkinsci/plugins/github_branch_source/Endpoint.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java index ea6cfb267..339dd66b6 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java @@ -129,7 +129,7 @@ public FormValidation doCheckApiUri(@QueryParameter String apiUri) { } 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"); + return FormValidation.error("This does not look like a GitHub Enterprise API endpoint (page not found"); } catch (IOException e) { // For example: https://github.mycompany.com/api/v3/ or https://github.mycompany.com/api/v3/mypath if (e.getMessage().contains("private mode enabled")) { From c990cdf59531616b7dd343b02eb6aa9338cc44ee Mon Sep 17 00:00:00 2001 From: recena Date: Mon, 18 Apr 2016 16:34:13 +0200 Subject: [PATCH 6/7] [JENKINS-33318] Reverted a modified line --- .../jenkinsci/plugins/github_branch_source/GitHubSCMSource.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java index 5a9ae2c5c..ebc3ca48c 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMSource.java @@ -468,6 +468,7 @@ public FormValidation doCheckScanCredentialsId(@AncestorInPath SCMSourceOwner co return FormValidation.error("Invalid credentials"); } } catch (IOException e) { + // ignore, never thrown LOGGER.log(Level.WARNING, "Exception validating credentials " + CredentialsNameProvider.name(credentials) + " on " + apiUri); return FormValidation.error("Exception validating credentials"); } From 2fab60db66f3d6335825172803e5d4dbd76c6542 Mon Sep 17 00:00:00 2001 From: recena Date: Mon, 18 Apr 2016 17:28:28 +0200 Subject: [PATCH 7/7] [JENKINS-33318] @svanoort's comment was addressed --- .../jenkinsci/plugins/github_branch_source/Endpoint.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java index 339dd66b6..07f07dd0c 100644 --- a/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java +++ b/src/main/java/org/jenkinsci/plugins/github_branch_source/Endpoint.java @@ -122,14 +122,14 @@ public FormValidation doCheckApiUri(@QueryParameter String apiUri) { } catch (MalformedURLException mue) { // For example: https:/api.github.com LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri, mue.getCause()); - return FormValidation.error("This does not look like a GitHub Enterprise API endpoint (malformed URL)"); + return FormValidation.error("The endpoint does not look like a GitHub Enterprise (malformed URL)"); } catch (JsonParseException jpe) { LOGGER.log(Level.WARNING, "Trying to configure a GitHub Enterprise server: " + apiUri, jpe.getCause()); - return FormValidation.error("This does not look like a GitHub Enterprise API endpoint"); + return FormValidation.error("The endpoint does not look like a GitHub Enterprise (invalid JSON response)"); } 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 (page not found"); + return FormValidation.error("The endpoint does not look like a GitHub Enterprise (page not found"); } catch (IOException e) { // For example: https://github.mycompany.com/api/v3/ or https://github.mycompany.com/api/v3/mypath if (e.getMessage().contains("private mode enabled")) { @@ -137,7 +137,7 @@ public FormValidation doCheckApiUri(@QueryParameter String apiUri) { return FormValidation.warning("Private mode enabled, validation disabled"); } LOGGER.log(Level.WARNING, e.getMessage()); - return FormValidation.error("This does not look like a GitHub Enterprise API endpoint"); + return FormValidation.error("The endpoint does not look like a GitHub Enterprise (verify network and/or try again later)"); } }