Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature. change & add params to cloudSetting #27

Merged
merged 3 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2533,12 +2533,17 @@ const docTemplate = `{
"domain.CreateCloudSettingRequest": {
"type": "object",
"required": [
"accessKeyId",
"name",
"organizationId",
"secretKey",
"secretKeyId"
"secretAccessKey"
],
"properties": {
"accessKeyId": {
"type": "string",
"maxLength": 128,
"minLength": 16
},
"cloudService": {
"type": "string",
"enum": [
Expand All @@ -2556,11 +2561,14 @@ const docTemplate = `{
"organizationId": {
"type": "string"
},
"secretKey": {
"type": "string"
"secretAccessKey": {
"type": "string",
"maxLength": 128,
"minLength": 16
},
"secretKeyId": {
"type": "string"
"sessionToken": {
"type": "string",
"maxLength": 2000
}
}
},
Expand Down Expand Up @@ -2787,15 +2795,23 @@ const docTemplate = `{
"domain.DeleteCloudSettingRequest": {
"type": "object",
"required": [
"secretKey",
"secretKeyId"
"accessKeyId",
"secretAccessKey"
],
"properties": {
"secretKey": {
"type": "string"
"accessKeyId": {
"type": "string",
"maxLength": 128,
"minLength": 16
},
"secretKeyId": {
"type": "string"
"secretAccessKey": {
"type": "string",
"maxLength": 128,
"minLength": 16
},
"sessionToken": {
"type": "string",
"maxLength": 2000
}
}
},
Expand Down
40 changes: 28 additions & 12 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2526,12 +2526,17 @@
"domain.CreateCloudSettingRequest": {
"type": "object",
"required": [
"accessKeyId",
"name",
"organizationId",
"secretKey",
"secretKeyId"
"secretAccessKey"
],
"properties": {
"accessKeyId": {
"type": "string",
"maxLength": 128,
"minLength": 16
},
"cloudService": {
"type": "string",
"enum": [
Expand All @@ -2549,11 +2554,14 @@
"organizationId": {
"type": "string"
},
"secretKey": {
"type": "string"
"secretAccessKey": {
"type": "string",
"maxLength": 128,
"minLength": 16
},
"secretKeyId": {
"type": "string"
"sessionToken": {
"type": "string",
"maxLength": 2000
}
}
},
Expand Down Expand Up @@ -2780,15 +2788,23 @@
"domain.DeleteCloudSettingRequest": {
"type": "object",
"required": [
"secretKey",
"secretKeyId"
"accessKeyId",
"secretAccessKey"
],
"properties": {
"secretKey": {
"type": "string"
"accessKeyId": {
"type": "string",
"maxLength": 128,
"minLength": 16
},
"secretKeyId": {
"type": "string"
"secretAccessKey": {
"type": "string",
"maxLength": 128,
"minLength": 16
},
"sessionToken": {
"type": "string",
"maxLength": 2000
}
}
},
Expand Down
30 changes: 22 additions & 8 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ definitions:
type: object
domain.CreateCloudSettingRequest:
properties:
accessKeyId:
maxLength: 128
minLength: 16
type: string
cloudService:
enum:
- AWS
Expand All @@ -403,15 +407,18 @@ definitions:
type: string
organizationId:
type: string
secretKey:
secretAccessKey:
maxLength: 128
minLength: 16
type: string
secretKeyId:
sessionToken:
maxLength: 2000
type: string
required:
- accessKeyId
- name
- organizationId
- secretKey
- secretKeyId
- secretAccessKey
type: object
domain.CreateCloudSettingResponse:
properties:
Expand Down Expand Up @@ -564,13 +571,20 @@ definitions:
type: object
domain.DeleteCloudSettingRequest:
properties:
secretKey:
accessKeyId:
maxLength: 128
minLength: 16
type: string
secretAccessKey:
maxLength: 128
minLength: 16
type: string
secretKeyId:
sessionToken:
maxLength: 2000
type: string
required:
- secretKey
- secretKeyId
- accessKeyId
- secretAccessKey
type: object
domain.DeleteStackRequest:
properties:
Expand Down
4 changes: 2 additions & 2 deletions internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions internal/usecase/cloud-setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 10 additions & 8 deletions pkg/domain/cloud-setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,min=16,max=128"`
SecretAccessKey string `json:"secretAccessKey" validate:"required,min=16,max=128"`
SessionToken string `json:"sessionToken" validate:"max=2000"`
}

type CreateCloudSettingResponse struct {
Expand All @@ -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,min=16,max=128"`
SecretAccessKey string `json:"secretAccessKey" validate:"required,min=16,max=128"`
SessionToken string `json:"sessionToken" validate:"max=2000"`
}

type CheckCloudSettingNameResponse struct {
Expand Down