Skip to content

Commit

Permalink
feat :: 배포 생성 시 Secret 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSu1768 committed Jun 26, 2024
1 parent 9c0e9ba commit 8bf6948
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String>, path: String)
// fun revoke(path: String)

fun getPath(deploy: Deploy, container: Container): String
fun getPath(deploy: Deploy): List<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<String> {
return listOf(
"${deploy.deployName}-${deploy.deployType.name}-prod",
"${deploy.deployName}-${deploy.deployType.name}-stag"
)
}
}

0 comments on commit 8bf6948

Please sign in to comment.