diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 0f4a03ac..127062a9 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -578,14 +578,14 @@ const docTemplate = `{ } } }, - "/cloud-settings": { + "/cloud-accounts": { "get": { "security": [ { "JWT": [] } ], - "description": "Get CloudSettings", + "description": "Get CloudAccounts", "consumes": [ "application/json" ], @@ -593,9 +593,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Get CloudSettings", + "summary": "Get CloudAccounts", "parameters": [ { "type": "string", @@ -608,7 +608,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.GetCloudSettingsResponse" + "$ref": "#/definitions/domain.GetCloudAccountsResponse" } } } @@ -619,7 +619,7 @@ const docTemplate = `{ "JWT": [] } ], - "description": "Create CloudSetting", + "description": "Create CloudAccount", "consumes": [ "application/json" ], @@ -627,9 +627,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Create CloudSetting", + "summary": "Create CloudAccount", "parameters": [ { "type": "string", @@ -644,7 +644,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.CreateCloudSettingRequest" + "$ref": "#/definitions/domain.CreateCloudAccountRequest" } } ], @@ -652,20 +652,20 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.CreateCloudSettingResponse" + "$ref": "#/definitions/domain.CreateCloudAccountResponse" } } } } }, - "/cloud-settings/name/{name}/existence": { + "/cloud-accounts/name/{name}/existence": { "get": { "security": [ { "JWT": [] } ], - "description": "Check name for cloudSetting", + "description": "Check name for cloudAccount", "consumes": [ "application/json" ], @@ -673,9 +673,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Check name for cloudSetting", + "summary": "Check name for cloudAccount", "parameters": [ { "type": "string", @@ -692,14 +692,14 @@ const docTemplate = `{ } } }, - "/cloud-settings/{cloudSettingId}": { + "/cloud-accounts/{cloudAccountId}": { "get": { "security": [ { "JWT": [] } ], - "description": "Get CloudSetting", + "description": "Get CloudAccount", "consumes": [ "application/json" ], @@ -707,14 +707,14 @@ const docTemplate = `{ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Get CloudSetting", + "summary": "Get CloudAccount", "parameters": [ { "type": "string", - "description": "cloudSettingId", - "name": "cloudSettingId", + "description": "cloudAccountId", + "name": "cloudAccountId", "in": "path", "required": true } @@ -723,7 +723,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.GetCloudSettingResponse" + "$ref": "#/definitions/domain.GetCloudAccountResponse" } } } @@ -734,7 +734,7 @@ const docTemplate = `{ "JWT": [] } ], - "description": "Update CloudSetting", + "description": "Update CloudAccount", "consumes": [ "application/json" ], @@ -742,9 +742,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Update CloudSetting", + "summary": "Update CloudAccount", "parameters": [ { "description": "Update cloud setting request", @@ -752,7 +752,7 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.UpdateCloudSettingRequest" + "$ref": "#/definitions/domain.UpdateCloudAccountRequest" } } ], @@ -768,7 +768,7 @@ const docTemplate = `{ "JWT": [] } ], - "description": "Delete CloudSetting", + "description": "Delete CloudAccount", "consumes": [ "application/json" ], @@ -776,9 +776,9 @@ const docTemplate = `{ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Delete CloudSetting", + "summary": "Delete CloudAccount", "parameters": [ { "description": "Delete cloud setting request", @@ -786,13 +786,13 @@ const docTemplate = `{ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.DeleteCloudSettingRequest" + "$ref": "#/definitions/domain.DeleteCloudAccountRequest" } }, { "type": "string", - "description": "cloudSettingId", - "name": "cloudSettingId", + "description": "cloudAccountId", + "name": "cloudAccountId", "in": "path", "required": true } @@ -2277,7 +2277,7 @@ const docTemplate = `{ } } }, - "domain.CloudSetting": { + "domain.CloudAccount": { "type": "object", "properties": { "cloudService": { @@ -2321,7 +2321,7 @@ const docTemplate = `{ } } }, - "domain.CloudSettingResponse": { + "domain.CloudAccountResponse": { "type": "object", "properties": { "cloudService": { @@ -2362,10 +2362,10 @@ const docTemplate = `{ "domain.Cluster": { "type": "object", "properties": { - "cloudSetting": { - "$ref": "#/definitions/domain.CloudSetting" + "cloudAccount": { + "$ref": "#/definitions/domain.CloudAccount" }, - "cloudSettingId": { + "cloudAccountId": { "type": "string" }, "conf": { @@ -2470,8 +2470,8 @@ const docTemplate = `{ "domain.ClusterResponse": { "type": "object", "properties": { - "cloudSetting": { - "$ref": "#/definitions/domain.CloudSettingResponse" + "cloudAccount": { + "$ref": "#/definitions/domain.CloudAccountResponse" }, "conf": { "$ref": "#/definitions/domain.ClusterConfResponse" @@ -2633,7 +2633,7 @@ const docTemplate = `{ } } }, - "domain.CreateCloudSettingRequest": { + "domain.CreateCloudAccountRequest": { "type": "object", "required": [ "accessKeyId", @@ -2675,7 +2675,7 @@ const docTemplate = `{ } } }, - "domain.CreateCloudSettingResponse": { + "domain.CreateCloudAccountResponse": { "type": "object", "properties": { "id": { @@ -2686,7 +2686,7 @@ const docTemplate = `{ "domain.CreateClusterRequest": { "type": "object", "properties": { - "cloudSettingId": { + "cloudAccountId": { "type": "string" }, "description": { @@ -2747,7 +2747,7 @@ const docTemplate = `{ "domain.CreateStackRequest": { "type": "object", "properties": { - "cloudSettingId": { + "cloudAccountId": { "type": "string" }, "cpNodeCnt": { @@ -2924,7 +2924,7 @@ const docTemplate = `{ } } }, - "domain.DeleteCloudSettingRequest": { + "domain.DeleteCloudAccountRequest": { "type": "object", "required": [ "accessKeyId", @@ -2985,21 +2985,21 @@ const docTemplate = `{ } } }, - "domain.GetCloudSettingResponse": { + "domain.GetCloudAccountResponse": { "type": "object", "properties": { - "cloudSetting": { - "$ref": "#/definitions/domain.CloudSettingResponse" + "cloudAccount": { + "$ref": "#/definitions/domain.CloudAccountResponse" } } }, - "domain.GetCloudSettingsResponse": { + "domain.GetCloudAccountsResponse": { "type": "object", "properties": { - "cloudSettings": { + "cloudAccounts": { "type": "array", "items": { - "$ref": "#/definitions/domain.CloudSettingResponse" + "$ref": "#/definitions/domain.CloudAccountResponse" } } } @@ -3350,8 +3350,8 @@ const docTemplate = `{ "domain.StackResponse": { "type": "object", "properties": { - "cloudSetting": { - "$ref": "#/definitions/domain.CloudSettingResponse" + "cloudAccount": { + "$ref": "#/definitions/domain.CloudAccountResponse" }, "createdAt": { "type": "string" @@ -3682,7 +3682,7 @@ const docTemplate = `{ } } }, - "domain.UpdateCloudSettingRequest": { + "domain.UpdateCloudAccountRequest": { "type": "object", "properties": { "description": { diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index 7a140e89..d82eb2e3 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -571,14 +571,14 @@ } } }, - "/cloud-settings": { + "/cloud-accounts": { "get": { "security": [ { "JWT": [] } ], - "description": "Get CloudSettings", + "description": "Get CloudAccounts", "consumes": [ "application/json" ], @@ -586,9 +586,9 @@ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Get CloudSettings", + "summary": "Get CloudAccounts", "parameters": [ { "type": "string", @@ -601,7 +601,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.GetCloudSettingsResponse" + "$ref": "#/definitions/domain.GetCloudAccountsResponse" } } } @@ -612,7 +612,7 @@ "JWT": [] } ], - "description": "Create CloudSetting", + "description": "Create CloudAccount", "consumes": [ "application/json" ], @@ -620,9 +620,9 @@ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Create CloudSetting", + "summary": "Create CloudAccount", "parameters": [ { "type": "string", @@ -637,7 +637,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.CreateCloudSettingRequest" + "$ref": "#/definitions/domain.CreateCloudAccountRequest" } } ], @@ -645,20 +645,20 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.CreateCloudSettingResponse" + "$ref": "#/definitions/domain.CreateCloudAccountResponse" } } } } }, - "/cloud-settings/name/{name}/existence": { + "/cloud-accounts/name/{name}/existence": { "get": { "security": [ { "JWT": [] } ], - "description": "Check name for cloudSetting", + "description": "Check name for cloudAccount", "consumes": [ "application/json" ], @@ -666,9 +666,9 @@ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Check name for cloudSetting", + "summary": "Check name for cloudAccount", "parameters": [ { "type": "string", @@ -685,14 +685,14 @@ } } }, - "/cloud-settings/{cloudSettingId}": { + "/cloud-accounts/{cloudAccountId}": { "get": { "security": [ { "JWT": [] } ], - "description": "Get CloudSetting", + "description": "Get CloudAccount", "consumes": [ "application/json" ], @@ -700,14 +700,14 @@ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Get CloudSetting", + "summary": "Get CloudAccount", "parameters": [ { "type": "string", - "description": "cloudSettingId", - "name": "cloudSettingId", + "description": "cloudAccountId", + "name": "cloudAccountId", "in": "path", "required": true } @@ -716,7 +716,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/domain.GetCloudSettingResponse" + "$ref": "#/definitions/domain.GetCloudAccountResponse" } } } @@ -727,7 +727,7 @@ "JWT": [] } ], - "description": "Update CloudSetting", + "description": "Update CloudAccount", "consumes": [ "application/json" ], @@ -735,9 +735,9 @@ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Update CloudSetting", + "summary": "Update CloudAccount", "parameters": [ { "description": "Update cloud setting request", @@ -745,7 +745,7 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.UpdateCloudSettingRequest" + "$ref": "#/definitions/domain.UpdateCloudAccountRequest" } } ], @@ -761,7 +761,7 @@ "JWT": [] } ], - "description": "Delete CloudSetting", + "description": "Delete CloudAccount", "consumes": [ "application/json" ], @@ -769,9 +769,9 @@ "application/json" ], "tags": [ - "CloudSettings" + "CloudAccounts" ], - "summary": "Delete CloudSetting", + "summary": "Delete CloudAccount", "parameters": [ { "description": "Delete cloud setting request", @@ -779,13 +779,13 @@ "in": "body", "required": true, "schema": { - "$ref": "#/definitions/domain.DeleteCloudSettingRequest" + "$ref": "#/definitions/domain.DeleteCloudAccountRequest" } }, { "type": "string", - "description": "cloudSettingId", - "name": "cloudSettingId", + "description": "cloudAccountId", + "name": "cloudAccountId", "in": "path", "required": true } @@ -2270,7 +2270,7 @@ } } }, - "domain.CloudSetting": { + "domain.CloudAccount": { "type": "object", "properties": { "cloudService": { @@ -2314,7 +2314,7 @@ } } }, - "domain.CloudSettingResponse": { + "domain.CloudAccountResponse": { "type": "object", "properties": { "cloudService": { @@ -2355,10 +2355,10 @@ "domain.Cluster": { "type": "object", "properties": { - "cloudSetting": { - "$ref": "#/definitions/domain.CloudSetting" + "cloudAccount": { + "$ref": "#/definitions/domain.CloudAccount" }, - "cloudSettingId": { + "cloudAccountId": { "type": "string" }, "conf": { @@ -2463,8 +2463,8 @@ "domain.ClusterResponse": { "type": "object", "properties": { - "cloudSetting": { - "$ref": "#/definitions/domain.CloudSettingResponse" + "cloudAccount": { + "$ref": "#/definitions/domain.CloudAccountResponse" }, "conf": { "$ref": "#/definitions/domain.ClusterConfResponse" @@ -2626,7 +2626,7 @@ } } }, - "domain.CreateCloudSettingRequest": { + "domain.CreateCloudAccountRequest": { "type": "object", "required": [ "accessKeyId", @@ -2668,7 +2668,7 @@ } } }, - "domain.CreateCloudSettingResponse": { + "domain.CreateCloudAccountResponse": { "type": "object", "properties": { "id": { @@ -2679,7 +2679,7 @@ "domain.CreateClusterRequest": { "type": "object", "properties": { - "cloudSettingId": { + "cloudAccountId": { "type": "string" }, "description": { @@ -2740,7 +2740,7 @@ "domain.CreateStackRequest": { "type": "object", "properties": { - "cloudSettingId": { + "cloudAccountId": { "type": "string" }, "cpNodeCnt": { @@ -2917,7 +2917,7 @@ } } }, - "domain.DeleteCloudSettingRequest": { + "domain.DeleteCloudAccountRequest": { "type": "object", "required": [ "accessKeyId", @@ -2978,21 +2978,21 @@ } } }, - "domain.GetCloudSettingResponse": { + "domain.GetCloudAccountResponse": { "type": "object", "properties": { - "cloudSetting": { - "$ref": "#/definitions/domain.CloudSettingResponse" + "cloudAccount": { + "$ref": "#/definitions/domain.CloudAccountResponse" } } }, - "domain.GetCloudSettingsResponse": { + "domain.GetCloudAccountsResponse": { "type": "object", "properties": { - "cloudSettings": { + "cloudAccounts": { "type": "array", "items": { - "$ref": "#/definitions/domain.CloudSettingResponse" + "$ref": "#/definitions/domain.CloudAccountResponse" } } } @@ -3343,8 +3343,8 @@ "domain.StackResponse": { "type": "object", "properties": { - "cloudSetting": { - "$ref": "#/definitions/domain.CloudSettingResponse" + "cloudAccount": { + "$ref": "#/definitions/domain.CloudAccountResponse" }, "createdAt": { "type": "string" @@ -3675,7 +3675,7 @@ } } }, - "domain.UpdateCloudSettingRequest": { + "domain.UpdateCloudAccountRequest": { "type": "object", "properties": { "description": { diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 7e5d1bc9..458c7843 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -176,7 +176,7 @@ definitions: type: string type: object type: object - domain.CloudSetting: + domain.CloudAccount: properties: cloudService: type: string @@ -205,7 +205,7 @@ definitions: updatorId: type: string type: object - domain.CloudSettingResponse: + domain.CloudAccountResponse: properties: cloudService: type: string @@ -232,9 +232,9 @@ definitions: type: object domain.Cluster: properties: - cloudSetting: - $ref: '#/definitions/domain.CloudSetting' - cloudSettingId: + cloudAccount: + $ref: '#/definitions/domain.CloudAccount' + cloudAccountId: type: string conf: $ref: '#/definitions/domain.ClusterConf' @@ -303,8 +303,8 @@ definitions: type: object domain.ClusterResponse: properties: - cloudSetting: - $ref: '#/definitions/domain.CloudSettingResponse' + cloudAccount: + $ref: '#/definitions/domain.CloudAccountResponse' conf: $ref: '#/definitions/domain.ClusterConfResponse' createdAt: @@ -414,7 +414,7 @@ definitions: - organization_id - target_cluster_id type: object - domain.CreateCloudSettingRequest: + domain.CreateCloudAccountRequest: properties: accessKeyId: maxLength: 128 @@ -445,14 +445,14 @@ definitions: - organizationId - secretAccessKey type: object - domain.CreateCloudSettingResponse: + domain.CreateCloudAccountResponse: properties: id: type: string type: object domain.CreateClusterRequest: properties: - cloudSettingId: + cloudAccountId: type: string description: type: string @@ -493,7 +493,7 @@ definitions: type: object domain.CreateStackRequest: properties: - cloudSettingId: + cloudAccountId: type: string cpNodeCnt: type: integer @@ -613,7 +613,7 @@ definitions: updatedAt: type: string type: object - domain.DeleteCloudSettingRequest: + domain.DeleteCloudAccountRequest: properties: accessKeyId: maxLength: 128 @@ -654,16 +654,16 @@ definitions: $ref: '#/definitions/domain.ApplicationResponse' type: array type: object - domain.GetCloudSettingResponse: + domain.GetCloudAccountResponse: properties: - cloudSetting: - $ref: '#/definitions/domain.CloudSettingResponse' + cloudAccount: + $ref: '#/definitions/domain.CloudAccountResponse' type: object - domain.GetCloudSettingsResponse: + domain.GetCloudAccountsResponse: properties: - cloudSettings: + cloudAccounts: items: - $ref: '#/definitions/domain.CloudSettingResponse' + $ref: '#/definitions/domain.CloudAccountResponse' type: array type: object domain.GetClustersResponse: @@ -891,8 +891,8 @@ definitions: type: object domain.StackResponse: properties: - cloudSetting: - $ref: '#/definitions/domain.CloudSettingResponse' + cloudAccount: + $ref: '#/definitions/domain.CloudAccountResponse' createdAt: type: string creator: @@ -1111,7 +1111,7 @@ definitions: metadata: type: string type: object - domain.UpdateCloudSettingRequest: + domain.UpdateCloudAccountRequest: properties: description: type: string @@ -1600,11 +1600,11 @@ paths: summary: logout tags: - Auth - /cloud-settings: + /cloud-accounts: get: consumes: - application/json - description: Get CloudSettings + description: Get CloudAccounts parameters: - description: show all organizations in: query @@ -1616,16 +1616,16 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.GetCloudSettingsResponse' + $ref: '#/definitions/domain.GetCloudAccountsResponse' security: - JWT: [] - summary: Get CloudSettings + summary: Get CloudAccounts tags: - - CloudSettings + - CloudAccounts post: consumes: - application/json - description: Create CloudSetting + description: Create CloudAccount parameters: - description: organizationId in: path @@ -1637,34 +1637,34 @@ paths: name: body required: true schema: - $ref: '#/definitions/domain.CreateCloudSettingRequest' + $ref: '#/definitions/domain.CreateCloudAccountRequest' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/domain.CreateCloudSettingResponse' + $ref: '#/definitions/domain.CreateCloudAccountResponse' security: - JWT: [] - summary: Create CloudSetting + summary: Create CloudAccount tags: - - CloudSettings - /cloud-settings/{cloudSettingId}: + - CloudAccounts + /cloud-accounts/{cloudAccountId}: delete: consumes: - application/json - description: Delete CloudSetting + description: Delete CloudAccount parameters: - description: Delete cloud setting request in: body name: body required: true schema: - $ref: '#/definitions/domain.DeleteCloudSettingRequest' - - description: cloudSettingId + $ref: '#/definitions/domain.DeleteCloudAccountRequest' + - description: cloudAccountId in: path - name: cloudSettingId + name: cloudAccountId required: true type: string produces: @@ -1674,17 +1674,17 @@ paths: description: OK security: - JWT: [] - summary: Delete CloudSetting + summary: Delete CloudAccount tags: - - CloudSettings + - CloudAccounts get: consumes: - application/json - description: Get CloudSetting + description: Get CloudAccount parameters: - - description: cloudSettingId + - description: cloudAccountId in: path - name: cloudSettingId + name: cloudAccountId required: true type: string produces: @@ -1693,23 +1693,23 @@ paths: "200": description: OK schema: - $ref: '#/definitions/domain.GetCloudSettingResponse' + $ref: '#/definitions/domain.GetCloudAccountResponse' security: - JWT: [] - summary: Get CloudSetting + summary: Get CloudAccount tags: - - CloudSettings + - CloudAccounts put: consumes: - application/json - description: Update CloudSetting + description: Update CloudAccount parameters: - description: Update cloud setting request in: body name: body required: true schema: - $ref: '#/definitions/domain.UpdateCloudSettingRequest' + $ref: '#/definitions/domain.UpdateCloudAccountRequest' produces: - application/json responses: @@ -1717,14 +1717,14 @@ paths: description: OK security: - JWT: [] - summary: Update CloudSetting + summary: Update CloudAccount tags: - - CloudSettings - /cloud-settings/name/{name}/existence: + - CloudAccounts + /cloud-accounts/name/{name}/existence: get: consumes: - application/json - description: Check name for cloudSetting + description: Check name for cloudAccount parameters: - description: name in: path @@ -1738,9 +1738,9 @@ paths: description: OK security: - JWT: [] - summary: Check name for cloudSetting + summary: Check name for cloudAccount tags: - - CloudSettings + - CloudAccounts /clusters: get: consumes: diff --git a/internal/database/database.go b/internal/database/database.go index 8c7b362e..39b55176 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -74,8 +74,8 @@ func migrateSchema(db *gorm.DB) error { return err } - // CloudSetting - if err := db.AutoMigrate(&repository.CloudSetting{}); err != nil { + // CloudAccount + if err := db.AutoMigrate(&repository.CloudAccount{}); err != nil { return err } diff --git a/internal/delivery/http/cloud-setting.go b/internal/delivery/http/cloud-account.go similarity index 56% rename from internal/delivery/http/cloud-setting.go rename to internal/delivery/http/cloud-account.go index 2701f798..9fa84256 100644 --- a/internal/delivery/http/cloud-setting.go +++ b/internal/delivery/http/cloud-account.go @@ -14,63 +14,63 @@ import ( "github.com/pkg/errors" ) -type CloudSettingHandler struct { - usecase usecase.ICloudSettingUsecase +type CloudAccountHandler struct { + usecase usecase.ICloudAccountUsecase } -func NewCloudSettingHandler(h usecase.ICloudSettingUsecase) *CloudSettingHandler { - return &CloudSettingHandler{ +func NewCloudAccountHandler(h usecase.ICloudAccountUsecase) *CloudAccountHandler { + return &CloudAccountHandler{ usecase: h, } } -// CreateCloudSetting godoc -// @Tags CloudSettings -// @Summary Create CloudSetting -// @Description Create CloudSetting +// CreateCloudAccount godoc +// @Tags CloudAccounts +// @Summary Create CloudAccount +// @Description Create CloudAccount // @Accept json // @Produce json // @Param organizationId path string true "organizationId" -// @Param body body domain.CreateCloudSettingRequest true "create cloud setting request" -// @Success 200 {object} domain.CreateCloudSettingResponse -// @Router /cloud-settings [post] +// @Param body body domain.CreateCloudAccountRequest true "create cloud setting request" +// @Success 200 {object} domain.CreateCloudAccountResponse +// @Router /cloud-accounts [post] // @Security JWT -func (h *CloudSettingHandler) CreateCloudSetting(w http.ResponseWriter, r *http.Request) { - input := domain.CreateCloudSettingRequest{} +func (h *CloudAccountHandler) CreateCloudAccount(w http.ResponseWriter, r *http.Request) { + input := domain.CreateCloudAccountRequest{} err := UnmarshalRequestInput(r, &input) if err != nil { ErrorJSON(w, httpErrors.NewBadRequestError(err)) return } - var dto domain.CloudSetting + var dto domain.CloudAccount if err = domain.Map(input, &dto); err != nil { log.Info(err) } - cloudSettingId, err := h.usecase.Create(r.Context(), dto) + cloudAccountId, err := h.usecase.Create(r.Context(), dto) if err != nil { ErrorJSON(w, err) return } - var out domain.CreateCloudSettingResponse - out.ID = cloudSettingId.String() + var out domain.CreateCloudAccountResponse + out.ID = cloudAccountId.String() ResponseJSON(w, http.StatusOK, out) } -// GetCloudSetting godoc -// @Tags CloudSettings -// @Summary Get CloudSettings -// @Description Get CloudSettings +// GetCloudAccount godoc +// @Tags CloudAccounts +// @Summary Get CloudAccounts +// @Description Get CloudAccounts // @Accept json // @Produce json // @Param all query string false "show all organizations" -// @Success 200 {object} domain.GetCloudSettingsResponse -// @Router /cloud-settings [get] +// @Success 200 {object} domain.GetCloudAccountsResponse +// @Router /cloud-accounts [get] // @Security JWT -func (h *CloudSettingHandler) GetCloudSettings(w http.ResponseWriter, r *http.Request) { +func (h *CloudAccountHandler) GetCloudAccounts(w http.ResponseWriter, r *http.Request) { user, ok := request.UserFrom(r.Context()) if !ok { ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid token"))) @@ -86,16 +86,16 @@ func (h *CloudSettingHandler) GetCloudSettings(w http.ResponseWriter, r *http.Re return } - cloudSettings, err := h.usecase.Fetch(user.GetOrganizationId()) + cloudAccounts, err := h.usecase.Fetch(user.GetOrganizationId()) if err != nil { ErrorJSON(w, err) return } - var out domain.GetCloudSettingsResponse - out.CloudSettings = make([]domain.CloudSettingResponse, len(cloudSettings)) - for i, cloudSetting := range cloudSettings { - if err := domain.Map(cloudSetting, &out.CloudSettings[i]); err != nil { + var out domain.GetCloudAccountsResponse + out.CloudAccounts = make([]domain.CloudAccountResponse, len(cloudAccounts)) + for i, cloudAccount := range cloudAccounts { + if err := domain.Map(cloudAccount, &out.CloudAccounts[i]); err != nil { log.Info(err) continue } @@ -104,59 +104,59 @@ func (h *CloudSettingHandler) GetCloudSettings(w http.ResponseWriter, r *http.Re ResponseJSON(w, http.StatusOK, out) } -// GetCloudSetting godoc -// @Tags CloudSettings -// @Summary Get CloudSetting -// @Description Get CloudSetting +// GetCloudAccount godoc +// @Tags CloudAccounts +// @Summary Get CloudAccount +// @Description Get CloudAccount // @Accept json // @Produce json -// @Param cloudSettingId path string true "cloudSettingId" -// @Success 200 {object} domain.GetCloudSettingResponse -// @Router /cloud-settings/{cloudSettingId} [get] +// @Param cloudAccountId path string true "cloudAccountId" +// @Success 200 {object} domain.GetCloudAccountResponse +// @Router /cloud-accounts/{cloudAccountId} [get] // @Security JWT -func (h *CloudSettingHandler) GetCloudSetting(w http.ResponseWriter, r *http.Request) { +func (h *CloudAccountHandler) GetCloudAccount(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - strId, ok := vars["cloudSettingId"] + strId, ok := vars["cloudAccountId"] if !ok { - ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid cloudSettingId"))) + ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid cloudAccountId"))) return } - cloudSettingId, err := uuid.Parse(strId) + cloudAccountId, err := uuid.Parse(strId) if err != nil { ErrorJSON(w, httpErrors.NewBadRequestError(errors.Wrap(err, "Failed to parse uuid %s"))) return } - cloudSetting, err := h.usecase.Get(cloudSettingId) + cloudAccount, err := h.usecase.Get(cloudAccountId) if err != nil { ErrorJSON(w, err) return } - var out domain.GetCloudSettingResponse - if err := domain.Map(cloudSetting, &out.CloudSetting); err != nil { + var out domain.GetCloudAccountResponse + if err := domain.Map(cloudAccount, &out.CloudAccount); err != nil { log.Info(err) } ResponseJSON(w, http.StatusOK, out) } -// UpdateCloudSetting godoc -// @Tags CloudSettings -// @Summary Update CloudSetting -// @Description Update CloudSetting +// UpdateCloudAccount godoc +// @Tags CloudAccounts +// @Summary Update CloudAccount +// @Description Update CloudAccount // @Accept json // @Produce json -// @Param body body domain.UpdateCloudSettingRequest true "Update cloud setting request" +// @Param body body domain.UpdateCloudAccountRequest true "Update cloud setting request" // @Success 200 {object} nil -// @Router /cloud-settings/{cloudSettingId} [put] +// @Router /cloud-accounts/{cloudAccountId} [put] // @Security JWT -func (h *CloudSettingHandler) UpdateCloudSetting(w http.ResponseWriter, r *http.Request) { +func (h *CloudAccountHandler) UpdateCloudAccount(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - strId, ok := vars["cloudSettingId"] + strId, ok := vars["cloudAccountId"] if !ok { - ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid cloudSettingId"))) + ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid cloudAccountId"))) return } @@ -166,14 +166,14 @@ func (h *CloudSettingHandler) UpdateCloudSetting(w http.ResponseWriter, r *http. return } - input := domain.UpdateCloudSettingRequest{} + input := domain.UpdateCloudAccountRequest{} err = UnmarshalRequestInput(r, &input) if err != nil { ErrorJSON(w, httpErrors.NewBadRequestError(err)) return } - var dto domain.CloudSetting + var dto domain.CloudAccount if err = domain.Map(input, &dto); err != nil { log.Info(err) } @@ -188,39 +188,39 @@ func (h *CloudSettingHandler) UpdateCloudSetting(w http.ResponseWriter, r *http. ResponseJSON(w, http.StatusOK, nil) } -// DeleteCloudSetting godoc -// @Tags CloudSettings -// @Summary Delete CloudSetting -// @Description Delete CloudSetting +// DeleteCloudAccount godoc +// @Tags CloudAccounts +// @Summary Delete CloudAccount +// @Description Delete CloudAccount // @Accept json // @Produce json -// @Param body body domain.DeleteCloudSettingRequest true "Delete cloud setting request" -// @Param cloudSettingId path string true "cloudSettingId" +// @Param body body domain.DeleteCloudAccountRequest true "Delete cloud setting request" +// @Param cloudAccountId path string true "cloudAccountId" // @Success 200 {object} nil -// @Router /cloud-settings/{cloudSettingId} [delete] +// @Router /cloud-accounts/{cloudAccountId} [delete] // @Security JWT -func (h *CloudSettingHandler) DeleteCloudSetting(w http.ResponseWriter, r *http.Request) { +func (h *CloudAccountHandler) DeleteCloudAccount(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) - cloudSettingId, ok := vars["cloudSettingId"] + cloudAccountId, ok := vars["cloudAccountId"] if !ok { - ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid cloudSettingId"))) + ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid cloudAccountId"))) return } - parsedId, err := uuid.Parse(cloudSettingId) + parsedId, err := uuid.Parse(cloudAccountId) if err != nil { ErrorJSON(w, httpErrors.NewBadRequestError(errors.Wrap(err, "Failed to parse uuid"))) return } - input := domain.DeleteCloudSettingRequest{} + input := domain.DeleteCloudAccountRequest{} err = UnmarshalRequestInput(r, &input) if err != nil { ErrorJSON(w, httpErrors.NewBadRequestError(err)) return } - var dto domain.CloudSetting + var dto domain.CloudAccount if err = domain.Map(input, &dto); err != nil { log.Info(err) } @@ -235,17 +235,17 @@ func (h *CloudSettingHandler) DeleteCloudSetting(w http.ResponseWriter, r *http. ResponseJSON(w, http.StatusOK, nil) } -// CheckCloudSettingName godoc -// @Tags CloudSettings -// @Summary Check name for cloudSetting -// @Description Check name for cloudSetting +// CheckCloudAccountName godoc +// @Tags CloudAccounts +// @Summary Check name for cloudAccount +// @Description Check name for cloudAccount // @Accept json // @Produce json // @Param name path string true "name" // @Success 200 {object} nil -// @Router /cloud-settings/name/{name}/existence [GET] +// @Router /cloud-accounts/name/{name}/existence [GET] // @Security JWT -func (h *CloudSettingHandler) CheckCloudSettingName(w http.ResponseWriter, r *http.Request) { +func (h *CloudAccountHandler) CheckCloudAccountName(w http.ResponseWriter, r *http.Request) { user, ok := request.UserFrom(r.Context()) if !ok { ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid token"))) @@ -270,7 +270,7 @@ func (h *CloudSettingHandler) CheckCloudSettingName(w http.ResponseWriter, r *ht } } - var out domain.CheckCloudSettingNameResponse + var out domain.CheckCloudAccountNameResponse out.Existed = exist ResponseJSON(w, http.StatusOK, out) diff --git a/internal/repository/cloud-account.go b/internal/repository/cloud-account.go new file mode 100644 index 00000000..f533a641 --- /dev/null +++ b/internal/repository/cloud-account.go @@ -0,0 +1,134 @@ +package repository + +import ( + "github.com/google/uuid" + "gorm.io/gorm" + "gorm.io/gorm/clause" + + "github.com/openinfradev/tks-api/pkg/domain" +) + +// Interfaces +type ICloudAccountRepository interface { + Get(cloudAccountId uuid.UUID) (domain.CloudAccount, error) + GetByName(organizationId string, name string) (domain.CloudAccount, error) + Fetch(organizationId string) ([]domain.CloudAccount, error) + Create(dto domain.CloudAccount) (cloudAccountId uuid.UUID, err error) + Update(dto domain.CloudAccount) (err error) + Delete(dto domain.CloudAccount) (err error) +} + +type CloudAccountRepository struct { + db *gorm.DB +} + +func NewCloudAccountRepository(db *gorm.DB) ICloudAccountRepository { + return &CloudAccountRepository{ + db: db, + } +} + +// Models +type CloudAccount struct { + gorm.Model + + ID uuid.UUID `gorm:"primarykey"` + OrganizationId string + Organization Organization `gorm:"foreignKey:OrganizationId"` + Name string + Description string + Resource string + CloudService string + CreatorId *uuid.UUID `gorm:"type:uuid"` + Creator User `gorm:"foreignKey:CreatorId"` + UpdatorId *uuid.UUID `gorm:"type:uuid"` + Updator User `gorm:"foreignKey:UpdatorId"` +} + +func (c *CloudAccount) BeforeCreate(tx *gorm.DB) (err error) { + c.ID = uuid.New() + return nil +} + +// Logics +func (r *CloudAccountRepository) Get(cloudAccountId uuid.UUID) (out domain.CloudAccount, err error) { + var cloudAccount CloudAccount + res := r.db.Preload(clause.Associations).First(&cloudAccount, "id = ?", cloudAccountId) + if res.Error != nil { + return domain.CloudAccount{}, res.Error + } + out = reflectCloudAccount(cloudAccount) + return +} + +func (r *CloudAccountRepository) GetByName(organizationId string, name string) (out domain.CloudAccount, err error) { + var cloudAccount CloudAccount + res := r.db.Preload(clause.Associations).First(&cloudAccount, "organization_id = ? AND name = ?", organizationId, name) + + if res.Error != nil { + return domain.CloudAccount{}, res.Error + } + out = reflectCloudAccount(cloudAccount) + return +} + +func (r *CloudAccountRepository) Fetch(organizationId string) (out []domain.CloudAccount, err error) { + var cloudAccounts []CloudAccount + res := r.db.Preload(clause.Associations).Find(&cloudAccounts, "organization_id = ?", organizationId) + if res.Error != nil { + return nil, res.Error + } + + for _, cloudAccount := range cloudAccounts { + out = append(out, reflectCloudAccount(cloudAccount)) + } + return +} + +func (r *CloudAccountRepository) Create(dto domain.CloudAccount) (cloudAccountId uuid.UUID, err error) { + cloudAccount := CloudAccount{ + OrganizationId: dto.OrganizationId, + Name: dto.Name, + Description: dto.Description, + CloudService: dto.CloudService, + Resource: dto.Resource, + CreatorId: &dto.CreatorId} + res := r.db.Create(&cloudAccount) + if res.Error != nil { + return uuid.Nil, res.Error + } + return cloudAccount.ID, nil +} + +func (r *CloudAccountRepository) Update(dto domain.CloudAccount) (err error) { + res := r.db.Model(&CloudAccount{}). + Where("id = ?", dto.ID). + Updates(map[string]interface{}{"Description": dto.Description, "Resource": dto.Resource, "UpdatorId": dto.UpdatorId}) + if res.Error != nil { + return res.Error + } + return nil +} + +func (r *CloudAccountRepository) Delete(dto domain.CloudAccount) (err error) { + res := r.db.Delete(&CloudAccount{}, "id = ?", dto.ID) + if res.Error != nil { + return res.Error + } + return nil +} + +func reflectCloudAccount(cloudAccount CloudAccount) domain.CloudAccount { + return domain.CloudAccount{ + ID: cloudAccount.ID, + OrganizationId: cloudAccount.OrganizationId, + Name: cloudAccount.Name, + Description: cloudAccount.Description, + Resource: cloudAccount.Resource, + CloudService: cloudAccount.CloudService, + Creator: reflectUser(cloudAccount.Creator), + Updator: reflectUser(cloudAccount.Updator), + CreatedAt: cloudAccount.CreatedAt, + UpdatedAt: cloudAccount.UpdatedAt, + } +} diff --git a/internal/repository/cloud-setting.go b/internal/repository/cloud-setting.go deleted file mode 100644 index 16c79e4d..00000000 --- a/internal/repository/cloud-setting.go +++ /dev/null @@ -1,134 +0,0 @@ -package repository - -import ( - "github.com/google/uuid" - "gorm.io/gorm" - "gorm.io/gorm/clause" - - "github.com/openinfradev/tks-api/pkg/domain" -) - -// Interfaces -type ICloudSettingRepository interface { - Get(cloudSettingId uuid.UUID) (domain.CloudSetting, error) - GetByName(organizationId string, name string) (domain.CloudSetting, error) - Fetch(organizationId string) ([]domain.CloudSetting, error) - Create(dto domain.CloudSetting) (cloudSettingId uuid.UUID, err error) - Update(dto domain.CloudSetting) (err error) - Delete(dto domain.CloudSetting) (err error) -} - -type CloudSettingRepository struct { - db *gorm.DB -} - -func NewCloudSettingRepository(db *gorm.DB) ICloudSettingRepository { - return &CloudSettingRepository{ - db: db, - } -} - -// Models -type CloudSetting struct { - gorm.Model - - ID uuid.UUID `gorm:"primarykey"` - OrganizationId string - Organization Organization `gorm:"foreignKey:OrganizationId"` - Name string - Description string - Resource string - CloudService string - CreatorId *uuid.UUID `gorm:"type:uuid"` - Creator User `gorm:"foreignKey:CreatorId"` - UpdatorId *uuid.UUID `gorm:"type:uuid"` - Updator User `gorm:"foreignKey:UpdatorId"` -} - -func (c *CloudSetting) BeforeCreate(tx *gorm.DB) (err error) { - c.ID = uuid.New() - return nil -} - -// Logics -func (r *CloudSettingRepository) Get(cloudSettingId uuid.UUID) (out domain.CloudSetting, err error) { - var cloudSetting CloudSetting - res := r.db.Preload(clause.Associations).First(&cloudSetting, "id = ?", cloudSettingId) - if res.Error != nil { - return domain.CloudSetting{}, res.Error - } - out = reflectCloudSetting(cloudSetting) - return -} - -func (r *CloudSettingRepository) GetByName(organizationId string, name string) (out domain.CloudSetting, err error) { - var cloudSetting CloudSetting - res := r.db.Preload(clause.Associations).First(&cloudSetting, "organization_id = ? AND name = ?", organizationId, name) - - if res.Error != nil { - return domain.CloudSetting{}, res.Error - } - out = reflectCloudSetting(cloudSetting) - return -} - -func (r *CloudSettingRepository) Fetch(organizationId string) (out []domain.CloudSetting, err error) { - var cloudSettings []CloudSetting - res := r.db.Preload(clause.Associations).Find(&cloudSettings, "organization_id = ?", organizationId) - if res.Error != nil { - return nil, res.Error - } - - for _, cloudSetting := range cloudSettings { - out = append(out, reflectCloudSetting(cloudSetting)) - } - return -} - -func (r *CloudSettingRepository) Create(dto domain.CloudSetting) (cloudSettingId uuid.UUID, err error) { - cloudSetting := CloudSetting{ - OrganizationId: dto.OrganizationId, - Name: dto.Name, - Description: dto.Description, - CloudService: dto.CloudService, - Resource: dto.Resource, - CreatorId: &dto.CreatorId} - res := r.db.Create(&cloudSetting) - if res.Error != nil { - return uuid.Nil, res.Error - } - return cloudSetting.ID, nil -} - -func (r *CloudSettingRepository) Update(dto domain.CloudSetting) (err error) { - res := r.db.Model(&CloudSetting{}). - Where("id = ?", dto.ID). - Updates(map[string]interface{}{"Description": dto.Description, "Resource": dto.Resource, "UpdatorId": dto.UpdatorId}) - if res.Error != nil { - return res.Error - } - return nil -} - -func (r *CloudSettingRepository) Delete(dto domain.CloudSetting) (err error) { - res := r.db.Delete(&CloudSetting{}, "id = ?", dto.ID) - if res.Error != nil { - return res.Error - } - return nil -} - -func reflectCloudSetting(cloudSetting CloudSetting) domain.CloudSetting { - return domain.CloudSetting{ - ID: cloudSetting.ID, - OrganizationId: cloudSetting.OrganizationId, - Name: cloudSetting.Name, - Description: cloudSetting.Description, - Resource: cloudSetting.Resource, - CloudService: cloudSetting.CloudService, - Creator: reflectUser(cloudSetting.Creator), - Updator: reflectUser(cloudSetting.Updator), - CreatedAt: cloudSetting.CreatedAt, - UpdatedAt: cloudSetting.UpdatedAt, - } -} diff --git a/internal/repository/cluster.go b/internal/repository/cluster.go index 8c71dcca..54609444 100644 --- a/internal/repository/cluster.go +++ b/internal/repository/cluster.go @@ -17,7 +17,7 @@ type IClusterRepository interface { WithTrx(*gorm.DB) IClusterRepository Fetch() (res []domain.Cluster, err error) FetchByOrganizationId(organizationId string) (res []domain.Cluster, err error) - FetchByCloudSettingId(cloudSettingId uuid.UUID) (res []domain.Cluster, err error) + FetchByCloudAccountId(cloudAccountId uuid.UUID) (res []domain.Cluster, err error) Get(id domain.ClusterId) (domain.Cluster, error) GetByName(organizationId string, name string) (domain.Cluster, error) Create(dto domain.Cluster) (clusterId domain.ClusterId, err error) @@ -55,8 +55,8 @@ type Cluster struct { WorkflowId string Status domain.ClusterStatus StatusDesc string - CloudSettingId uuid.UUID - CloudSetting CloudSetting `gorm:"foreignKey:CloudSettingId"` + CloudAccountId uuid.UUID + CloudAccount CloudAccount `gorm:"foreignKey:CloudAccountId"` StackTemplateId uuid.UUID StackTemplate StackTemplate `gorm:"foreignKey:StackTemplateId"` CreatorId *uuid.UUID `gorm:"type:uuid"` @@ -114,10 +114,10 @@ func (r *ClusterRepository) FetchByOrganizationId(organizationId string) (out [] return } -func (r *ClusterRepository) FetchByCloudSettingId(cloudSettingId uuid.UUID) (out []domain.Cluster, err error) { +func (r *ClusterRepository) FetchByCloudAccountId(cloudAccountId uuid.UUID) (out []domain.Cluster, err error) { var clusters []Cluster - res := r.db.Preload("CloudSetting").Order("updated_at desc, created_at desc").Find(&clusters, "cloud_setting_id = ?", cloudSettingId) + res := r.db.Preload("CloudAccount").Order("updated_at desc, created_at desc").Find(&clusters, "cloud_account_id = ?", cloudAccountId) if res.Error != nil { return nil, res.Error @@ -160,7 +160,7 @@ func (r *ClusterRepository) Create(dto domain.Cluster) (clusterId domain.Cluster OrganizationId: dto.OrganizationId, Name: dto.Name, Description: dto.Description, - CloudSettingId: dto.CloudSettingId, + CloudAccountId: dto.CloudAccountId, StackTemplateId: dto.StackTemplateId, CreatorId: dto.CreatorId, UpdatorId: nil, @@ -208,8 +208,8 @@ func reflectCluster(cluster Cluster) domain.Cluster { OrganizationId: cluster.OrganizationId, Name: cluster.Name, Description: cluster.Description, - CloudSettingId: cluster.CloudSettingId, - CloudSetting: reflectCloudSetting(cluster.CloudSetting), + CloudAccountId: cluster.CloudAccountId, + CloudAccount: reflectCloudAccount(cluster.CloudAccount), StackTemplateId: cluster.StackTemplateId, StackTemplate: reflectStackTemplate(cluster.StackTemplate), Status: cluster.Status, diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 98734909..73b15eee 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -10,7 +10,7 @@ type Repository struct { Organization IOrganizationRepository AppGroup IAppGroupRepository AppServeApp IAppServeAppRepository - CloudSetting ICloudSettingRepository + CloudAccount ICloudAccountRepository StackTemplate IStackTemplateRepository History IHistoryRepository } diff --git a/internal/route/route.go b/internal/route/route.go index 929e24a1..418a9230 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -60,7 +60,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, asset http.Handler, Organization: repository.NewOrganizationRepository(db), AppGroup: repository.NewAppGroupRepository(db), AppServeApp: repository.NewAppServeAppRepository(db), - CloudSetting: repository.NewCloudSettingRepository(db), + CloudAccount: repository.NewCloudAccountRepository(db), StackTemplate: repository.NewStackTemplateRepository(db), History: repository.NewHistoryRepository(db), } @@ -111,13 +111,13 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, asset http.Handler, r.Handle(API_PREFIX+API_VERSION+"/app-serve-apps/{appId}/status", authMiddleware(http.HandlerFunc(appServeAppHandler.UpdateAppServeAppStatus), kc)).Methods(http.MethodPatch) r.Handle(API_PREFIX+API_VERSION+"/app-serve-apps/{appId}/endpoint", authMiddleware(http.HandlerFunc(appServeAppHandler.UpdateAppServeAppEndpoint), kc)).Methods(http.MethodPatch) - cloudSettingHandler := delivery.NewCloudSettingHandler(usecase.NewCloudSettingUsecase(repoFactory, argoClient)) - r.Handle(API_PREFIX+API_VERSION+"/cloud-settings", authMiddleware(http.HandlerFunc(cloudSettingHandler.GetCloudSettings), kc)).Methods(http.MethodGet) - r.Handle(API_PREFIX+API_VERSION+"/cloud-settings", authMiddleware(http.HandlerFunc(cloudSettingHandler.CreateCloudSetting), kc)).Methods(http.MethodPost) - r.Handle(API_PREFIX+API_VERSION+"/cloud-settings/name/{name}/existence", authMiddleware(http.HandlerFunc(cloudSettingHandler.CheckCloudSettingName), kc)).Methods(http.MethodGet) - r.Handle(API_PREFIX+API_VERSION+"/cloud-settings/{cloudSettingId}", authMiddleware(http.HandlerFunc(cloudSettingHandler.GetCloudSetting), kc)).Methods(http.MethodGet) - r.Handle(API_PREFIX+API_VERSION+"/cloud-settings/{cloudSettingId}", authMiddleware(http.HandlerFunc(cloudSettingHandler.UpdateCloudSetting), kc)).Methods(http.MethodPut) - r.Handle(API_PREFIX+API_VERSION+"/cloud-settings/{cloudSettingId}", authMiddleware(http.HandlerFunc(cloudSettingHandler.DeleteCloudSetting), kc)).Methods(http.MethodDelete) + cloudAccountHandler := delivery.NewCloudAccountHandler(usecase.NewCloudAccountUsecase(repoFactory, argoClient)) + r.Handle(API_PREFIX+API_VERSION+"/cloud-accounts", authMiddleware(http.HandlerFunc(cloudAccountHandler.GetCloudAccounts), kc)).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/cloud-accounts", authMiddleware(http.HandlerFunc(cloudAccountHandler.CreateCloudAccount), kc)).Methods(http.MethodPost) + r.Handle(API_PREFIX+API_VERSION+"/cloud-accounts/name/{name}/existence", authMiddleware(http.HandlerFunc(cloudAccountHandler.CheckCloudAccountName), kc)).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/cloud-accounts/{cloudAccountId}", authMiddleware(http.HandlerFunc(cloudAccountHandler.GetCloudAccount), kc)).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/cloud-accounts/{cloudAccountId}", authMiddleware(http.HandlerFunc(cloudAccountHandler.UpdateCloudAccount), kc)).Methods(http.MethodPut) + r.Handle(API_PREFIX+API_VERSION+"/cloud-accounts/{cloudAccountId}", authMiddleware(http.HandlerFunc(cloudAccountHandler.DeleteCloudAccount), kc)).Methods(http.MethodDelete) stackTemplateHandler := delivery.NewStackTemplateHandler(usecase.NewStackTemplateUsecase(repoFactory)) r.Handle(API_PREFIX+API_VERSION+"/stack-templates", authMiddleware(http.HandlerFunc(stackTemplateHandler.GetStackTemplates), kc)).Methods(http.MethodGet) diff --git a/internal/usecase/cloud-setting.go b/internal/usecase/cloud-account.go similarity index 55% rename from internal/usecase/cloud-setting.go rename to internal/usecase/cloud-account.go index c1a711e3..9adf84c3 100644 --- a/internal/usecase/cloud-setting.go +++ b/internal/usecase/cloud-account.go @@ -15,30 +15,30 @@ import ( "gorm.io/gorm" ) -type ICloudSettingUsecase interface { - Get(cloudSettingId uuid.UUID) (domain.CloudSetting, error) - GetByName(organizationId string, name string) (domain.CloudSetting, error) - Fetch(organizationId string) ([]domain.CloudSetting, error) - Create(ctx context.Context, dto domain.CloudSetting) (cloudSettingId uuid.UUID, err error) - Update(ctx context.Context, dto domain.CloudSetting) error - Delete(ctx context.Context, dto domain.CloudSetting) error +type ICloudAccountUsecase interface { + Get(cloudAccountId uuid.UUID) (domain.CloudAccount, error) + GetByName(organizationId string, name string) (domain.CloudAccount, error) + Fetch(organizationId string) ([]domain.CloudAccount, error) + Create(ctx context.Context, dto domain.CloudAccount) (cloudAccountId uuid.UUID, err error) + Update(ctx context.Context, dto domain.CloudAccount) error + Delete(ctx context.Context, dto domain.CloudAccount) error } -type CloudSettingUsecase struct { - repo repository.ICloudSettingRepository +type CloudAccountUsecase struct { + repo repository.ICloudAccountRepository clusterRepo repository.IClusterRepository argo argowf.ArgoClient } -func NewCloudSettingUsecase(r repository.Repository, argoClient argowf.ArgoClient) ICloudSettingUsecase { - return &CloudSettingUsecase{ - repo: r.CloudSetting, +func NewCloudAccountUsecase(r repository.Repository, argoClient argowf.ArgoClient) ICloudAccountUsecase { + return &CloudAccountUsecase{ + repo: r.CloudAccount, clusterRepo: r.Cluster, argo: argoClient, } } -func (u *CloudSettingUsecase) Create(ctx context.Context, dto domain.CloudSetting) (cloudSettingId uuid.UUID, err error) { +func (u *CloudAccountUsecase) Create(ctx context.Context, dto domain.CloudAccount) (cloudAccountId uuid.UUID, err error) { user, ok := request.UserFrom(ctx) if !ok { return uuid.Nil, httpErrors.NewBadRequestError(fmt.Errorf("Invalid token")) @@ -52,18 +52,18 @@ func (u *CloudSettingUsecase) Create(ctx context.Context, dto domain.CloudSettin return uuid.Nil, httpErrors.NewBadRequestError(httpErrors.DuplicateResource) } - cloudSettingId, err = u.repo.Create(dto) + cloudAccountId, err = u.repo.Create(dto) if err != nil { return uuid.Nil, httpErrors.NewInternalServerError(err) } - log.Info("newly created CloudSetting ID:", cloudSettingId) + log.Info("newly created CloudAccount ID:", cloudAccountId) /* workflowId, err := u.argo.SumbitWorkflowFromWftpl( "tks-create-contract-repo", argowf.SubmitOptions{ Parameters: []string{ - "contract_id=" + cloudSettingId, + "contract_id=" + cloudAccountId, }, }) if err != nil { @@ -71,15 +71,15 @@ func (u *CloudSettingUsecase) Create(ctx context.Context, dto domain.CloudSettin return "", fmt.Errorf("Failed to call argo workflow : %s", err) } log.Info("submited workflow :", workflowId) - if err := u.repo.InitWorkflow(cloudSettingId, workflowId); err != nil { - return "", fmt.Errorf("Failed to initialize cloudSetting status to 'CREATING'. err : %s", err) + if err := u.repo.InitWorkflow(cloudAccountId, workflowId); err != nil { + return "", fmt.Errorf("Failed to initialize cloudAccount status to 'CREATING'. err : %s", err) } */ - return cloudSettingId, nil + return cloudAccountId, nil } -func (u *CloudSettingUsecase) Update(ctx context.Context, dto domain.CloudSetting) error { +func (u *CloudAccountUsecase) Update(ctx context.Context, dto domain.CloudAccount) error { user, ok := request.UserFrom(ctx) if !ok { return httpErrors.NewBadRequestError(fmt.Errorf("Invalid token")) @@ -94,29 +94,29 @@ func (u *CloudSettingUsecase) Update(ctx context.Context, dto domain.CloudSettin return nil } -func (u *CloudSettingUsecase) Get(cloudSettingId uuid.UUID) (res domain.CloudSetting, err error) { - res, err = u.repo.Get(cloudSettingId) +func (u *CloudAccountUsecase) Get(cloudAccountId uuid.UUID) (res domain.CloudAccount, err error) { + res, err = u.repo.Get(cloudAccountId) if err != nil { - return domain.CloudSetting{}, err + return domain.CloudAccount{}, err } - res.Clusters = u.getClusterCnt(cloudSettingId) + res.Clusters = u.getClusterCnt(cloudAccountId) return } -func (u *CloudSettingUsecase) GetByName(organizationId string, name string) (res domain.CloudSetting, err error) { +func (u *CloudAccountUsecase) GetByName(organizationId string, name string) (res domain.CloudAccount, err error) { res, err = u.repo.GetByName(organizationId, name) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { - return domain.CloudSetting{}, httpErrors.NewNotFoundError(err) + return domain.CloudAccount{}, httpErrors.NewNotFoundError(err) } - return domain.CloudSetting{}, err + return domain.CloudAccount{}, err } return } -func (u *CloudSettingUsecase) Fetch(organizationId string) (res []domain.CloudSetting, err error) { +func (u *CloudAccountUsecase) Fetch(organizationId string) (res []domain.CloudAccount, err error) { res, err = u.repo.Fetch(organizationId) if err != nil { return nil, err @@ -124,7 +124,7 @@ func (u *CloudSettingUsecase) Fetch(organizationId string) (res []domain.CloudSe return res, nil } -func (u *CloudSettingUsecase) Delete(ctx context.Context, dto domain.CloudSetting) (err error) { +func (u *CloudAccountUsecase) Delete(ctx context.Context, dto domain.CloudAccount) (err error) { user, ok := request.UserFrom(ctx) if !ok { return httpErrors.NewBadRequestError(fmt.Errorf("Invalid token")) @@ -145,12 +145,12 @@ func (u *CloudSettingUsecase) Delete(ctx context.Context, dto domain.CloudSettin return nil } -func (u *CloudSettingUsecase) getClusterCnt(cloudSettingId uuid.UUID) (cnt int) { +func (u *CloudAccountUsecase) getClusterCnt(cloudAccountId uuid.UUID) (cnt int) { cnt = 0 - clusters, err := u.clusterRepo.FetchByCloudSettingId(cloudSettingId) + clusters, err := u.clusterRepo.FetchByCloudAccountId(cloudAccountId) if err != nil { - log.Error("Failed to get clusters by cloudSettingId. err : ", err) + log.Error("Failed to get clusters by cloudAccountId. err : ", err) return cnt } diff --git a/internal/usecase/cluster.go b/internal/usecase/cluster.go index ebc1ce66..ec5283ef 100644 --- a/internal/usecase/cluster.go +++ b/internal/usecase/cluster.go @@ -20,7 +20,7 @@ import ( type IClusterUsecase interface { WithTrx(*gorm.DB) IClusterUsecase Fetch(organizationId string) ([]domain.Cluster, error) - FetchByCloudSettingId(cloudSettingId uuid.UUID) (out []domain.Cluster, err error) + FetchByCloudAccountId(cloudAccountId uuid.UUID) (out []domain.Cluster, err error) Create(ctx context.Context, dto domain.Cluster) (clusterId domain.ClusterId, err error) Get(clusterId domain.ClusterId) (out domain.Cluster, err error) Delete(clusterId domain.ClusterId) (err error) @@ -88,9 +88,9 @@ func (u *ClusterUsecase) Fetch(organizationId string) (out []domain.Cluster, err return out, nil } -func (u *ClusterUsecase) FetchByCloudSettingId(cloudSettingId uuid.UUID) (out []domain.Cluster, err error) { - if cloudSettingId == uuid.Nil { - return nil, fmt.Errorf("Invalid cloudSettingId") +func (u *ClusterUsecase) FetchByCloudAccountId(cloudAccountId uuid.UUID) (out []domain.Cluster, err error) { + if cloudAccountId == uuid.Nil { + return nil, fmt.Errorf("Invalid cloudAccountId") } out, err = u.repo.Fetch() diff --git a/internal/usecase/dashboard.go b/internal/usecase/dashboard.go index bb66cf88..18050824 100644 --- a/internal/usecase/dashboard.go +++ b/internal/usecase/dashboard.go @@ -44,11 +44,6 @@ func (u *DashboardUsecase) GetCharts(organizationId string, chartType domain.Cha out = append(out, chart) } - // [TODO] For sample data - if chartType == domain.ChartType_TRAFFIC { - - } - return } diff --git a/internal/usecase/stack.go b/internal/usecase/stack.go index 5ede0713..0090633c 100644 --- a/internal/usecase/stack.go +++ b/internal/usecase/stack.go @@ -78,7 +78,7 @@ func (u *StackUsecase) Create(ctx context.Context, dto domain.Stack) (err error) "cluster_name=" + dto.Name, "description=" + dto.Description, "organization_id=" + dto.OrganizationId, - "cloud_account_id=" + dto.CloudSettingId.String(), + "cloud_account_id=" + dto.CloudAccountId.String(), "stack_template_id=" + dto.StackTemplateId.String(), "creator=" + user.GetUserId().String(), /* @@ -95,28 +95,21 @@ func (u *StackUsecase) Create(ctx context.Context, dto domain.Stack) (err error) log.Debug("Submitted workflow: ", workflowId) // wait & get clusterId ( max 1min ) - cnt := 0 - - ticker := time.NewTicker(time.Second * 2) - for range ticker.C { - if cnt >= 60 { // max wait 60sec - break - } - + for i := 0; i < 60; i++ { + time.Sleep(time.Second * 2) workflow, err := u.argo.GetWorkflow("argo", workflowId) if err != nil { return err } - if workflow.Status.Phase != "Running" { - return err + if workflow.Status.Phase != "" && workflow.Status.Phase != "Running" { + return fmt.Errorf("Invalid workflow status") } if workflow.Status.Progress == "1/2" { // start creating cluster time.Sleep(time.Second * 5) // Buffer break } - cnt += 1 } // [TODO] need clusterId? @@ -204,27 +197,21 @@ func (u *StackUsecase) Delete(ctx context.Context, dto domain.Stack) (err error) log.Debug("Submitted workflow: ", workflowId) // wait & get clusterId ( max 1min ) - cnt := 0 - ticker := time.NewTicker(time.Second * 2) - for range ticker.C { - if cnt >= 60 { // max wait 60sec - break - } - + for i := 0; i < 60; i++ { + time.Sleep(time.Second * 2) workflow, err := u.argo.GetWorkflow("argo", workflowId) if err != nil { return err } - if workflow.Status.Phase != "Running" { - return err + if workflow.Status.Phase != "" && workflow.Status.Phase != "Running" { + return fmt.Errorf("Invalid workflow status") } - if workflow.Status.Progress == "1/2" { // start deleting service - time.Sleep(time.Second * 10) // Buffer + if workflow.Status.Progress == "1/2" { // start creating cluster + time.Sleep(time.Second * 5) // Buffer break } - cnt += 1 } return nil @@ -240,8 +227,8 @@ func reflectClusterToStack(cluster domain.Cluster) domain.Stack { Description: cluster.Description, Status: status, StatusDesc: statusDesc, - CloudSettingId: cluster.CloudSettingId, - CloudSetting: cluster.CloudSetting, + CloudAccountId: cluster.CloudAccountId, + CloudAccount: cluster.CloudAccount, StackTemplateId: cluster.StackTemplateId, StackTemplate: cluster.StackTemplate, CreatorId: cluster.CreatorId, diff --git a/pkg/domain/cloud-setting.go b/pkg/domain/cloud-account.go similarity index 80% rename from pkg/domain/cloud-setting.go rename to pkg/domain/cloud-account.go index 29f10b13..60d70f82 100644 --- a/pkg/domain/cloud-setting.go +++ b/pkg/domain/cloud-account.go @@ -14,7 +14,7 @@ const ( ) // 내부 -type CloudSetting struct { +type CloudAccount struct { ID uuid.UUID OrganizationId string Name string @@ -30,7 +30,7 @@ type CloudSetting struct { UpdatedAt time.Time } -type CloudSettingResponse struct { +type CloudAccountResponse struct { ID string `json:"id"` OrganizationId string `json:"organizationId"` Name string `json:"name"` @@ -44,15 +44,15 @@ type CloudSettingResponse struct { UpdatedAt time.Time `json:"updatedAt"` } -type GetCloudSettingsResponse struct { - CloudSettings []CloudSettingResponse `json:"cloudSettings"` +type GetCloudAccountsResponse struct { + CloudAccounts []CloudAccountResponse `json:"cloudAccounts"` } -type GetCloudSettingResponse struct { - CloudSetting CloudSettingResponse `json:"cloudSetting"` +type GetCloudAccountResponse struct { + CloudAccount CloudAccountResponse `json:"cloudAccount"` } -type CreateCloudSettingRequest struct { +type CreateCloudAccountRequest struct { OrganizationId string `json:"organizationId" validate:"required"` Name string `json:"name" validate:"required"` Description string `json:"description"` @@ -62,20 +62,20 @@ type CreateCloudSettingRequest struct { SessionToken string `json:"sessionToken" validate:"max=2000"` } -type CreateCloudSettingResponse struct { +type CreateCloudAccountResponse struct { ID string `json:"id"` } -type UpdateCloudSettingRequest struct { +type UpdateCloudAccountRequest struct { Description string `json:"description"` } -type DeleteCloudSettingRequest struct { +type DeleteCloudAccountRequest struct { 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 { +type CheckCloudAccountNameResponse struct { Existed bool `json:"existed"` } diff --git a/pkg/domain/cluster.go b/pkg/domain/cluster.go index cf3e04a1..a9d44471 100644 --- a/pkg/domain/cluster.go +++ b/pkg/domain/cluster.go @@ -54,8 +54,8 @@ type Cluster = struct { OrganizationId string Name string Description string - CloudSettingId uuid.UUID - CloudSetting CloudSetting + CloudAccountId uuid.UUID + CloudAccount CloudAccount StackTemplateId uuid.UUID StackTemplate StackTemplate Status ClusterStatus @@ -119,7 +119,7 @@ type CreateClusterRequest struct { StackTemplateId string `json:"stackTemplateId"` Name string `json:"name"` Description string `json:"description"` - CloudSettingId string `json:"cloudSettingId"` + CloudAccountId string `json:"cloudAccountId"` NumOfAz int `json:"numOfAz"` MachineType string `json:"machineType"` Region string `json:"region"` @@ -135,7 +135,7 @@ type ClusterResponse struct { OrganizationId string `json:"organizationId"` Name string `json:"name"` Description string `json:"description"` - CloudSetting CloudSettingResponse `json:"cloudSetting"` + CloudAccount CloudAccountResponse `json:"cloudAccount"` StackTemplate StackTemplateResponse `json:"stackTemplate"` Status string `json:"status"` StatusDesc string `json:"statusDesc"` diff --git a/pkg/domain/stack.go b/pkg/domain/stack.go index f7665044..786ca675 100644 --- a/pkg/domain/stack.go +++ b/pkg/domain/stack.go @@ -54,8 +54,8 @@ type Stack = struct { Name string Description string OrganizationId string - CloudSettingId uuid.UUID - CloudSetting CloudSetting + CloudAccountId uuid.UUID + CloudAccount CloudAccount StackTemplateId uuid.UUID StackTemplate StackTemplate Status StackStatus @@ -76,7 +76,7 @@ type CreateStackRequest struct { Name string `json:"name"` Description string `json:"description"` StackTemplateId string `json:"stackTemplateId"` - CloudSettingId string `json:"cloudSettingId"` + CloudAccountId string `json:"cloudAccountId"` CpNodeCnt int `json:"cpNodeCnt"` TksNodeCnt int `json:"tksNodeCnt"` UserNodeCnt int `json:"userNodeCnt"` @@ -92,7 +92,7 @@ type StackResponse struct { Description string `json:"description"` OrganizationId string `json:"organizationId"` StackTemplate StackTemplateResponse `json:"stackTemplate,omitempty"` - CloudSetting CloudSettingResponse `json:"cloudSetting,omitempty"` + CloudAccount CloudAccountResponse `json:"cloudAccount,omitempty"` Status string `json:"status"` StatusDesc string `json:"statusDesc"` PrimaryCluster bool `json:"primaryCluster"` diff --git a/scripts/init_postgres.sql b/scripts/init_postgres.sql index f22dd79a..d8c600c8 100644 --- a/scripts/init_postgres.sql +++ b/scripts/init_postgres.sql @@ -15,7 +15,7 @@ insert into policies ( role_id, name, description, c, create_priviledge, u, upda insert into organizations ( id, name, description, created_at, updated_at ) values ( 'master', 'master', 'tks', now(), now() ); insert into users ( id, account_id, name, password, organization_id, role_id, created_at, updated_at ) values ( 'bf67de40-ce15-4dc0-b6c2-17f053ca504f', 'admin', 'admin', '$2a$10$Akf03nbLHk93sTtozm35XuINXkJeNX7A1T9o/Pxpg9R2B2PToBPOO', 'master', 'b2b689f0-ceeb-46c2-b280-0bc06896acd1', now(), now() ); -insert into cloud_settings ( id, name, description, organization_id, cloud_service, resource, created_at, updated_at ) +insert into cloud_accounts ( id, name, description, organization_id, cloud_service, resource, created_at, updated_at ) values ( 'ce9e0387-01cb-4f37-a22a-fb91b6338434', 'aws', 'aws_description', 'master', 'AWS', 'result', now(), now() ); insert into stack_templates ( id, organization_id, name, description, version, cloud_service, platform, template, kube_version, kube_type, created_at, updated_at, services )