use of org.jboss.pnc.bacon.config.KeycloakConfig in project bacon by project-ncl.
the class PncClientHelper method setup.
public static Configuration setup(boolean authenticationNeeded) {
Config config = Config.instance();
KeycloakConfig keycloakConfig = config.getActiveProfile().getKeycloak();
String bearerToken = "";
if (authenticationNeeded) {
if (keycloakConfig == null) {
throw new FatalException("Keycloak section is needed in the configuration file!");
}
keycloakConfig.validate();
bearerToken = getBearerToken(keycloakConfig);
if (bearerToken == null || bearerToken.isEmpty()) {
throw new FatalException("Credentials don't seem to be valid");
}
}
config.getActiveProfile().getPnc().validate();
String url = config.getActiveProfile().getPnc().getUrl();
try {
URI uri = new URI(url);
Integer port = null;
if (uri.getPort() != -1) {
port = uri.getPort();
}
Configuration configuration = Configuration.builder().protocol(uri.getScheme()).port(port).host(uri.getHost()).bearerToken(bearerToken).pageSize(50).build();
printBannerIfNecessary(configuration);
return configuration;
} catch (URISyntaxException e) {
throw new FatalException("URI syntax issue", e);
}
}
Aggregations