Skip to content

Commit

Permalink
CID-2776: addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedlajmileanix committed Aug 6, 2024
1 parent 4e332af commit 58618dd
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ class GitHubWebhookController(private val webhookService: WebhookService) {
@RequestBody payload: String
) {
runCatching {
logger.info("Received a GitHub event of type $eventType")
if (SUPPORTED_EVENT_TYPES.contains(eventType.uppercase())) {
webhookService.consumeWebhookEvent(eventType, payload)
} else {
logger.warn("Event type not supported")
logger.warn("Received an unsupported event of type: $eventType")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PostStartupRunner(

override fun run(args: ApplicationArguments?) {
webSocketService.initSession()
githubAuthenticationService.generateJwtToken()
githubAuthenticationService.generateAndCacheJwtToken()
gitHubScanningService.scanGitHubResources()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class GitHubAuthenticationService(
}

fun refreshTokens() {
generateJwtToken()
generateAndCacheJwtToken()
val jwtToken = cachingService.get("jwtToken")
generateAndCacheInstallationTokens(
gitHubClient.getInstallations("Bearer $jwtToken"),
jwtToken.toString()
)
}

fun generateJwtToken() {
fun generateAndCacheJwtToken() {
runCatching {
logger.info("Generating JWT token")
Security.addProvider(BouncyCastleProvider())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class WebhookService(
when (eventType.uppercase()) {
"PUSH" -> handlePushEvent(payload)
else -> {
logger.debug("Sending event of type: $eventType")
logger.info("Sending event of type: $eventType")
webSocketService.sendMessage("/events/other", payload)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GitHubAuthenticationServiceTest {
every { resourceLoader.getResource(any()) } returns ClassPathResource("valid-private-key.pem")
every { gitHubEnterpriseService.verifyJwt(any()) } returns Unit

assertDoesNotThrow { githubAuthenticationService.generateJwtToken() }
assertDoesNotThrow { githubAuthenticationService.generateAndCacheJwtToken() }
assertNotNull(cachingService.get("jwtToken"))
}

Expand All @@ -44,6 +44,6 @@ class GitHubAuthenticationServiceTest {
every { githubEnterpriseProperties.pemFile } returns "invalid-private-key.pem"
every { resourceLoader.getResource(any()) } returns ClassPathResource("invalid-private-key.pem")

assertThrows(IllegalArgumentException::class.java) { githubAuthenticationService.generateJwtToken() }
assertThrows(IllegalArgumentException::class.java) { githubAuthenticationService.generateAndCacheJwtToken() }
}
}

0 comments on commit 58618dd

Please sign in to comment.