Skip to content

Commit

Permalink
Merge pull request #5 from mcanoy/disable
Browse files Browse the repository at this point in the history
Allow Sonar to start if plugin fails.
  • Loading branch information
mcanoy authored Sep 17, 2019
2 parents fd05639 + 7ad3ac3 commit aff25e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.DS_Store
target/
example/apply.rety
example/apply.retry
example/roles
example/sonar-auth-openshift-plugin-*.jar
.project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.concurrent.ExecutionException;
import java.io.File;
Expand Down Expand Up @@ -39,6 +40,7 @@ public class OpenShiftIdentityProvider implements OAuth2IdentityProvider {

public static final String KEY = "openshift";
private String todoCallback = "";
private boolean initializedOpenshift = true;

private final OpenShiftScribeApi scribeApi;
private final OpenShiftConfiguration config;
Expand All @@ -49,28 +51,42 @@ public OpenShiftIdentityProvider(OpenShiftConfiguration config, OpenShiftScribeA
this.config = config;
this.scribeApi = scribeApi;

try {
if(isEnabled()) {
initOpenShift();
} else {
LOGGER.info("AuthOpenShiftPlugin is disabled");
}
} catch (Exception ex) {
initializedOpenshift = false;
LOGGER.severe("AuthOpenShiftPlugin failed to initialize. Disabling...");
}

LOGGER.fine("OpenShift API " + scribeApi.toString());
}

private void initOpenShift() throws Exception {

try {
setKeystore();
} catch (Exception ex) {
LOGGER.severe("Problem setting up ssl");
throw new IllegalStateException("Problem setting up ssl", ex);
LOGGER.log(Level.SEVERE, "Problem setting up ssl", ex);
throw ex;
}

try {
getServiceAccountName();
} catch (Exception ex) {
LOGGER.severe("Problem getting service account");
throw new IllegalStateException("Problem getting service account", ex);
LOGGER.log(Level.SEVERE, "Problem getting service account", ex);
throw ex;
}

try {
todoCallback = this.callbackBaseUrl();
} catch (Exception ex) {
LOGGER.severe("Problem getting callback url (base on pod's service");
throw new IllegalStateException("Problem getting callback url", ex);
LOGGER.log(Level.SEVERE, "Problem getting callback url (based on pod's service)", ex);
throw ex;
}

LOGGER.fine("OpenShift API " + scribeApi.toString());
}

@Override
Expand All @@ -91,7 +107,7 @@ public Display getDisplay() {

@Override
public boolean isEnabled() {
return config.isEnabled();
return initializedOpenshift && config.isEnabled();
}

@Override
Expand All @@ -109,7 +125,7 @@ public void init(InitContext context) {
LOGGER.fine("Redirect:" + url);
context.redirectTo(url);
} catch (IOException e) {
LOGGER.severe(String.format("Unable to read/write client id and/or client secret from service account.%n"));
LOGGER.severe("Unable to read/write client id and/or client secret from service account.");
throw new IllegalStateException("Unable to complete init", e);
}
}
Expand Down Expand Up @@ -185,7 +201,7 @@ private String callbackBaseUrl() throws IOException {
OAuth2AccessToken token = new OAuth2AccessToken(config.getClientSecret());

OAuthRequest request = new OAuthRequest(Verb.GET, config.getRouteURL(config.getNamespace()));
LOGGER.info("URL--->" + request.getUrl());
LOGGER.info("Route URL: " + request.getUrl());
scribe.signRequest(token, request);
Response response;
try {
Expand Down

0 comments on commit aff25e1

Please sign in to comment.