Skip to content

Commit

Permalink
add more useful error messages for OpenShift
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed May 23, 2021
1 parent 60b3057 commit f57890a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Master (unreleased)
* \[test\] Run tests against Java 11 [#30](https://github.com/jenkinsci/kubernetes-credentials-plugin/pull/30)
* use Secret instead of String for sensitive data [#31](https://github.com/jenkinsci/kubernetes-credentials-plugin/pull/31)
* change minimal Jenkins version for 2.222.1 LTS [42edb2ef](https://github.com/jenkinsci/kubernetes-credentials-plugin/commit/42edb2efffb1415f055975667f351f13ed8f4642)
* make OpenshiftBearerToken errors more helpful [#32](https://github.com/jenkinsci/kubernetes-credentials-plugin/pull/32)

0.8.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -103,12 +106,18 @@ public String getToken(String apiServerURL, String caCertData, boolean skipTlsVe
if (token == null || System.currentTimeMillis() > token.expire) {
try {
token = refreshToken(apiServerURL, caCertData, skipTlsVerify);
} catch (ClientProtocolException e) {
throw new IOException("Can't parse protocol in the OAuth server URL ('" + apiServerURL + "')", e);
} catch (HttpClientWithTLSOptionsFactory.TLSConfigurationError e) {
throw new IOException("Could not configure SSL Factory in HttpClientWithTLSOptionsFactory: " + e.getMessage(), e);
} catch (URISyntaxException e) {
throw new IOException("The OAuth server URL was invalid ('" + apiServerURL + "'): " + e.getMessage(), e);
} catch (HttpHostConnectException e) {
throw new IOException("Can't connect to the OAuth server ('" + apiServerURL + "'): " + e.getMessage(), e);
} catch (TokenResponseError e) {
throw new IOException("The response from the OAuth server was invalid: " + e.getMessage(), e);
} catch (UnknownHostException e) {
throw new IOException("Can't resolve OAuth server hostname ('" + apiServerURL + "'): " + e.getMessage(), e);
} catch (URISyntaxException e) {
throw new IOException("The OAuth server URL was invalid ('" + apiServerURL + "'): " + e.getMessage(), e);
}

this.tokenCache.put(apiServerURL, token);
Expand Down

0 comments on commit f57890a

Please sign in to comment.