From 7d335772001cbd8c040849173369d6b0bbc6d84e Mon Sep 17 00:00:00 2001 From: Taekyu Date: Thu, 22 Jun 2023 10:28:53 +0900 Subject: [PATCH 1/2] trivial. minor fix. --- internal/usecase/cloud-account.go | 5 +++-- internal/usecase/cluster.go | 4 ++-- pkg/domain/cloud-account.go | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/usecase/cloud-account.go b/internal/usecase/cloud-account.go index b9548271..6f4f141b 100644 --- a/internal/usecase/cloud-account.go +++ b/internal/usecase/cloud-account.go @@ -69,7 +69,7 @@ func (u *CloudAccountUsecase) Create(ctx context.Context, dto domain.CloudAccoun log.InfoWithContext(ctx, "newly created CloudAccount ID:", cloudAccountId) // FOR TEST. ADD MAGIC KEYWORD - if strings.Contains(dto.Name, "INCLUSTER") { + if strings.Contains(dto.Name, domain.CLOUD_ACCOUNT_INCLUSTER) { if err := u.repo.InitWorkflow(cloudAccountId, "", domain.CloudAccountStatus_CREATED); err != nil { return uuid.Nil, errors.Wrap(err, "Failed to initialize status") } @@ -210,7 +210,8 @@ func (u *CloudAccountUsecase) DeleteForce(ctx context.Context, cloudAccountId uu return err } - if cloudAccount.Status != domain.CloudAccountStatus_CREATE_ERROR { + if !strings.Contains(cloudAccount.Name, domain.CLOUD_ACCOUNT_INCLUSTER) && + cloudAccount.Status != domain.CloudAccountStatus_CREATE_ERROR { return fmt.Errorf("The status is not CREATE_ERROR. %s", cloudAccount.Status) } diff --git a/internal/usecase/cluster.go b/internal/usecase/cluster.go index 75119f5a..8fc09539 100644 --- a/internal/usecase/cluster.go +++ b/internal/usecase/cluster.go @@ -133,7 +133,7 @@ func (u *ClusterUsecase) Create(ctx context.Context, dto domain.Cluster) (cluste if ca.ID == dto.CloudAccountId { // FOR TEST. ADD MAGIC KEYWORD - if strings.Contains(ca.Name, "INCLUSTER") { + if strings.Contains(ca.Name, domain.CLOUD_ACCOUNT_INCLUSTER) { tksCloudAccountId = "NULL" } isExist = true @@ -237,7 +237,7 @@ func (u *ClusterUsecase) Delete(ctx context.Context, clusterId domain.ClusterId) return httpErrors.NewInternalServerError(fmt.Errorf("Failed to get cloudAccount"), "", "") } tksCloudAccountId := cluster.CloudAccountId.String() - if strings.Contains(cloudAccount.Name, "INCLUSTER") { + if strings.Contains(cloudAccount.Name, domain.CLOUD_ACCOUNT_INCLUSTER) { tksCloudAccountId = "NULL" } diff --git a/pkg/domain/cloud-account.go b/pkg/domain/cloud-account.go index e13b8f6f..a27002a5 100644 --- a/pkg/domain/cloud-account.go +++ b/pkg/domain/cloud-account.go @@ -6,6 +6,8 @@ import ( "github.com/google/uuid" ) +const CLOUD_ACCOUNT_INCLUSTER = "INCLUSTER" + const ( CloudService_UNDEFINED = "UNDEFINED" CloudService_AWS = "AWS" From a24fae1856a1dfb76060b455dcbabf8a33131806 Mon Sep 17 00:00:00 2001 From: Taekyu Date: Thu, 22 Jun 2023 11:36:12 +0900 Subject: [PATCH 2/2] bugfix. add condition awsAccountId on cloud account creation --- internal/repository/cloud-account.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/repository/cloud-account.go b/internal/repository/cloud-account.go index e42115f0..51960663 100644 --- a/internal/repository/cloud-account.go +++ b/internal/repository/cloud-account.go @@ -83,7 +83,7 @@ func (r *CloudAccountRepository) GetByName(organizationId string, name string) ( func (r *CloudAccountRepository) GetByAwsAccountId(awsAccountId string) (out domain.CloudAccount, err error) { var cloudAccount CloudAccount - res := r.db.Preload(clause.Associations).First(&cloudAccount, "aws_account_id = ?", awsAccountId) + res := r.db.Preload(clause.Associations).First(&cloudAccount, "aws_account_id = ? AND status != ?", awsAccountId, domain.CloudAccountStatus_DELETED) if res.Error != nil { return domain.CloudAccount{}, res.Error