From e2c88a505f349e226b1a28c3a69a4793dcf15702 Mon Sep 17 00:00:00 2001 From: Chad Elliott Date: Mon, 3 Feb 2025 09:55:11 -0600 Subject: [PATCH 1/2] Combine the notifications and pulse-response configurations into a single slack configuration. --- .../configuration/CheckInsConfiguration.java | 47 ++++--------------- .../social_media/SlackPoster.java | 5 +- .../social_media/SlackSearch.java | 4 +- .../pulseresponse/PulseSlackCommand.java | 1 - .../pulseresponse/SlackSignatureVerifier.java | 1 - server/src/main/resources/application.yml | 12 ++--- 6 files changed, 18 insertions(+), 52 deletions(-) diff --git a/server/src/main/java/com/objectcomputing/checkins/configuration/CheckInsConfiguration.java b/server/src/main/java/com/objectcomputing/checkins/configuration/CheckInsConfiguration.java index f8e8d7f92..d29dedbe8 100644 --- a/server/src/main/java/com/objectcomputing/checkins/configuration/CheckInsConfiguration.java +++ b/server/src/main/java/com/objectcomputing/checkins/configuration/CheckInsConfiguration.java @@ -32,10 +32,7 @@ public static class ApplicationConfig { private GoogleApiConfig googleApi; @NotNull - private NotificationsConfig notifications; - - @NotNull - private PulseResponseConfig pulseResponse; + private SlackConfig slack; @Getter @Setter @@ -75,42 +72,16 @@ public static class ScopeConfig { @Getter @Setter - @ConfigurationProperties("notifications") - public static class NotificationsConfig { - - @NotNull - private SlackConfig slack; - - @Getter - @Setter - @ConfigurationProperties("slack") - public static class SlackConfig { - @NotBlank - private String webhookUrl; - - @NotBlank - private String botToken; - } - } - - @Getter - @Setter - @ConfigurationProperties("pulse-response") - public static class PulseResponseConfig { - - @NotNull - private SlackConfig slack; + @ConfigurationProperties("slack") + public static class SlackConfig { + @NotBlank + private String webhookUrl; - @Getter - @Setter - @ConfigurationProperties("slack") - public static class SlackConfig { - @NotBlank - private String signingSecret; + @NotBlank + private String botToken; - @NotBlank - private String botToken; - } + @NotBlank + private String signingSecret; } } } diff --git a/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackPoster.java b/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackPoster.java index be08f13e1..b1839f649 100644 --- a/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackPoster.java +++ b/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackPoster.java @@ -21,8 +21,9 @@ public class SlackPoster { private CheckInsConfiguration configuration; public HttpResponse post(String slackBlock) { - // See if we can have a webhook URL. - String slackWebHook = configuration.getApplication().getNotifications().getSlack().getWebhookUrl(); + // See if we have a webhook URL. + String slackWebHook = configuration.getApplication() + .getSlack().getWebhookUrl(); if (slackWebHook != null) { // POST it to Slack. BlockingHttpClient client = slackClient.toBlocking(); diff --git a/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackSearch.java b/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackSearch.java index 526fdf6a0..38bed736e 100644 --- a/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackSearch.java +++ b/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackSearch.java @@ -32,7 +32,7 @@ public SlackSearch(CheckInsConfiguration checkInsConfiguration) { } public String findChannelId(String channelName) { - String token = configuration.getApplication().getNotifications().getSlack().getBotToken(); + String token = configuration.getApplication().getSlack().getBotToken(); if (token != null) { try { MethodsClient client = Slack.getInstance().methods(token); @@ -57,7 +57,7 @@ public String findChannelId(String channelName) { } public String findUserId(String userEmail) { - String token = configuration.getApplication().getNotifications().getSlack().getBotToken(); + String token = configuration.getApplication().getSlack().getBotToken(); if (token != null) { try { MethodsClient client = Slack.getInstance().methods(token); diff --git a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseSlackCommand.java b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseSlackCommand.java index 439de89da..1c48eb30b 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseSlackCommand.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/PulseSlackCommand.java @@ -35,7 +35,6 @@ public boolean send(String triggerId) { // See if we have a token. String token = configuration.getApplication() - .getPulseResponse() .getSlack().getBotToken(); if (token != null && !slackBlocks.isEmpty()) { MethodsClient client = Slack.getInstance().methods(token); diff --git a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/SlackSignatureVerifier.java b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/SlackSignatureVerifier.java index c9be9ed27..2d95c33bd 100644 --- a/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/SlackSignatureVerifier.java +++ b/server/src/main/java/com/objectcomputing/checkins/services/pulseresponse/SlackSignatureVerifier.java @@ -30,7 +30,6 @@ public boolean verifyRequest(String slackSignature, String timestamp, String req // Generate HMAC-SHA256 signature String secret = configuration.getApplication() - .getPulseResponse() .getSlack().getSigningSecret(); String computedSignature = "v0=" + hmacSha256(secret, baseString); diff --git a/server/src/main/resources/application.yml b/server/src/main/resources/application.yml index 72d611518..469d84a58 100755 --- a/server/src/main/resources/application.yml +++ b/server/src/main/resources/application.yml @@ -97,14 +97,10 @@ check-ins: feedback: max-suggestions: 6 request-subject: "Feedback request" - notifications: - slack: - webhook-url: ${ SLACK_WEBHOOK_URL } - bot-token: ${ SLACK_BOT_TOKEN } - pulse-response: - slack: - signing-secret: ${ SLACK_PULSE_SIGNING_SECRET } - bot-token: ${ SLACK_PULSE_BOT_TOKEN } + slack: + webhook-url: ${ SLACK_WEBHOOK_URL } + bot-token: ${ SLACK_BOT_TOKEN } + signing-secret: ${ SLACK_SIGNING_SECRET } web-address: ${ WEB_ADDRESS } --- flyway: From 824e5bdaeeaf9f79a48c5a3e83da85ec94bb7836 Mon Sep 17 00:00:00 2001 From: Chad Elliott Date: Tue, 4 Feb 2025 14:54:08 -0600 Subject: [PATCH 2/2] Switch to the new configuration. --- .../notifications/social_media/SlackSearch.java | 2 +- .../pulseresponse/PulseResponseControllerTest.java | 1 - server/src/test/resources/application-test.yml | 12 ++++-------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackSearch.java b/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackSearch.java index 1d5e6881d..e7fbb6fed 100644 --- a/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackSearch.java +++ b/server/src/main/java/com/objectcomputing/checkins/notifications/social_media/SlackSearch.java @@ -80,7 +80,7 @@ public String findUserId(String userEmail) { } public String findUserEmail(String userId) { - String token = configuration.getApplication().getNotifications().getSlack().getBotToken(); + String token = configuration.getApplication().getSlack().getBotToken(); if (token != null) { try { MethodsClient client = Slack.getInstance().methods(token); diff --git a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java index fa7d0c0b5..c4d94aa70 100644 --- a/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java +++ b/server/src/test/java/com/objectcomputing/checkins/services/pulseresponse/PulseResponseControllerTest.java @@ -556,7 +556,6 @@ void testCreateAPulseResponseFromSlack() { private String slackSignature(String timestamp, String rawBody) { String baseString = "v0:" + timestamp + ":" + rawBody; String secret = configuration.getApplication() - .getPulseResponse() .getSlack().getSigningSecret(); try { diff --git a/server/src/test/resources/application-test.yml b/server/src/test/resources/application-test.yml index c5aca006c..132a9b1a6 100644 --- a/server/src/test/resources/application-test.yml +++ b/server/src/test/resources/application-test.yml @@ -41,14 +41,10 @@ check-ins: application: google-api: delegated-user: test@objectcomputing.com - notifications: - slack: - webhook-url: https://bogus.objectcomputing.com/slack - bot-token: BOGUS_TOKEN - pulse-response: - slack: - signing-secret: BOGUS_SIGNING_SECRET - bot-token: BOGUS_TOKEN + slack: + webhook-url: https://bogus.objectcomputing.com/slack + bot-token: BOGUS_TOKEN + signing-secret: BOGUS_SIGNING_SECRET --- aes: key: BOGUS_TEST_KEY