diff --git a/api/swagger/docs.go b/api/swagger/docs.go index f91cf948..6c16a985 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -1,4 +1,5 @@ -// Code generated by swaggo/swag. DO NOT EDIT +// Package swagger GENERATED BY SWAG; DO NOT EDIT +// This file was generated by swaggo/swag package swagger import "github.com/swaggo/swag" @@ -1196,7 +1197,7 @@ const docTemplate = `{ "JWT": [] } ], - "description": "Get chart data", + "description": "Get charts data", "consumes": [ "application/json" ], @@ -1206,7 +1207,7 @@ const docTemplate = `{ "tags": [ "Dashboards" ], - "summary": "Get chart data", + "summary": "Get charts data", "parameters": [ { "type": "string", @@ -1246,6 +1247,64 @@ const docTemplate = `{ } } }, + "/organizations/{organizationId}/dashboard/charts/{chartType}": { + "get": { + "security": [ + { + "JWT": [] + } + ], + "description": "Get chart data", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Dashboards" + ], + "summary": "Get chart data", + "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "chartType", + "name": "chartType", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "duration", + "name": "duration", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "interval", + "name": "interval", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.GetDashboardChartResponse" + } + } + } + } + }, "/organizations/{organizationId}/primary-cluster": { "patch": { "security": [ @@ -2054,7 +2113,7 @@ const docTemplate = `{ "type": "object", "properties": { "appGroupType": { - "$ref": "#/definitions/domain.AppGroupType" + "type": "integer" }, "clusterId": { "type": "string" @@ -2075,7 +2134,7 @@ const docTemplate = `{ "type": "string" }, "status": { - "$ref": "#/definitions/domain.AppGroupStatus" + "type": "integer" }, "statusDescription": { "type": "string" @@ -2091,38 +2150,6 @@ const docTemplate = `{ } } }, - "domain.AppGroupStatus": { - "type": "integer", - "enum": [ - 0, - 1, - 2, - 3, - 4, - 5 - ], - "x-enum-varnames": [ - "AppGroupStatus_PENDING", - "AppGroupStatus_INSTALLING", - "AppGroupStatus_RUNNING", - "AppGroupStatus_DELETING", - "AppGroupStatus_DELETED", - "AppGroupStatus_ERROR" - ] - }, - "domain.AppGroupType": { - "type": "integer", - "enum": [ - 0, - 1, - 2 - ], - "x-enum-varnames": [ - "AppGroupType_UNSPECIFIED", - "AppGroupType_LMA", - "AppGroupType_SERVICE_MESH" - ] - }, "domain.AppServeApp": { "type": "object", "properties": { @@ -2279,7 +2306,7 @@ const docTemplate = `{ "type": "string" }, "applicationType": { - "$ref": "#/definitions/domain.ApplicationType" + "type": "integer" }, "createdAt": { "type": "string" @@ -2298,34 +2325,16 @@ const docTemplate = `{ } } }, - "domain.ApplicationType": { - "type": "integer", - "enum": [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ], - "x-enum-varnames": [ - "ApplicationType_UNSPECIFIED", - "ApplicationType_THANOS", - "ApplicationType_PROMETHEUS", - "ApplicationType_GRAFANA", - "ApplicationType_KIALI", - "ApplicationType_KIBANA", - "ApplicationType_ELASTICSERCH", - "ApplicationType_CLOUD_CONSOLE", - "ApplicationType_HORIZON", - "ApplicationType_JAEGER", - "ApplicationType_KUBERNETES_DASHBOARD" - ] + "domain.Axis": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string" + } + } + } }, "domain.ChartData": { "type": "object", @@ -2336,33 +2345,11 @@ const docTemplate = `{ "$ref": "#/definitions/domain.Unit" } }, - "xaxis": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "type": "string" - } - }, - "type": { - "type": "string" - } - } + "xAxis": { + "$ref": "#/definitions/domain.Axis" }, - "yaxis": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "type": "string" - } - }, - "type": { - "type": "string" - } - } + "yAxis": { + "$ref": "#/definitions/domain.Axis" } } }, @@ -2488,7 +2475,7 @@ const docTemplate = `{ "type": "string" }, "status": { - "$ref": "#/definitions/domain.ClusterStatus" + "type": "integer" }, "statusDesc": { "type": "string" @@ -2600,25 +2587,6 @@ const docTemplate = `{ } } }, - "domain.ClusterStatus": { - "type": "integer", - "enum": [ - 0, - 1, - 2, - 3, - 4, - 5 - ], - "x-enum-varnames": [ - "ClusterStatus_PENDING", - "ClusterStatus_INSTALLING", - "ClusterStatus_RUNNING", - "ClusterStatus_DELETING", - "ClusterStatus_DELETED", - "ClusterStatus_ERROR" - ] - }, "domain.CreateAppGroupRequest": { "type": "object", "required": [ @@ -3119,6 +3087,14 @@ const docTemplate = `{ } } }, + "domain.GetDashboardChartResponse": { + "type": "object", + "properties": { + "chart": { + "$ref": "#/definitions/domain.DashboardChartResponse" + } + } + }, "domain.GetDashboardChartsResponse": { "type": "object", "properties": { @@ -3296,7 +3272,7 @@ const docTemplate = `{ "type": "string" }, "status": { - "$ref": "#/definitions/domain.OrganizationStatus" + "type": "integer" }, "updatedAt": { "type": "string" @@ -3410,7 +3386,7 @@ const docTemplate = `{ "type": "string" }, "status": { - "$ref": "#/definitions/domain.OrganizationStatus" + "type": "integer" }, "statusDescription": { "type": "string" @@ -3420,29 +3396,6 @@ const docTemplate = `{ } } }, - "domain.OrganizationStatus": { - "type": "integer", - "enum": [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7 - ], - "x-enum-varnames": [ - "OrganizationStatus_PENDING", - "OrganizationStatus_CREATE", - "OrganizationStatus_CREATING", - "OrganizationStatus_CREATED", - "OrganizationStatus_DELETE", - "OrganizationStatus_DELETING", - "OrganizationStatus_DELETED", - "OrganizationStatus_ERROR" - ] - }, "domain.Role": { "type": "object", "properties": { diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index ff72f5b9..99050103 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -1190,7 +1190,7 @@ "JWT": [] } ], - "description": "Get chart data", + "description": "Get charts data", "consumes": [ "application/json" ], @@ -1200,7 +1200,7 @@ "tags": [ "Dashboards" ], - "summary": "Get chart data", + "summary": "Get charts data", "parameters": [ { "type": "string", @@ -1240,6 +1240,64 @@ } } }, + "/organizations/{organizationId}/dashboard/charts/{chartType}": { + "get": { + "security": [ + { + "JWT": [] + } + ], + "description": "Get chart data", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Dashboards" + ], + "summary": "Get chart data", + "parameters": [ + { + "type": "string", + "description": "organizationId", + "name": "organizationId", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "chartType", + "name": "chartType", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "duration", + "name": "duration", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "interval", + "name": "interval", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/domain.GetDashboardChartResponse" + } + } + } + } + }, "/organizations/{organizationId}/primary-cluster": { "patch": { "security": [ @@ -2048,7 +2106,7 @@ "type": "object", "properties": { "appGroupType": { - "$ref": "#/definitions/domain.AppGroupType" + "type": "integer" }, "clusterId": { "type": "string" @@ -2069,7 +2127,7 @@ "type": "string" }, "status": { - "$ref": "#/definitions/domain.AppGroupStatus" + "type": "integer" }, "statusDescription": { "type": "string" @@ -2085,38 +2143,6 @@ } } }, - "domain.AppGroupStatus": { - "type": "integer", - "enum": [ - 0, - 1, - 2, - 3, - 4, - 5 - ], - "x-enum-varnames": [ - "AppGroupStatus_PENDING", - "AppGroupStatus_INSTALLING", - "AppGroupStatus_RUNNING", - "AppGroupStatus_DELETING", - "AppGroupStatus_DELETED", - "AppGroupStatus_ERROR" - ] - }, - "domain.AppGroupType": { - "type": "integer", - "enum": [ - 0, - 1, - 2 - ], - "x-enum-varnames": [ - "AppGroupType_UNSPECIFIED", - "AppGroupType_LMA", - "AppGroupType_SERVICE_MESH" - ] - }, "domain.AppServeApp": { "type": "object", "properties": { @@ -2273,7 +2299,7 @@ "type": "string" }, "applicationType": { - "$ref": "#/definitions/domain.ApplicationType" + "type": "integer" }, "createdAt": { "type": "string" @@ -2292,34 +2318,16 @@ } } }, - "domain.ApplicationType": { - "type": "integer", - "enum": [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10 - ], - "x-enum-varnames": [ - "ApplicationType_UNSPECIFIED", - "ApplicationType_THANOS", - "ApplicationType_PROMETHEUS", - "ApplicationType_GRAFANA", - "ApplicationType_KIALI", - "ApplicationType_KIBANA", - "ApplicationType_ELASTICSERCH", - "ApplicationType_CLOUD_CONSOLE", - "ApplicationType_HORIZON", - "ApplicationType_JAEGER", - "ApplicationType_KUBERNETES_DASHBOARD" - ] + "domain.Axis": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "type": "string" + } + } + } }, "domain.ChartData": { "type": "object", @@ -2330,33 +2338,11 @@ "$ref": "#/definitions/domain.Unit" } }, - "xaxis": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "type": "string" - } - }, - "type": { - "type": "string" - } - } + "xAxis": { + "$ref": "#/definitions/domain.Axis" }, - "yaxis": { - "type": "object", - "properties": { - "data": { - "type": "array", - "items": { - "type": "string" - } - }, - "type": { - "type": "string" - } - } + "yAxis": { + "$ref": "#/definitions/domain.Axis" } } }, @@ -2482,7 +2468,7 @@ "type": "string" }, "status": { - "$ref": "#/definitions/domain.ClusterStatus" + "type": "integer" }, "statusDesc": { "type": "string" @@ -2594,25 +2580,6 @@ } } }, - "domain.ClusterStatus": { - "type": "integer", - "enum": [ - 0, - 1, - 2, - 3, - 4, - 5 - ], - "x-enum-varnames": [ - "ClusterStatus_PENDING", - "ClusterStatus_INSTALLING", - "ClusterStatus_RUNNING", - "ClusterStatus_DELETING", - "ClusterStatus_DELETED", - "ClusterStatus_ERROR" - ] - }, "domain.CreateAppGroupRequest": { "type": "object", "required": [ @@ -3113,6 +3080,14 @@ } } }, + "domain.GetDashboardChartResponse": { + "type": "object", + "properties": { + "chart": { + "$ref": "#/definitions/domain.DashboardChartResponse" + } + } + }, "domain.GetDashboardChartsResponse": { "type": "object", "properties": { @@ -3290,7 +3265,7 @@ "type": "string" }, "status": { - "$ref": "#/definitions/domain.OrganizationStatus" + "type": "integer" }, "updatedAt": { "type": "string" @@ -3404,7 +3379,7 @@ "type": "string" }, "status": { - "$ref": "#/definitions/domain.OrganizationStatus" + "type": "integer" }, "statusDescription": { "type": "string" @@ -3414,29 +3389,6 @@ } } }, - "domain.OrganizationStatus": { - "type": "integer", - "enum": [ - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7 - ], - "x-enum-varnames": [ - "OrganizationStatus_PENDING", - "OrganizationStatus_CREATE", - "OrganizationStatus_CREATING", - "OrganizationStatus_CREATED", - "OrganizationStatus_DELETE", - "OrganizationStatus_DELETING", - "OrganizationStatus_DELETED", - "OrganizationStatus_ERROR" - ] - }, "domain.Role": { "type": "object", "properties": { diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index c4d5753e..9c4e18bb 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -3,7 +3,7 @@ definitions: domain.AppGroupResponse: properties: appGroupType: - $ref: '#/definitions/domain.AppGroupType' + type: integer clusterId: type: string createdAt: @@ -17,7 +17,7 @@ definitions: name: type: string status: - $ref: '#/definitions/domain.AppGroupStatus' + type: integer statusDescription: type: string updatedAt: @@ -27,32 +27,6 @@ definitions: workflowId: type: string type: object - domain.AppGroupStatus: - enum: - - 0 - - 1 - - 2 - - 3 - - 4 - - 5 - type: integer - x-enum-varnames: - - AppGroupStatus_PENDING - - AppGroupStatus_INSTALLING - - AppGroupStatus_RUNNING - - AppGroupStatus_DELETING - - AppGroupStatus_DELETED - - AppGroupStatus_ERROR - domain.AppGroupType: - enum: - - 0 - - 1 - - 2 - type: integer - x-enum-varnames: - - AppGroupType_UNSPECIFIED - - AppGroupType_LMA - - AppGroupType_SERVICE_MESH domain.AppServeApp: properties: app_serve_app_tasks: @@ -165,7 +139,7 @@ definitions: appGroupId: type: string applicationType: - $ref: '#/definitions/domain.ApplicationType' + type: integer createdAt: type: string endpoint: @@ -177,56 +151,23 @@ definitions: updatedAt: type: string type: object - domain.ApplicationType: - enum: - - 0 - - 1 - - 2 - - 3 - - 4 - - 5 - - 6 - - 7 - - 8 - - 9 - - 10 - type: integer - x-enum-varnames: - - ApplicationType_UNSPECIFIED - - ApplicationType_THANOS - - ApplicationType_PROMETHEUS - - ApplicationType_GRAFANA - - ApplicationType_KIALI - - ApplicationType_KIBANA - - ApplicationType_ELASTICSERCH - - ApplicationType_CLOUD_CONSOLE - - ApplicationType_HORIZON - - ApplicationType_JAEGER - - ApplicationType_KUBERNETES_DASHBOARD + domain.Axis: + properties: + data: + items: + type: string + type: array + type: object domain.ChartData: properties: series: items: $ref: '#/definitions/domain.Unit' type: array - xaxis: - properties: - data: - items: - type: string - type: array - type: - type: string - type: object - yaxis: - properties: - data: - items: - type: string - type: array - type: - type: string - type: object + xAxis: + $ref: '#/definitions/domain.Axis' + yAxis: + $ref: '#/definitions/domain.Axis' type: object domain.CloudAccount: properties: @@ -309,7 +250,7 @@ definitions: stackTemplateId: type: string status: - $ref: '#/definitions/domain.ClusterStatus' + type: integer statusDesc: type: string updatedAt: @@ -382,22 +323,6 @@ definitions: updator: $ref: '#/definitions/domain.SimpleUserResponse' type: object - domain.ClusterStatus: - enum: - - 0 - - 1 - - 2 - - 3 - - 4 - - 5 - type: integer - x-enum-varnames: - - ClusterStatus_PENDING - - ClusterStatus_INSTALLING - - ClusterStatus_RUNNING - - ClusterStatus_DELETING - - ClusterStatus_DELETED - - ClusterStatus_ERROR domain.CreateAppGroupRequest: properties: appGroupType: @@ -738,6 +663,11 @@ definitions: $ref: '#/definitions/domain.ClusterResponse' type: array type: object + domain.GetDashboardChartResponse: + properties: + chart: + $ref: '#/definitions/domain.DashboardChartResponse' + type: object domain.GetDashboardChartsResponse: properties: charts: @@ -853,7 +783,7 @@ definitions: primaryClusterId: type: string status: - $ref: '#/definitions/domain.OrganizationStatus' + type: integer updatedAt: type: string type: object @@ -928,32 +858,12 @@ definitions: primaryClusterId: type: string status: - $ref: '#/definitions/domain.OrganizationStatus' + type: integer statusDescription: type: string updatedAt: type: string type: object - domain.OrganizationStatus: - enum: - - 0 - - 1 - - 2 - - 3 - - 4 - - 5 - - 6 - - 7 - type: integer - x-enum-varnames: - - OrganizationStatus_PENDING - - OrganizationStatus_CREATE - - OrganizationStatus_CREATING - - OrganizationStatus_CREATED - - OrganizationStatus_DELETE - - OrganizationStatus_DELETING - - OrganizationStatus_DELETED - - OrganizationStatus_ERROR domain.Role: properties: createdAt: @@ -2090,7 +2000,7 @@ paths: get: consumes: - application/json - description: Get chart data + description: Get charts data parameters: - description: organizationId in: path @@ -2120,6 +2030,44 @@ paths: $ref: '#/definitions/domain.GetDashboardChartsResponse' security: - JWT: [] + summary: Get charts data + tags: + - Dashboards + /organizations/{organizationId}/dashboard/charts/{chartType}: + get: + consumes: + - application/json + description: Get chart data + parameters: + - description: organizationId + in: path + name: organizationId + required: true + type: string + - description: chartType + in: path + name: chartType + required: true + type: string + - description: duration + in: query + name: duration + required: true + type: string + - description: interval + in: query + name: interval + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/domain.GetDashboardChartResponse' + security: + - JWT: [] summary: Get chart data tags: - Dashboards diff --git a/internal/delivery/http/dashboard.go b/internal/delivery/http/dashboard.go index e763ec53..f92d4e70 100644 --- a/internal/delivery/http/dashboard.go +++ b/internal/delivery/http/dashboard.go @@ -23,8 +23,8 @@ func NewDashboardHandler(h usecase.IDashboardUsecase) *DashboardHandler { // GetCharts godoc // @Tags Dashboards -// @Summary Get chart data -// @Description Get chart data +// @Summary Get charts data +// @Description Get charts data // @Accept json // @Produce json // @Param organizationId path string true "organizationId" @@ -43,13 +43,6 @@ func (h *DashboardHandler) GetCharts(w http.ResponseWriter, r *http.Request) { } query := r.URL.Query() - strType := query.Get("chartType") - chartType := new(domain.ChartType).FromString(strType) - if strType == "" { - chartType = domain.ChartType(domain.ChartType_ALL) - } - - log.Info("a", chartType) duration := query.Get("duration") if duration == "" { duration = "1d" // default @@ -60,7 +53,7 @@ func (h *DashboardHandler) GetCharts(w http.ResponseWriter, r *http.Request) { interval = "1d" // default } - charts, err := h.usecase.GetCharts(organizationId, chartType, duration, interval) + charts, err := h.usecase.GetCharts(organizationId, domain.ChartType_ALL, duration, interval) if err != nil { ErrorJSON(w, err) return @@ -77,3 +70,64 @@ func (h *DashboardHandler) GetCharts(w http.ResponseWriter, r *http.Request) { ResponseJSON(w, http.StatusOK, out) } + +// GetCharts godoc +// @Tags Dashboards +// @Summary Get chart data +// @Description Get chart data +// @Accept json +// @Produce json +// @Param organizationId path string true "organizationId" +// @Param chartType path string true "chartType" +// @Param duration query string true "duration" +// @Param interval query string true "interval" +// @Success 200 {object} domain.GetDashboardChartResponse +// @Router /organizations/{organizationId}/dashboard/charts/{chartType} [get] +// @Security JWT +func (h *DashboardHandler) GetChart(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + organizationId, ok := vars["organizationId"] + if !ok { + ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid organizationId"))) + return + } + + strType, ok := vars["chartType"] + if !ok { + ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid chartType"))) + return + } + chartType := new(domain.ChartType).FromString(strType) + if chartType == domain.ChartType_ERROR { + ErrorJSON(w, httpErrors.NewBadRequestError(fmt.Errorf("Invalid chartType"))) + return + } + + query := r.URL.Query() + duration := query.Get("duration") + if duration == "" { + duration = "1d" // default + } + + interval := query.Get("interval") + if interval == "" { + interval = "1d" // default + } + + charts, err := h.usecase.GetCharts(organizationId, chartType, duration, interval) + if err != nil { + ErrorJSON(w, err) + return + } + if len(charts) < 1 { + ErrorJSON(w, httpErrors.NewInternalServerError(fmt.Errorf("Not found chart"))) + return + } + + var out domain.DashboardChartResponse + if err := domain.Map(charts[0], &out); err != nil { + log.Info(err) + } + + ResponseJSON(w, http.StatusOK, out) +} diff --git a/internal/middleware/auth/authenticator/keycloak/keycloak.go b/internal/middleware/auth/authenticator/keycloak/keycloak.go index bef2fb74..e81b926c 100644 --- a/internal/middleware/auth/authenticator/keycloak/keycloak.go +++ b/internal/middleware/auth/authenticator/keycloak/keycloak.go @@ -2,6 +2,9 @@ package keycloak import ( "fmt" + "net/http" + "strings" + jwtWithouKey "github.com/dgrijalva/jwt-go" "github.com/google/uuid" "github.com/openinfradev/tks-api/internal/keycloak" @@ -9,8 +12,6 @@ import ( "github.com/openinfradev/tks-api/internal/middleware/auth/request" "github.com/openinfradev/tks-api/internal/middleware/auth/user" "github.com/openinfradev/tks-api/pkg/log" - "net/http" - "strings" ) type keycloakAuthenticator struct { diff --git a/internal/route/route.go b/internal/route/route.go index 6a47184a..42a196fa 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -131,6 +131,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, asset http.Handler, dashboardHandler := delivery.NewDashboardHandler(usecase.NewDashboardUsecase(repoFactory)) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboard/charts", authMiddleware.Handle(http.HandlerFunc(dashboardHandler.GetCharts))).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboard/charts/{chartType}", authMiddleware.Handle(http.HandlerFunc(dashboardHandler.GetChart))).Methods(http.MethodGet) // assets r.PathPrefix("/api/").HandlerFunc(http.NotFound) diff --git a/internal/usecase/cloud-account.go b/internal/usecase/cloud-account.go index 604f8872..5b932acb 100644 --- a/internal/usecase/cloud-account.go +++ b/internal/usecase/cloud-account.go @@ -44,6 +44,8 @@ func (u *CloudAccountUsecase) Create(ctx context.Context, dto domain.CloudAccoun return uuid.Nil, httpErrors.NewBadRequestError(fmt.Errorf("Invalid token")) } + // 요청한 사ㅇㅏ가 허가 받지 않은 사용자라면 block + dto.Resource = "TODO server result or additional information" dto.CreatorId = user.GetUserId() diff --git a/internal/usecase/cluster.go b/internal/usecase/cluster.go index a130ea9b..f7f7a006 100644 --- a/internal/usecase/cluster.go +++ b/internal/usecase/cluster.go @@ -160,11 +160,13 @@ func (u *ClusterUsecase) Create(ctx context.Context, dto domain.Cluster) (cluste "create-tks-usercluster", argowf.SubmitOptions{ Parameters: []string{ + fmt.Sprintf("tks_info_host=%s", viper.GetString("external-address")), "contract_id=" + dto.OrganizationId, "cluster_id=" + clusterId.String(), "site_name=" + clusterId.String(), "template_name=" + stackTemplate.Template, "git_account=" + viper.GetString("git-account"), + "creator=" + user.GetUserId().String(), //"manifest_repo_url=" + viper.GetString("git-base-url") + "/" + viper.GetString("git-account") + "/" + clusterId + "-manifests", }, }) diff --git a/internal/usecase/dashboard.go b/internal/usecase/dashboard.go index 18050824..b7c40b62 100644 --- a/internal/usecase/dashboard.go +++ b/internal/usecase/dashboard.go @@ -51,9 +51,7 @@ func (u *DashboardUsecase) getPrometheus(organizationId string, chartType string // [TODO] get prometheus if chartType == domain.ChartType_TRAFFIC.String() { chartData := domain.ChartData{} - chartData.XAxis.Type = "category" chartData.XAxis.Data = []string{"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"} - chartData.YAxis.Type = "value" chartData.Series = append(chartData.Series, domain.Unit{ Name: "Cluster in", diff --git a/internal/usecase/stack.go b/internal/usecase/stack.go index 4d4188ba..6fd40606 100644 --- a/internal/usecase/stack.go +++ b/internal/usecase/stack.go @@ -3,9 +3,10 @@ package usecase import ( "context" "fmt" - "github.com/openinfradev/tks-api/internal/middleware/auth/request" "time" + "github.com/openinfradev/tks-api/internal/middleware/auth/request" + "github.com/openinfradev/tks-api/internal/repository" argowf "github.com/openinfradev/tks-api/pkg/argo-client" "github.com/openinfradev/tks-api/pkg/domain" @@ -46,6 +47,8 @@ func (u *StackUsecase) Create(ctx context.Context, dto domain.Stack) (err error) return httpErrors.NewBadRequestError(fmt.Errorf("Invalid token")) } + // 요청한 사ㅇㅏ가 허가 받지 않은 사용자라면 block + // [TODO] check primary cluster clusters, err := u.clusterRepo.FetchByOrganizationId(dto.OrganizationId) if err != nil { diff --git a/internal/usecase/user.go b/internal/usecase/user.go index 0fbdbc96..aac3f214 100644 --- a/internal/usecase/user.go +++ b/internal/usecase/user.go @@ -3,9 +3,10 @@ package usecase import ( "context" "fmt" - "github.com/openinfradev/tks-api/internal/middleware/auth/request" "net/http" + "github.com/openinfradev/tks-api/internal/middleware/auth/request" + "github.com/Nerzal/gocloak/v13" "github.com/google/uuid" "github.com/openinfradev/tks-api/internal/helper" @@ -71,6 +72,9 @@ func (u *UserUsecase) DeleteAdmin(organizationId string) error { } func (u *UserUsecase) CreateAdmin(orgainzationId string) (*domain.User, error) { + + // 요청한 사ㅇㅏ가 허가 받지 않은 사용자라면 block + user := domain.User{ AccountId: "admin", Password: "admin", diff --git a/pkg/api-client/api-client.go b/pkg/api-client/api-client.go index fb94d413..1fd8d210 100644 --- a/pkg/api-client/api-client.go +++ b/pkg/api-client/api-client.go @@ -71,12 +71,11 @@ func (c *ApiClientImpl) Get(path string) (out interface{}, err error) { return restError, fmt.Errorf("HTTP status [%d] message [%s]", res.StatusCode, restError.ErrMessage) } - var resJson interface{} - if err := json.Unmarshal(body, &resJson); err != nil { + if err := json.Unmarshal(body, &out); err != nil { return nil, err } - return resJson, nil + return out, nil } func (c *ApiClientImpl) Post(path string, input interface{}) (out interface{}, err error) { @@ -129,10 +128,9 @@ func (c *ApiClientImpl) callWithBody(method string, path string, input interface return restError, fmt.Errorf("HTTP status [%d] message [%s]", res.StatusCode, restError.ErrMessage) } - var resJson interface{} - if err := json.Unmarshal(body, &resJson); err != nil { + if err := json.Unmarshal(body, &out); err != nil { return nil, err } - return resJson, nil + return } diff --git a/pkg/domain/dashboard.go b/pkg/domain/dashboard.go index 8558c9d6..6ad788a2 100644 --- a/pkg/domain/dashboard.go +++ b/pkg/domain/dashboard.go @@ -58,20 +58,18 @@ type DashboardChart struct { } type Unit struct { - Name string - Data []string + Name string `json:"name"` + Data []string `json:"data"` +} + +type Axis struct { + Data []string `json:"data"` } type ChartData struct { - XAxis struct { - Type string - Data []string - } - YAxis struct { - Type string - Data []string - } - Series []Unit + XAxis Axis `json:"xAxis"` + YAxis Axis `json:"yAxis"` + Series []Unit `json:"series"` } type DashboardChartResponse struct { @@ -88,3 +86,7 @@ type DashboardChartResponse struct { type GetDashboardChartsResponse struct { Charts []DashboardChartResponse `json:"charts"` } + +type GetDashboardChartResponse struct { + Chart DashboardChartResponse `json:"chart"` +} diff --git a/scripts/erd_postgres.sql b/scripts/erd_postgres.sql new file mode 100644 index 00000000..da611fb8 --- /dev/null +++ b/scripts/erd_postgres.sql @@ -0,0 +1,390 @@ +CREATE TABLE IF NOT EXISTS public.app_groups +( + id text NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + app_group_type integer, + cluster_id text , + name text , + description text , + workflow_id text , + status integer, + status_desc text , + creator_id uuid, + updator_id uuid, + CONSTRAINT app_groups_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.app_serve_app_tasks +( + id text NOT NULL, + app_serve_app_id text NOT NULL, + version text , + status text , + output text , + artifact_url text , + image_url text , + executable_path text , + profile text , + app_config text , + app_secret text , + extra_env text , + port text , + resource_spec text , + helm_revision integer, + strategy text , + pv_enabled boolean, + pv_storage_class text , + pv_access_mode text , + pv_size text , + pv_mount_path text , + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + CONSTRAINT app_serve_app_tasks_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.app_serve_apps +( + id text NOT NULL, + name text , + organization_id text , + type text , + app_type text , + endpoint_url text , + preview_endpoint_url text , + target_cluster_id text , + status text , + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + CONSTRAINT app_serve_apps_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.applications +( + id uuid NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + app_group_id text , + endpoint text , + metadata jsonb, + type integer, + CONSTRAINT applications_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.cloud_accounts +( + id text NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + organization_id character varying(36) , + name text , + description text , + resource text , + cloud_service text , + creator_id uuid, + updator_id uuid, + CONSTRAINT cloud_accounts_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.cloud_settings +( + id text NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + organization_id character varying(36) , + name text , + description text , + resource text , + type text , + creator_id uuid, + updator_id uuid, + cloud_service text , + CONSTRAINT cloud_settings_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.clusters +( + id text NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + name text , + organization_id character varying(36) , + template_id text , + ssh_key_name text , + region text , + num_of_az bigint, + machine_type text , + min_size_per_az bigint, + max_size_per_az bigint, + creator text , + description text , + workflow_id text , + status integer, + status_desc text , + cloud_setting_id text , + creator_id uuid, + updator_id uuid, + stack_template_id text , + cloud_account_id text , + CONSTRAINT clusters_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.histories +( + id uuid NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + user_id text , + history_type text , + project_id text , + description text , + CONSTRAINT histories_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.organizations +( + id character varying(36) NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + name text , + description text , + phone_number text , + workflow_id text , + status integer, + status_desc text , + creator text , + phone text , + primary_cluster_id text , + CONSTRAINT organizations_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.policies +( + id bigint NOT NULL DEFAULT nextval('policies_id_seq'::regclass), + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + role_id uuid, + name text , + description text , + c boolean, + create_priviledge text , + u boolean, + update_priviledge text , + r boolean, + read_priviledge text , + d boolean, + delete_priviledge text , + creator text , + CONSTRAINT policies_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.roles +( + id uuid NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + name text , + description text , + creator text , + CONSTRAINT roles_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.stack_templates +( + id text NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + organization_id character varying(36) , + name text , + description text , + version text , + cloud_service text , + platform text , + template text , + creator_id uuid, + updator_id uuid, + kube_version text , + kube_type text , + services jsonb, + CONSTRAINT stack_templates_pkey PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS public.users +( + id uuid NOT NULL, + created_at timestamp with time zone, + updated_at timestamp with time zone, + deleted_at timestamp with time zone, + account_id text , + name text , + password text , + auth_type text , + role_id uuid, + organization_id character varying(36) , + creator text , + email_address text , + department text , + description text , + email text , + CONSTRAINT users_pkey PRIMARY KEY (id) +); + +ALTER TABLE IF EXISTS public.app_groups + ADD CONSTRAINT fk_app_groups_creator FOREIGN KEY (creator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.app_groups + ADD CONSTRAINT fk_app_groups_updator FOREIGN KEY (updator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.app_serve_app_tasks + ADD CONSTRAINT fk_app_serve_apps_app_serve_app_tasks FOREIGN KEY (app_serve_app_id) + REFERENCES public.app_serve_apps (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.cloud_accounts + ADD CONSTRAINT fk_cloud_accounts_creator FOREIGN KEY (creator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.cloud_accounts + ADD CONSTRAINT fk_cloud_accounts_organization FOREIGN KEY (organization_id) + REFERENCES public.organizations (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.cloud_accounts + ADD CONSTRAINT fk_cloud_accounts_updator FOREIGN KEY (updator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.cloud_settings + ADD CONSTRAINT fk_cloud_settings_creator FOREIGN KEY (creator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.cloud_settings + ADD CONSTRAINT fk_cloud_settings_organization FOREIGN KEY (organization_id) + REFERENCES public.organizations (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.cloud_settings + ADD CONSTRAINT fk_cloud_settings_updator FOREIGN KEY (updator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.clusters + ADD CONSTRAINT fk_clusters_cloud_account FOREIGN KEY (cloud_account_id) + REFERENCES public.cloud_accounts (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.clusters + ADD CONSTRAINT fk_clusters_cloud_setting FOREIGN KEY (cloud_setting_id) + REFERENCES public.cloud_settings (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.clusters + ADD CONSTRAINT fk_clusters_creator FOREIGN KEY (creator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.clusters + ADD CONSTRAINT fk_clusters_organization FOREIGN KEY (organization_id) + REFERENCES public.organizations (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.clusters + ADD CONSTRAINT fk_clusters_stack_template FOREIGN KEY (stack_template_id) + REFERENCES public.stack_templates (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.clusters + ADD CONSTRAINT fk_clusters_updator FOREIGN KEY (updator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.policies + ADD CONSTRAINT fk_policies_role FOREIGN KEY (role_id) + REFERENCES public.roles (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.stack_templates + ADD CONSTRAINT fk_stack_templates_creator FOREIGN KEY (creator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.stack_templates + ADD CONSTRAINT fk_stack_templates_organization FOREIGN KEY (organization_id) + REFERENCES public.organizations (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.stack_templates + ADD CONSTRAINT fk_stack_templates_updator FOREIGN KEY (updator_id) + REFERENCES public.users (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.users + ADD CONSTRAINT fk_users_organization FOREIGN KEY (organization_id) + REFERENCES public.organizations (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + + +ALTER TABLE IF EXISTS public.users + ADD CONSTRAINT fk_users_role FOREIGN KEY (role_id) + REFERENCES public.roles (id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE NO ACTION; + +END; \ No newline at end of file