Skip to content

Commit

Permalink
Revert "fix(slack): Fix Slack callback handling"
Browse files Browse the repository at this point in the history
This reverts commit db018a9.
  • Loading branch information
osoriano committed Sep 20, 2023
1 parent 7ec9211 commit fee0d81
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 396 deletions.
1 change: 0 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ testContainersVersion=1.15.3
okHttpVersion=4.5.0
resilience4jVersion=1.5.0
spinnakerGradleVersion=8.23.0
slackSdkVersion=1.12.1

# Used to control whether to spin up docker to run liquibase before jooq
buildingInDocker=false
Expand Down
6 changes: 3 additions & 3 deletions keel-notifications/keel-notifications.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ dependencies {
implementation(project(":keel-network"))
implementation("org.springframework.boot:spring-boot-autoconfigure")

implementation("com.slack.api:slack-api-model-kotlin-extension:${slackSdkVersion}")
implementation("com.slack.api:slack-api-client-kotlin-extension:${slackSdkVersion}")
implementation("com.slack.api:bolt:${slackSdkVersion}")
implementation("com.slack.api:slack-api-model-kotlin-extension:1.4.1")
implementation("com.slack.api:slack-api-client-kotlin-extension:1.4.1")
implementation("com.slack.api:bolt:1.6.0")

testImplementation("dev.minutest:minutest")
testImplementation("io.strikt:strikt-core")
Expand Down
10 changes: 4 additions & 6 deletions keel-web/keel-web.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
plugins {
id "application"
id "com.github.hauner.jarTest" version "1.0.1"
id("application")
}

apply plugin: "com.netflix.dgs.codegen"
apply plugin: "io.spinnaker.package"
apply plugin: "com.github.hauner.jarTest"
apply(plugin: "com.netflix.dgs.codegen")
apply(plugin: "io.spinnaker.package")

repositories {
mavenCentral() // for graphql-java-extended-scalars
Expand Down Expand Up @@ -48,7 +46,7 @@ dependencies {
implementation("io.swagger.core.v3:swagger-annotations:2.1.2")
implementation("org.apache.maven:maven-artifact:3.6.3")
implementation("io.spinnaker.kork:kork-plugins")
implementation("com.slack.api:bolt-servlet:${slackSdkVersion}")
implementation("com.slack.api:bolt-servlet:1.6.0")
implementation("com.graphql-java:graphql-java-extended-scalars:16.0.1")

// DGS dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ import org.springframework.context.annotation.Configuration
@Configuration
@ConditionalOnProperty(name = ["keel.security.custom"], havingValue = "false", matchIfMissing = true)
@EnableFiatAutoConfig
class DefaultSecurityConfiguration
class SecurityConfiguration

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.netflix.spinnaker.keel.rest

import com.netflix.spinnaker.keel.notifications.slack.callbacks.CommitModalCallbackHandler
import com.netflix.spinnaker.keel.notifications.slack.callbacks.ManualJudgmentCallbackHandler
import com.slack.api.app_backend.interactive_components.payload.BlockActionPayload
import com.slack.api.bolt.App
import com.slack.api.bolt.context.builtin.ActionContext
import com.slack.api.bolt.request.builtin.BlockActionRequest
import com.slack.api.bolt.servlet.SlackAppServlet
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
import javax.servlet.annotation.WebServlet


@Component
@WebServlet("/slack/notifications/callbacks")
/**
* New endpoint for the new slack integration. This will be called from gate directly instead of echo.
* We use Slack Bolt library (https://github.com/slackapi/java-slack-sdk/), which has a native support for handling callbacks from slack.
*/
class SlackAppController(
slackApp: App,
private val mjHandler: ManualJudgmentCallbackHandler,
private val commitModalCallbackHandler: CommitModalCallbackHandler,
) : SlackAppServlet(slackApp) {

private val log by lazy { LoggerFactory.getLogger(javaClass) }

init {
// The pattern here should match the action id field in the actual button.
// for example, for manual judgment notifications: constraintId:OVERRIDE_PASS:MANUAL_JUDGMENT
val actionIdPattern = "^(\\w+):(\\w+):(\\w+)".toPattern()
slackApp.blockAction(actionIdPattern) { req: BlockActionRequest, ctx: ActionContext ->
if (req.payload.notificationType == "MANUAL_JUDGMENT") {
log.info(logMessage("'manual judgment' button clicked", req))
mjHandler.respondToButton(req, ctx)
} else if (req.payload.notificationType == "FULL_COMMIT_MODAL") {
log.info(logMessage("'show full commit' button clicked", req))
commitModalCallbackHandler.openModal(req, ctx)
} else if (req.payload.actions.first().actionId == "button:url:mj-diff-link") {
log.info(logMessage("'see changes' button clicked", req))
} else {
log.debug(logMessage("Unrecognized action", req))
}
// we always need to acknowledge the button within 3 seconds
ctx.ack()
}
}

fun logMessage(what: String, req: BlockActionRequest) =
"[slack interaction] $what by ${req.payload.user.username} (${req.payload.user.id}) " +
"in channel ${req.payload.channel.name} (${req.payload.channel.id})"

//action id is consistent of 3 parts, where the last part is the type
val BlockActionPayload.notificationType
get() = actions.first().actionId.split(":").last()
}

This file was deleted.

Loading

0 comments on commit fee0d81

Please sign in to comment.