use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class UpdateChecker method getUpdateModel.
public UpdateModel getUpdateModel() {
IntHttpClient intHttpClient = createHttpClient();
DockerTagRetriever dockerTagRetriever = new DockerTagRetriever(gson, intHttpClient);
Optional<AboutModel> aboutModel = aboutReader.getAboutModel();
String currentVersion = aboutModel.map(AboutModel::getVersion).orElse(null);
String alertCreated = aboutModel.map(AboutModel::getCreated).orElse(null);
boolean isProduction = isProductionVersion(currentVersion);
Optional<VersionDateModel> latestAvailableVersion = getLatestAvailableTag(dockerTagRetriever, isProduction);
String repositoryUrl = dockerTagRetriever.getRepositoryUrl();
// latestAvailableVersion will not be present if Alert can not reach Docker Hub and DockerTagRetriever will log a warning
// if latestAvailableVersion is empty, use the Alert version and date so we report no update available
String latestVersion = latestAvailableVersion.map(VersionDateModel::getVersionName).orElse(currentVersion);
String latestDate = latestAvailableVersion.map(VersionDateModel::getDate).orElse(alertCreated);
return getUpdateModel(currentVersion, alertCreated, latestVersion, latestDate, repositoryUrl);
}
use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class MSTeamsChannelMessageSender method sendMessages.
@Override
public MessageResult sendMessages(MSTeamsJobDetailsModel msTeamsJobDetailsModel, List<MSTeamsChannelMessageModel> channelMessages) throws AlertException {
String webhook = msTeamsJobDetailsModel.getWebhook();
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
List<Request> messageRequests = channelMessages.stream().map(this::createJsonString).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
restChannelUtility.sendMessage(messageRequests, msTeamsKey.getUniversalKey());
return new MessageResult(String.format("Successfully sent %d MSTeams message(s)", channelMessages.size()));
}
use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method createMockHttpClientWithResponse.
private IntHttpClient createMockHttpClientWithResponse(Response response) throws IntegrationException {
IntHttpClient intHttpClient = Mockito.mock(IntHttpClient.class);
Mockito.when(intHttpClient.execute(Mockito.any(Request.class))).thenReturn(response);
return intHttpClient;
}
use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method sendMessageRuntimeExceptionTest.
@Test
public void sendMessageRuntimeExceptionTest() throws IntegrationException {
IntHttpClient intHttpClient = Mockito.mock(IntHttpClient.class);
Mockito.when(intHttpClient.execute(Mockito.any(Request.class))).thenThrow(new IllegalStateException("Something is wrong"));
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
try {
restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
fail("Expected an exception to be thrown");
} catch (AlertException e) {
// Pass
}
}
use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class ChannelRestConnectionFactoryTest method testConnectionFields.
@Test
void testConnectionFields() {
String baseUrl = "https://example-base-url";
final String host = "host";
final int port = 1;
CredentialsBuilder builder = Credentials.newBuilder();
builder.setUsername("username");
builder.setPassword("password");
Credentials credentials = builder.build();
ProxyInfoBuilder proxyBuilder = ProxyInfo.newBuilder();
proxyBuilder.setHost(host);
proxyBuilder.setPort(port);
proxyBuilder.setCredentials(credentials);
proxyBuilder.setNtlmDomain(null);
proxyBuilder.setNtlmWorkstation(null);
ProxyInfo expectedProxyInfo = proxyBuilder.build();
MockAlertProperties testAlertProperties = new MockAlertProperties();
testAlertProperties.setAlertTrustCertificate(true);
ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
Mockito.when(proxyManager.createProxyInfoForHost(baseUrl)).thenReturn(expectedProxyInfo);
ChannelRestConnectionFactory channelRestConnectionFactory = new ChannelRestConnectionFactory(testAlertProperties, proxyManager, gson);
IntHttpClient intHttpClient = channelRestConnectionFactory.createIntHttpClient(baseUrl);
assertNotNull(intHttpClient);
assertEquals(expectedProxyInfo, intHttpClient.getProxyInfo());
}
Aggregations