Search in sources :

Example 1 with KeycloakConfig

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);
    }
}
Also used : Configuration(org.jboss.pnc.client.Configuration) FatalException(org.jboss.pnc.bacon.common.exception.FatalException) KeycloakConfig(org.jboss.pnc.bacon.config.KeycloakConfig) Config(org.jboss.pnc.bacon.config.Config) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) KeycloakConfig(org.jboss.pnc.bacon.config.KeycloakConfig)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 FatalException (org.jboss.pnc.bacon.common.exception.FatalException)1 Config (org.jboss.pnc.bacon.config.Config)1 KeycloakConfig (org.jboss.pnc.bacon.config.KeycloakConfig)1 Configuration (org.jboss.pnc.client.Configuration)1