Skip to content

Commit

Permalink
management-service: fixed swagger + webhook links (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
MDybek authored Dec 15, 2024
1 parent 04a56de commit d38a27d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
8 changes: 4 additions & 4 deletions management-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<java.version>21</java.version>
<spring.boot.version>3.4.0</spring.boot.version>
<projectlombok.version>1.18.36</projectlombok.version>
<springdoc.version>2.6.0</springdoc.version>
<springdoc.version>2.7.0</springdoc.version>
<jjwt.version>0.12.6</jjwt.version>
<commonmark.version>0.24.0</commonmark.version>
<slack-api-client.version>1.44.2</slack-api-client.version>
Expand Down Expand Up @@ -94,19 +94,19 @@
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>2.7.0</version>
<version>2.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.auth/google-auth-library-oauth2-http -->
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>1.30.0</version>
<version>1.30.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.http-client/google-http-client-gson -->
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-gson</artifactId>
<version>1.45.1</version>
<version>1.45.3</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -106,18 +104,10 @@ public DiscordReceiver getDiscordReceiver(Long receiverWebhookId) {
}

private String getAnonymizedWebhookUrl(String webhookUrl) {
webhookUrl = confidentialTextEncoder.decrypt(webhookUrl);
String decryptedUrl = confidentialTextEncoder.decrypt(webhookUrl);
int lastSlashIndex = decryptedUrl.lastIndexOf('/');

String[] webhookParts = webhookUrl.split("/");
String authToken = webhookParts[webhookParts.length - 1];

return joinWebhookWithoutAuthToken(webhookParts) + "/" + "*".repeat(authToken.length());
}

private String joinWebhookWithoutAuthToken(String[] webhookParts) {
return Stream.of(webhookParts)
.limit(webhookParts.length - 1)
.collect(Collectors.joining("/"));
return decryptedUrl.substring(0, lastSlashIndex + 1) + "****";
}

private void checkIfWebhookExists(String webhookUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -92,18 +90,10 @@ private void validateWebhookUrl(String webhookUrl) {
}

private String getAnonymizedWebhookUrl(String webhookUrl) {
webhookUrl = confidentialTextEncoder.decrypt(webhookUrl);
String decryptedUrl = confidentialTextEncoder.decrypt(webhookUrl);
int lastSlashIndex = decryptedUrl.lastIndexOf('/');

String[] webhookParts = webhookUrl.split("/");
String authToken = webhookParts[webhookParts.length - 1];

return joinWebhookWithoutAuthToken(webhookParts) + "/" + "*".repeat(authToken.length());
}

private String joinWebhookWithoutAuthToken(String[] webhookParts) {
return Stream.of(webhookParts)
.limit(webhookParts.length - 1)
.collect(Collectors.joining("/"));
return decryptedUrl.substring(0, lastSlashIndex + 1) + "****";
}

public SlackReceiver getById(Long receiverId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DiscordReceiverServiceTest extends Specification {
def "should update discord integration successfully"() {
given:
def id = 1L
def encryptedWebhookUrl = "https://discord.com/api/webhooks/1234554321/********************************************************"
def encryptedWebhookUrl = "https://discord.com/api/webhooks/1234554321/****"
def decryptedWebhookUrl = "https://discord.com/api/webhooks/1234554321/xKh5vF0Som55bSex4q9slwOApmB0VXjcUoVS5Z9v9vu89snl-XeedfHj"
def discordReceiverUpdateRequest = new UpdateDiscordReceiverRequest("Updated Receiver", decryptedWebhookUrl)
def existingReceiver = createDiscordReceiver(id, "Receiver 1", encryptedWebhookUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class SlackReceiverServiceTest extends Specification {
1 * confidentialTextEncoder.decrypt("encryptedUrl1") >> "https://slack.com/receiver1/token1"
1 * confidentialTextEncoder.decrypt("encryptedUrl2") >> "https://slack.com/receiver2/token2"
result.size() == 2
result[0].webhookUrl == "https://slack.com/receiver1/******"
result[1].webhookUrl == "https://slack.com/receiver2/******"
result[0].webhookUrl == "https://slack.com/receiver1/****"
result[1].webhookUrl == "https://slack.com/receiver2/****"
}

def "getEncodedWebhookUrl should return receiver with decoded webhook URL"() {
Expand Down Expand Up @@ -104,7 +104,7 @@ class SlackReceiverServiceTest extends Specification {

then:
receiver.receiverName == "UpdatedReceiver"
receiver.webhookUrl == "https://hooks.slack.com/services/T04PB0Y4K8Q/B07QG098S7M/********************"
receiver.webhookUrl == "https://hooks.slack.com/services/T04PB0Y4K8Q/B07QG098S7M/****"
}

def "addNewSlackIntegration should save new slack integration"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,16 @@ class ReportsServiceTest extends Specification {
def result = reportsService.getApplicationIncidentById(incidentId)

then:
result == Optional.of(applicationIncidentDTO)
result.get().id == applicationIncidentDTO.id
result.get().clusterId == applicationIncidentDTO.clusterId
result.get().applicationName == applicationIncidentDTO.applicationName
result.get().category == applicationIncidentDTO.category
result.get().title == applicationIncidentDTO.title
result.get().summary == applicationIncidentDTO.summary
result.get().accuracy == applicationIncidentDTO.accuracy
result.get().customPrompt == applicationIncidentDTO.customPrompt
result.get().recommendation == applicationIncidentDTO.recommendation
result.get().urgency == applicationIncidentDTO.urgency
}

def "should get node incident by id"() {
Expand All @@ -252,7 +261,16 @@ class ReportsServiceTest extends Specification {
def result = reportsService.getNodeIncidentById(incidentId)

then:
result == Optional.of(nodeIncidentDTO)
result.get().id == nodeIncidentDTO.id
result.get().clusterId == nodeIncidentDTO.clusterId
result.get().nodeName == nodeIncidentDTO.nodeName
result.get().category == nodeIncidentDTO.category
result.get().title == nodeIncidentDTO.title
result.get().summary == nodeIncidentDTO.summary
result.get().accuracy == nodeIncidentDTO.accuracy
result.get().customPrompt == nodeIncidentDTO.customPrompt
result.get().recommendation == nodeIncidentDTO.recommendation
result.get().urgency == nodeIncidentDTO.urgency
}

private ReportGenerationRequestMetadata createReportGenerationRequestMetadata(String correlationId, ReportGenerationStatus status, String clusterId, long sinceMs, long toMs) {
Expand Down

0 comments on commit d38a27d

Please sign in to comment.