Skip to content

Commit

Permalink
Merge pull request #63 from leanix/feature/CID-3381/Validate-LEANIX_D…
Browse files Browse the repository at this point in the history
…OMAIN-and-LEANIX_TECHNICAL_USER_TOKEN-presence

CID-3381: Validate Env variables presence
  • Loading branch information
mohamedlajmileanix authored Dec 19, 2024
2 parents 7f6cdcf + 88b7366 commit e6eef63
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package net.leanix.githubagent.config

import jakarta.annotation.PostConstruct
import net.leanix.githubagent.exceptions.GitHubEnterpriseConfigurationMissingException
import org.springframework.context.event.ContextRefreshedEvent
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

@Component
class AgentSetupValidation(
private val gitHubEnterpriseProperties: GitHubEnterpriseProperties
private val gitHubEnterpriseProperties: GitHubEnterpriseProperties,
private val leanIXProperties: LeanIXProperties
) {

@PostConstruct
fun validateConfiguration() {
@EventListener
@SuppressWarnings("UnusedParameter")
fun onApplicationEvent(event: ContextRefreshedEvent) {
val missingProperties = mutableListOf<String>()

if (gitHubEnterpriseProperties.baseUrl.isBlank()) {
Expand All @@ -23,6 +26,14 @@ class AgentSetupValidation(
missingProperties.add("GITHUB_ENTERPRISE_PEM_FILE")
}

if (leanIXProperties.wsBaseUrl.isBlank()) {
missingProperties.add("LEANIX_WS_BASE_URL")
}

if (leanIXProperties.auth.accessTokenUri.isBlank()) {
missingProperties.add("LEANIX_AUTH_ACCESS_TOKEN_URI")
}

if (missingProperties.isNotEmpty()) {
throw GitHubEnterpriseConfigurationMissingException(missingProperties.joinToString(", "))
}
Expand Down

0 comments on commit e6eef63

Please sign in to comment.