From a3450cc500426f71dd2b4fbe34534c64f68a206e Mon Sep 17 00:00:00 2001 From: Taekyu Date: Fri, 14 Apr 2023 15:42:30 +0900 Subject: [PATCH 1/3] feature. change & add params to cloudSetting --- api/swagger/docs.go | 24 ++++++++++++++++-------- api/swagger/swagger.json | 24 ++++++++++++++++-------- api/swagger/swagger.yaml | 22 ++++++++++++++-------- pkg/domain/cloud-setting.go | 18 ++++++++++-------- 4 files changed, 56 insertions(+), 32 deletions(-) diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 885f9121..560d1feb 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -2533,12 +2533,16 @@ const docTemplate = `{ "domain.CreateCloudSettingRequest": { "type": "object", "required": [ + "accessKeyId", "name", "organizationId", - "secretKey", - "secretKeyId" + "secretAccessKey", + "sessionToken" ], "properties": { + "accessKeyId": { + "type": "string" + }, "cloudService": { "type": "string", "enum": [ @@ -2556,10 +2560,10 @@ const docTemplate = `{ "organizationId": { "type": "string" }, - "secretKey": { + "secretAccessKey": { "type": "string" }, - "secretKeyId": { + "sessionToken": { "type": "string" } } @@ -2787,14 +2791,18 @@ const docTemplate = `{ "domain.DeleteCloudSettingRequest": { "type": "object", "required": [ - "secretKey", - "secretKeyId" + "accessKeyId", + "secretAccessKey", + "sessionToken" ], "properties": { - "secretKey": { + "accessKeyId": { + "type": "string" + }, + "secretAccessKey": { "type": "string" }, - "secretKeyId": { + "sessionToken": { "type": "string" } } diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 16d84299..eadd0eda 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -2526,12 +2526,16 @@ "domain.CreateCloudSettingRequest": { "type": "object", "required": [ + "accessKeyId", "name", "organizationId", - "secretKey", - "secretKeyId" + "secretAccessKey", + "sessionToken" ], "properties": { + "accessKeyId": { + "type": "string" + }, "cloudService": { "type": "string", "enum": [ @@ -2549,10 +2553,10 @@ "organizationId": { "type": "string" }, - "secretKey": { + "secretAccessKey": { "type": "string" }, - "secretKeyId": { + "sessionToken": { "type": "string" } } @@ -2780,14 +2784,18 @@ "domain.DeleteCloudSettingRequest": { "type": "object", "required": [ - "secretKey", - "secretKeyId" + "accessKeyId", + "secretAccessKey", + "sessionToken" ], "properties": { - "secretKey": { + "accessKeyId": { + "type": "string" + }, + "secretAccessKey": { "type": "string" }, - "secretKeyId": { + "sessionToken": { "type": "string" } } diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 7ec5782a..d4de4df9 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -391,6 +391,8 @@ definitions: type: object domain.CreateCloudSettingRequest: properties: + accessKeyId: + type: string cloudService: enum: - AWS @@ -403,15 +405,16 @@ definitions: type: string organizationId: type: string - secretKey: + secretAccessKey: type: string - secretKeyId: + sessionToken: type: string required: + - accessKeyId - name - organizationId - - secretKey - - secretKeyId + - secretAccessKey + - sessionToken type: object domain.CreateCloudSettingResponse: properties: @@ -564,13 +567,16 @@ definitions: type: object domain.DeleteCloudSettingRequest: properties: - secretKey: + accessKeyId: + type: string + secretAccessKey: type: string - secretKeyId: + sessionToken: type: string required: - - secretKey - - secretKeyId + - accessKeyId + - secretAccessKey + - sessionToken type: object domain.DeleteStackRequest: properties: diff --git a/pkg/domain/cloud-setting.go b/pkg/domain/cloud-setting.go index f186c802..9ad1f32b 100644 --- a/pkg/domain/cloud-setting.go +++ b/pkg/domain/cloud-setting.go @@ -53,12 +53,13 @@ type GetCloudSettingResponse struct { } type CreateCloudSettingRequest struct { - OrganizationId string `json:"organizationId" validate:"required"` - Name string `json:"name" validate:"required"` - Description string `json:"description"` - CloudService string `json:"cloudService" validate:"oneof=AWS AZZURE GCP"` - SecretKeyId string `json:"secretKeyId" validate:"required"` - SecretKey string `json:"secretKey" validate:"required"` + OrganizationId string `json:"organizationId" validate:"required"` + Name string `json:"name" validate:"required"` + Description string `json:"description"` + CloudService string `json:"cloudService" validate:"oneof=AWS AZZURE GCP"` + AccessKeyId string `json:"accessKeyId" validate:"required"` + SecretAccessKey string `json:"secretAccessKey" validate:"required"` + SessionToken string `json:"sessionToken" validate:"required"` } type CreateCloudSettingResponse struct { @@ -70,8 +71,9 @@ type UpdateCloudSettingRequest struct { } type DeleteCloudSettingRequest struct { - SecretKeyId string `json:"secretKeyId" validate:"required"` - SecretKey string `json:"secretKey" validate:"required"` + AccessKeyId string `json:"accessKeyId" validate:"required"` + SecretAccessKey string `json:"secretAccessKey" validate:"required"` + SessionToken string `json:"sessionToken" validate:"required"` } type CheckCloudSettingNameResponse struct { From 0ff87980d6ca4ca9af3e8003523a4dad9c7ddd26 Mon Sep 17 00:00:00 2001 From: Taekyu Date: Fri, 14 Apr 2023 15:53:58 +0900 Subject: [PATCH 2/3] feature. minor fixes --- api/swagger/docs.go | 28 ++++++++++++++++++---------- api/swagger/swagger.json | 28 ++++++++++++++++++---------- api/swagger/swagger.yaml | 12 ++++++++++-- internal/usecase/cloud-setting.go | 6 ++++++ pkg/domain/cloud-setting.go | 12 ++++++------ 5 files changed, 58 insertions(+), 28 deletions(-) diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 560d1feb..caebe5ff 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -2536,12 +2536,13 @@ const docTemplate = `{ "accessKeyId", "name", "organizationId", - "secretAccessKey", - "sessionToken" + "secretAccessKey" ], "properties": { "accessKeyId": { - "type": "string" + "type": "string", + "maxLength": 128, + "minLength": 16 }, "cloudService": { "type": "string", @@ -2561,10 +2562,13 @@ const docTemplate = `{ "type": "string" }, "secretAccessKey": { - "type": "string" + "type": "string", + "maxLength": 128, + "minLength": 16 }, "sessionToken": { - "type": "string" + "type": "string", + "maxLength": 2000 } } }, @@ -2792,18 +2796,22 @@ const docTemplate = `{ "type": "object", "required": [ "accessKeyId", - "secretAccessKey", - "sessionToken" + "secretAccessKey" ], "properties": { "accessKeyId": { - "type": "string" + "type": "string", + "maxLength": 128, + "minLength": 16 }, "secretAccessKey": { - "type": "string" + "type": "string", + "maxLength": 128, + "minLength": 16 }, "sessionToken": { - "type": "string" + "type": "string", + "maxLength": 2000 } } }, diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index eadd0eda..4ec10cd4 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -2529,12 +2529,13 @@ "accessKeyId", "name", "organizationId", - "secretAccessKey", - "sessionToken" + "secretAccessKey" ], "properties": { "accessKeyId": { - "type": "string" + "type": "string", + "maxLength": 128, + "minLength": 16 }, "cloudService": { "type": "string", @@ -2554,10 +2555,13 @@ "type": "string" }, "secretAccessKey": { - "type": "string" + "type": "string", + "maxLength": 128, + "minLength": 16 }, "sessionToken": { - "type": "string" + "type": "string", + "maxLength": 2000 } } }, @@ -2785,18 +2789,22 @@ "type": "object", "required": [ "accessKeyId", - "secretAccessKey", - "sessionToken" + "secretAccessKey" ], "properties": { "accessKeyId": { - "type": "string" + "type": "string", + "maxLength": 128, + "minLength": 16 }, "secretAccessKey": { - "type": "string" + "type": "string", + "maxLength": 128, + "minLength": 16 }, "sessionToken": { - "type": "string" + "type": "string", + "maxLength": 2000 } } }, diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index d4de4df9..37fb5171 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -392,6 +392,8 @@ definitions: domain.CreateCloudSettingRequest: properties: accessKeyId: + maxLength: 128 + minLength: 16 type: string cloudService: enum: @@ -406,15 +408,17 @@ definitions: organizationId: type: string secretAccessKey: + maxLength: 128 + minLength: 16 type: string sessionToken: + maxLength: 2000 type: string required: - accessKeyId - name - organizationId - secretAccessKey - - sessionToken type: object domain.CreateCloudSettingResponse: properties: @@ -568,15 +572,19 @@ definitions: domain.DeleteCloudSettingRequest: properties: accessKeyId: + maxLength: 128 + minLength: 16 type: string secretAccessKey: + maxLength: 128 + minLength: 16 type: string sessionToken: + maxLength: 2000 type: string required: - accessKeyId - secretAccessKey - - sessionToken type: object domain.DeleteStackRequest: properties: diff --git a/internal/usecase/cloud-setting.go b/internal/usecase/cloud-setting.go index 9378488c..c1a711e3 100644 --- a/internal/usecase/cloud-setting.go +++ b/internal/usecase/cloud-setting.go @@ -46,6 +46,12 @@ func (u *CloudSettingUsecase) Create(ctx context.Context, dto domain.CloudSettin dto.Resource = "TODO server result or additional information" dto.CreatorId = user.GetUserId() + + _, err = u.GetByName(dto.OrganizationId, dto.Name) + if err == nil { + return uuid.Nil, httpErrors.NewBadRequestError(httpErrors.DuplicateResource) + } + cloudSettingId, err = u.repo.Create(dto) if err != nil { return uuid.Nil, httpErrors.NewInternalServerError(err) diff --git a/pkg/domain/cloud-setting.go b/pkg/domain/cloud-setting.go index 9ad1f32b..29f10b13 100644 --- a/pkg/domain/cloud-setting.go +++ b/pkg/domain/cloud-setting.go @@ -57,9 +57,9 @@ type CreateCloudSettingRequest struct { Name string `json:"name" validate:"required"` Description string `json:"description"` CloudService string `json:"cloudService" validate:"oneof=AWS AZZURE GCP"` - AccessKeyId string `json:"accessKeyId" validate:"required"` - SecretAccessKey string `json:"secretAccessKey" validate:"required"` - SessionToken string `json:"sessionToken" validate:"required"` + AccessKeyId string `json:"accessKeyId" validate:"required,min=16,max=128"` + SecretAccessKey string `json:"secretAccessKey" validate:"required,min=16,max=128"` + SessionToken string `json:"sessionToken" validate:"max=2000"` } type CreateCloudSettingResponse struct { @@ -71,9 +71,9 @@ type UpdateCloudSettingRequest struct { } type DeleteCloudSettingRequest struct { - AccessKeyId string `json:"accessKeyId" validate:"required"` - SecretAccessKey string `json:"secretAccessKey" validate:"required"` - SessionToken string `json:"sessionToken" validate:"required"` + AccessKeyId string `json:"accessKeyId" validate:"required,min=16,max=128"` + SecretAccessKey string `json:"secretAccessKey" validate:"required,min=16,max=128"` + SessionToken string `json:"sessionToken" validate:"max=2000"` } type CheckCloudSettingNameResponse struct { From 4fe222a4aa681312053398c8de7fa4828c79e1b7 Mon Sep 17 00:00:00 2001 From: Taekyu Date: Fri, 14 Apr 2023 15:58:10 +0900 Subject: [PATCH 3/3] trivial. change swagger path to root "/" --- internal/route/route.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/route/route.go b/internal/route/route.go index cef35d84..4f760061 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -52,7 +52,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, asset http.Handler, // [TODO] Transaction //r.Use(transactionMiddleware(db)) - r.PathPrefix("/swagger").Handler(httpSwagger.WrapHandler) + //r.PathPrefix("/swagger").Handler(httpSwagger.WrapHandler) repoFactory := repository.Repository{ User: repository.NewUserRepository(db), @@ -136,7 +136,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, asset http.Handler, // assets r.PathPrefix("/api/").HandlerFunc(http.NotFound) - r.PathPrefix("/").Handler(asset).Methods(http.MethodGet) + r.PathPrefix("/").Handler(httpSwagger.WrapHandler).Methods(http.MethodGet) //withLog := handlers.LoggingHandler(os.Stdout, r)