Skip to content

Commit

Permalink
CID-1829: minor fixes and revert change to InitialStateRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedlajmileanix committed Aug 29, 2023
1 parent ad6f670 commit 1661e85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import net.leanix.vsm.gitlab.broker.connector.domain.GitLabAssignment
import net.leanix.vsm.gitlab.broker.shared.exception.VsmException
import org.springframework.stereotype.Component
import java.net.URLEncoder
import java.nio.charset.StandardCharsets

@Component
class ValidationService(
Expand All @@ -16,7 +17,7 @@ class ValidationService(
val orgName = gitLabAssignment.connectorConfiguration.orgName
runCatching {
validateUserAccess()
validateOrgName(gitLabAssignment.connectorConfiguration.orgName)
validateOrgName(orgName)
}.onSuccess {
logInfoMessages("vsm.configuration.validation.successful", arrayOf(orgName), gitLabAssignment)
}.onFailure { exception ->
Expand All @@ -33,7 +34,7 @@ class ValidationService(

private fun validateOrgName(orgName: String) {
runCatching {
gitlabClientProvider.getOrg(URLEncoder.encode(orgName, "UTF-8"))
gitlabClientProvider.getOrg(URLEncoder.encode(orgName, StandardCharsets.UTF_8.toString()))
}.onFailure {
throw VsmException.OrgNameValidationFailed()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.leanix.vsm.gitlab.broker.connector.runner

import net.leanix.vsm.gitlab.broker.connector.application.AssignmentService
import net.leanix.vsm.gitlab.broker.connector.application.ValidationService
import net.leanix.vsm.gitlab.broker.shared.cache.AssignmentsCache
import net.leanix.vsm.gitlab.broker.webhook.domain.WebhookService
import org.slf4j.Logger
Expand All @@ -13,26 +12,24 @@ import org.springframework.stereotype.Component
@Component
class InitialStateRunner(
private val assignmentService: AssignmentService,
private val validationService: ValidationService,
private val webhookService: WebhookService
) : ApplicationRunner {

private val logger: Logger = LoggerFactory.getLogger(InitialStateRunner::class.java)

override fun run(args: ApplicationArguments?) {
logger.info("Started to get initial state")
fetchAndValidateAssignments()
fetchAssignments()
setupWebhook()
}

private fun fetchAndValidateAssignments() {
private fun fetchAssignments() {
runCatching {
assignmentService.getAssignments()?.forEach { assignment ->
logger.info(
"Received assignment for ${assignment.connectorConfiguration.orgName} " +
"with configuration id: ${assignment.configurationId} and with run id: ${assignment.runId}"
)
validationService.validateConfiguration(assignment)
}
}.onSuccess {
logger.info("Cached ${AssignmentsCache.getAll().size} assignments")
Expand Down

0 comments on commit 1661e85

Please sign in to comment.