use of org.jboss.pnc.client.Configuration 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);
}
}
use of org.jboss.pnc.client.Configuration in project bacon by project-ncl.
the class DaHelper method getAuthenticatedClient.
private static ResteasyWebTarget getAuthenticatedClient() {
ResteasyWebTarget target = getClient();
Configuration pncConfiguration = PncClientHelper.getPncConfiguration();
target.register(new TokenAuthenticator(pncConfiguration.getBearerToken()));
return target;
}
use of org.jboss.pnc.client.Configuration in project pnc by project-ncl.
the class BuildEndpointTest method shouldFailGetAllWithLargePage.
@Test
public void shouldFailGetAllWithLargePage() throws RemoteResourceException {
final Configuration clientConfig = RestClientConfiguration.asAnonymous();
Configuration largePageConfig = Configuration.builder().basicAuth(clientConfig.getBasicAuth()).bearerToken(clientConfig.getBearerToken()).host(clientConfig.getHost()).pageSize(MAX_PAGE_SIZE + 1).port(clientConfig.getPort()).protocol(clientConfig.getProtocol()).build();
BuildClient client = new BuildClient(largePageConfig);
assertThatThrownBy(() -> client.getAll(null, null)).hasCauseInstanceOf(BadRequestException.class);
}
Aggregations