From f9ab68cb6549d6d08f8660472b9338ce4ff94852 Mon Sep 17 00:00:00 2001 From: mohamedlajmileanix Date: Mon, 7 Oct 2024 10:31:34 +0200 Subject: [PATCH] CID-3000: Switch from app name to slug --- .../net/leanix/githubagent/dto/GitHubAppResponse.kt | 2 +- .../net/leanix/githubagent/runners/PostStartupRunner.kt | 2 +- .../githubagent/services/GitHubEnterpriseService.kt | 2 +- .../githubagent/services/GitHubEnterpriseServiceTest.kt | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/net/leanix/githubagent/dto/GitHubAppResponse.kt b/src/main/kotlin/net/leanix/githubagent/dto/GitHubAppResponse.kt index 167859f..ecb8426 100644 --- a/src/main/kotlin/net/leanix/githubagent/dto/GitHubAppResponse.kt +++ b/src/main/kotlin/net/leanix/githubagent/dto/GitHubAppResponse.kt @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty @JsonIgnoreProperties(ignoreUnknown = true) data class GitHubAppResponse( - @JsonProperty("name") val name: String, + @JsonProperty("slug") val slug: String, @JsonProperty("permissions") val permissions: Map, @JsonProperty("events") val events: List ) diff --git a/src/main/kotlin/net/leanix/githubagent/runners/PostStartupRunner.kt b/src/main/kotlin/net/leanix/githubagent/runners/PostStartupRunner.kt index 9c12a97..5f978d3 100644 --- a/src/main/kotlin/net/leanix/githubagent/runners/PostStartupRunner.kt +++ b/src/main/kotlin/net/leanix/githubagent/runners/PostStartupRunner.kt @@ -36,7 +36,7 @@ class PostStartupRunner( val jwt = cachingService.get("jwtToken") as String webSocketService.sendMessage( APP_NAME_TOPIC, - gitHubEnterpriseService.getGitHubApp(jwt).name + gitHubEnterpriseService.getGitHubApp(jwt).slug ) gitHubScanningService.scanGitHubResources() } diff --git a/src/main/kotlin/net/leanix/githubagent/services/GitHubEnterpriseService.kt b/src/main/kotlin/net/leanix/githubagent/services/GitHubEnterpriseService.kt index c2a031e..d949b07 100644 --- a/src/main/kotlin/net/leanix/githubagent/services/GitHubEnterpriseService.kt +++ b/src/main/kotlin/net/leanix/githubagent/services/GitHubEnterpriseService.kt @@ -20,7 +20,7 @@ class GitHubEnterpriseService(private val githubClient: GitHubClient) { runCatching { val githubApp = getGitHubApp(jwt) validateGithubAppResponse(githubApp) - logger.info("Authenticated as GitHub App: '${githubApp.name}'") + logger.info("Authenticated as GitHub App: '${githubApp.slug}'") }.onFailure { logger.error("Failed to verify JWT token", it) when (it) { diff --git a/src/test/kotlin/net/leanix/githubagent/services/GitHubEnterpriseServiceTest.kt b/src/test/kotlin/net/leanix/githubagent/services/GitHubEnterpriseServiceTest.kt index f3c63a6..e58983d 100644 --- a/src/test/kotlin/net/leanix/githubagent/services/GitHubEnterpriseServiceTest.kt +++ b/src/test/kotlin/net/leanix/githubagent/services/GitHubEnterpriseServiceTest.kt @@ -19,7 +19,7 @@ class GitHubEnterpriseServiceTest { fun `verifyJwt with valid jwt should not throw exception`() { val jwt = "validJwt" val githubApp = GitHubAppResponse( - name = "validApp", + slug = "validApp", permissions = mapOf("administration" to "read", "contents" to "read", "metadata" to "read"), events = listOf("label", "public", "repository") ) @@ -39,7 +39,7 @@ class GitHubEnterpriseServiceTest { @Test fun `validateGithubAppResponse with correct permissions should not throw exception`() { val response = GitHubAppResponse( - name = "validApp", + slug = "validApp", permissions = mapOf("administration" to "read", "contents" to "read", "metadata" to "read"), events = listOf("label", "public", "repository") ) @@ -50,7 +50,7 @@ class GitHubEnterpriseServiceTest { @Test fun `validateGithubAppResponse with missing permissions should throw exception`() { val response = GitHubAppResponse( - name = "validApp", + slug = "validApp", permissions = mapOf("administration" to "read", "contents" to "read"), events = listOf("label", "public", "repository") ) @@ -63,7 +63,7 @@ class GitHubEnterpriseServiceTest { @Test fun `validateGithubAppResponse with missing events should throw exception`() { val response = GitHubAppResponse( - name = "validApp", + slug = "validApp", permissions = mapOf("administration" to "read", "contents" to "read", "metadata" to "read"), events = listOf("label", "public") )