Permalink
Browse files

Merge pull request #46 from recena/JENKINS-33318

[JENKINS-33318] GHE server validation with private mode enabled
  • Loading branch information...
recena committed Apr 18, 2016
2 parents 8a607fb + 2a812c2 commit 80a151959a75a0bd7665d39f9c0696ef6a1c988c
@@ -51,7 +51,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-api</artifactId>
<version>1.72.1</version>
<version>1.75</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -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;
@@ -115,14 +116,28 @@ 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");
// 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) {
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, mue.getCause());
return FormValidation.error("The endpoint does not look like a GitHub Enterprise (malformed URL)");
} 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, jpe.getCause());
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("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")) {
LOGGER.log(Level.FINE, e.getMessage());
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 URL");
return FormValidation.error("The endpoint does not look like a GitHub Enterprise (verify network and/or try again later)");
}
}

@@ -1,3 +1,3 @@
<p>
<a href="https://developer.github.com/v3/">GitHub API</a> endpoint such as <code>https://github.example.com/api/v3</code>.
<a href="https://developer.github.com/v3/">GitHub API</a> endpoint such as <code>https://github.example.com/api/v3/</code>.
</p>

0 comments on commit 80a1519

Please sign in to comment.