diff --git a/src/main/kotlin/xquare/app/xquareinfra/domain/container/application/service/UpdateEnvironmentVariableService.kt b/src/main/kotlin/xquare/app/xquareinfra/domain/container/application/service/UpdateEnvironmentVariableService.kt index 2b9e4d1..ae01595 100644 --- a/src/main/kotlin/xquare/app/xquareinfra/domain/container/application/service/UpdateEnvironmentVariableService.kt +++ b/src/main/kotlin/xquare/app/xquareinfra/domain/container/application/service/UpdateEnvironmentVariableService.kt @@ -40,7 +40,7 @@ class UpdateEnvironmentVariableService( container.updateEnvironmentVariable(environmentVariable) - val path = "${deploy.deployName}-${deploy.deployType.name}-${container.containerEnvironment.name}" + val path = vaultUtil.getPath(deploy, container) vaultUtil.addSecret(environmentVariable, path) val namespace = "${deploy.team.teamNameEn}-${container.containerEnvironment.name}" diff --git a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/ApproveDeployService.kt b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/ApproveDeployService.kt index 4bbff0c..c61d52c 100644 --- a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/ApproveDeployService.kt +++ b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/ApproveDeployService.kt @@ -8,13 +8,15 @@ import xquare.app.xquareinfra.domain.deploy.application.port.`in`.ApproveDeployU import xquare.app.xquareinfra.domain.deploy.application.port.out.FindDeployPort import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException import xquare.app.xquareinfra.infrastructure.exception.XquareException +import xquare.app.xquareinfra.infrastructure.vault.VaultUtil @Transactional @Service class ApproveDeployService( @Value("\${secret.projectSecret}") private val accessKey: String, - private val findDeployPort: FindDeployPort + private val findDeployPort: FindDeployPort, + private val vaultUtil: VaultUtil ): ApproveDeployUseCase { override fun approveDeploy(deployNameEn: String, req: ApproveDeployRequest) { @@ -24,5 +26,10 @@ class ApproveDeployService( val deploy = findDeployPort.findByDeployName(deployNameEn) ?: throw BusinessLogicException.DEPLOY_NOT_FOUND deploy.updateSecret(req.secretKey) deploy.approveDeploy() + + val path = vaultUtil.getPath(deploy) + path.forEach { + vaultUtil.addSecret(mapOf("init" to "Please delete this variable"), it) + } } } \ No newline at end of file diff --git a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/CreateDeployService.kt b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/CreateDeployService.kt index 0bb289b..b1a442d 100644 --- a/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/CreateDeployService.kt +++ b/src/main/kotlin/xquare/app/xquareinfra/domain/deploy/application/service/CreateDeployService.kt @@ -14,6 +14,7 @@ import xquare.app.xquareinfra.domain.team.application.port.out.FindTeamPort import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException import xquare.app.xquareinfra.infrastructure.feign.client.deploy.DeployClient import xquare.app.xquareinfra.infrastructure.feign.client.deploy.dto.request.FeignCreateDeployRequest +import xquare.app.xquareinfra.infrastructure.vault.VaultUtil import java.util.* @Transactional diff --git a/src/main/kotlin/xquare/app/xquareinfra/infrastructure/vault/VaultUtil.kt b/src/main/kotlin/xquare/app/xquareinfra/infrastructure/vault/VaultUtil.kt index 4e0a3af..c0091b5 100644 --- a/src/main/kotlin/xquare/app/xquareinfra/infrastructure/vault/VaultUtil.kt +++ b/src/main/kotlin/xquare/app/xquareinfra/infrastructure/vault/VaultUtil.kt @@ -1,6 +1,12 @@ package xquare.app.xquareinfra.infrastructure.vault +import xquare.app.xquareinfra.domain.container.domain.Container +import xquare.app.xquareinfra.domain.deploy.domain.Deploy + interface VaultUtil { fun addSecret(secrets: Map, path: String) // fun revoke(path: String) + + fun getPath(deploy: Deploy, container: Container): String + fun getPath(deploy: Deploy): List } \ No newline at end of file diff --git a/src/main/kotlin/xquare/app/xquareinfra/infrastructure/vault/VaultUtilImpl.kt b/src/main/kotlin/xquare/app/xquareinfra/infrastructure/vault/VaultUtilImpl.kt index 9d541a1..e2b26e2 100644 --- a/src/main/kotlin/xquare/app/xquareinfra/infrastructure/vault/VaultUtilImpl.kt +++ b/src/main/kotlin/xquare/app/xquareinfra/infrastructure/vault/VaultUtilImpl.kt @@ -2,6 +2,8 @@ package xquare.app.xquareinfra.infrastructure.vault import com.bettercloud.vault.Vault import org.springframework.stereotype.Service +import xquare.app.xquareinfra.domain.container.domain.Container +import xquare.app.xquareinfra.domain.deploy.domain.Deploy import xquare.app.xquareinfra.infrastructure.exception.CriticalException @Service @@ -18,4 +20,15 @@ private class VaultUtilImpl( throw CriticalException(500, "Vault Exception") } } + + override fun getPath(deploy: Deploy, container: Container): String { + return "${deploy.deployName}-${deploy.deployType.name}-${container.containerEnvironment.name}" + } + + override fun getPath(deploy: Deploy): List { + return listOf( + "${deploy.deployName}-${deploy.deployType.name}-prod", + "${deploy.deployName}-${deploy.deployType.name}-stag" + ) + } } \ No newline at end of file