Skip to content

Commit ef77c00

Browse files
Merge pull request #129 from leanix/feature/CID-3854/allow-the-user-to-trigger-a-full-scan-from-leanix-workspace
CID-3854: Allow user to trigger a full scan from LeanIX
2 parents d693372 + 39cc41c commit ef77c00

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/main/kotlin/net/leanix/githubagent/handler/BrokerStompSessionHandler.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class BrokerStompSessionHandler(
1717
private val artifactDownloadHandler: ArtifactDownloadHandler,
1818
private val repositoryGetHandler: RepositoryGetHandler,
1919
private val installationGetHandler: InstallationGetHandler,
20+
private val fullScanHandler: FullScanHandler,
2021
private val eventPublisher: ApplicationEventPublisher
2122
) : StompSessionHandlerAdapter() {
2223
@Lazy
@@ -33,6 +34,7 @@ class BrokerStompSessionHandler(
3334
session.subscribe("/user/queue/message/artifact", artifactDownloadHandler)
3435
session.subscribe("/user/queue/message/repository", repositoryGetHandler)
3536
session.subscribe("/user/queue/message/installation", installationGetHandler)
37+
session.subscribe("/user/queue/message/fullScan", fullScanHandler)
3638
eventPublisher.publishEvent(ConnectionEstablishedEvent())
3739
}
3840

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package net.leanix.githubagent.handler
2+
3+
import net.leanix.githubagent.services.CachingService
4+
import net.leanix.githubagent.services.GitHubStartService
5+
import org.slf4j.LoggerFactory
6+
import org.springframework.beans.factory.annotation.Autowired
7+
import org.springframework.beans.factory.annotation.Value
8+
import org.springframework.context.annotation.Lazy
9+
import org.springframework.messaging.simp.stomp.StompFrameHandler
10+
import org.springframework.messaging.simp.stomp.StompHeaders
11+
import org.springframework.stereotype.Component
12+
import java.lang.reflect.Type
13+
14+
@Component
15+
class FullScanHandler(
16+
@Lazy @Autowired
17+
private val cachingService: CachingService,
18+
@Lazy @Autowired
19+
private val gitHubStartService: GitHubStartService,
20+
@Value("\${webhookEventService.waitingTime}") private val waitingTime: Long,
21+
) : StompFrameHandler {
22+
23+
private val logger = LoggerFactory.getLogger(FullScanHandler::class.java)
24+
25+
override fun getPayloadType(headers: StompHeaders): Type {
26+
return MessagePayload::class.java
27+
}
28+
29+
override fun handleFrame(headers: StompHeaders, payload: Any?) {
30+
logger.info("Received full scan request")
31+
runCatching {
32+
while (cachingService.get("runId") != null) {
33+
logger.info("A full scan is already in progress, waiting for it to finish.")
34+
Thread.sleep(waitingTime)
35+
}
36+
GitHubStartService.requireScan = true
37+
gitHubStartService.verifyAndStartScan()
38+
}
39+
}
40+
}
41+
42+
data class MessagePayload(val message: String)

src/main/kotlin/net/leanix/githubagent/services/GitHubStartService.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ class GitHubStartService(
1616
private val cachingService: CachingService,
1717
private val syncLogService: SyncLogService
1818
) {
19-
var requireScan = true
19+
companion object {
20+
var requireScan: Boolean = true
21+
}
2022

2123
@SuppressWarnings("UnusedParameter")
2224
@Async
2325
@EventListener
2426
fun startAgent(connectionEstablishedEvent: ConnectionEstablishedEvent) {
27+
verifyAndStartScan()
28+
}
29+
30+
fun verifyAndStartScan() {
2531
if (requireScan) {
2632
runCatching {
2733
requireScan = false

0 commit comments

Comments
 (0)