Skip to content

Commit

Permalink
Merge pull request #407 from seungkyua/20240419_policy_violation_top5
Browse files Browse the repository at this point in the history
20240419 policy violation top5
  • Loading branch information
seungkyua authored Apr 19, 2024
2 parents 4396650 + 9d19fbc commit 0abb93b
Show file tree
Hide file tree
Showing 11 changed files with 498 additions and 50 deletions.
80 changes: 80 additions & 0 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3582,6 +3582,57 @@ const docTemplate = `{
}
}
},
"/organizations/{organizationId}/dashboards/widgets/policy-violation-top5": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get policy violation top5",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Dashboard Widgets"
],
"summary": "Get policy violation top5",
"parameters": [
{
"type": "string",
"description": "Organization ID",
"name": "organizationId",
"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/github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationTop5Response"
}
}
}
}
},
"/organizations/{organizationId}/dashboards/widgets/resources": {
"get": {
"security": [
Expand Down Expand Up @@ -12653,6 +12704,35 @@ const docTemplate = `{
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationTop5Response": {
"type": "object",
"properties": {
"chartData": {
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.BarChartData"
},
"chartType": {
"type": "string"
},
"description": {
"type": "string"
},
"duration": {
"type": "string"
},
"interval": {
"type": "string"
},
"name": {
"type": "string"
},
"organizationId": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetDashboardResourcesResponse": {
"type": "object",
"properties": {
Expand Down
80 changes: 80 additions & 0 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3576,6 +3576,57 @@
}
}
},
"/organizations/{organizationId}/dashboards/widgets/policy-violation-top5": {
"get": {
"security": [
{
"JWT": []
}
],
"description": "Get policy violation top5",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Dashboard Widgets"
],
"summary": "Get policy violation top5",
"parameters": [
{
"type": "string",
"description": "Organization ID",
"name": "organizationId",
"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/github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationTop5Response"
}
}
}
}
},
"/organizations/{organizationId}/dashboards/widgets/resources": {
"get": {
"security": [
Expand Down Expand Up @@ -12647,6 +12698,35 @@
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationTop5Response": {
"type": "object",
"properties": {
"chartData": {
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.BarChartData"
},
"chartType": {
"type": "string"
},
"description": {
"type": "string"
},
"duration": {
"type": "string"
},
"interval": {
"type": "string"
},
"name": {
"type": "string"
},
"organizationId": {
"type": "string"
},
"updatedAt": {
"type": "string"
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetDashboardResourcesResponse": {
"type": "object",
"properties": {
Expand Down
52 changes: 52 additions & 0 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1748,6 +1748,25 @@ definitions:
updatedAt:
type: string
type: object
github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationTop5Response:
properties:
chartData:
$ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.BarChartData'
chartType:
type: string
description:
type: string
duration:
type: string
interval:
type: string
name:
type: string
organizationId:
type: string
updatedAt:
type: string
type: object
github_com_openinfradev_tks-api_pkg_domain.GetDashboardResourcesResponse:
properties:
resources:
Expand Down Expand Up @@ -6595,6 +6614,39 @@ paths:
summary: Get policy violation log
tags:
- Dashboard Widgets
/organizations/{organizationId}/dashboards/widgets/policy-violation-top5:
get:
consumes:
- application/json
description: Get policy violation top5
parameters:
- description: Organization ID
in: path
name: organizationId
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/github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationTop5Response'
security:
- JWT: []
summary: Get policy violation top5
tags:
- Dashboard Widgets
/organizations/{organizationId}/dashboards/widgets/resources:
get:
consumes:
Expand Down
1 change: 1 addition & 0 deletions internal/delivery/api/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const (
GetPolicyViolationLogDashboard
GetPolicyStatisticsDashboard
GetWorkloadDashboard
GetPolicyViolationTop5Dashboard

// SystemNotificationTemplate
Admin_CreateSystemNotificationTemplate
Expand Down
8 changes: 8 additions & 0 deletions internal/delivery/api/generated_endpoints.go.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "GetWorkloadDashboard",
Group: "Dashboard",
},
GetPolicyViolationTop5Dashboard: {
Name: "GetPolicyViolationTop5Dashboard",
Group: "Dashboard",
},
Admin_CreateSystemNotificationTemplate: {
Name: "Admin_CreateSystemNotificationTemplate",
Group: "SystemNotificationTemplate",
Expand Down Expand Up @@ -1108,6 +1112,8 @@ func (e Endpoint) String() string {
return "GetPolicyStatisticsDashboard"
case GetWorkloadDashboard:
return "GetWorkloadDashboard"
case GetPolicyViolationTop5Dashboard:
return "GetPolicyViolationTop5Dashboard"
case Admin_CreateSystemNotificationTemplate:
return "Admin_CreateSystemNotificationTemplate"
case Admin_UpdateSystemNotificationTemplate:
Expand Down Expand Up @@ -1570,6 +1576,8 @@ func GetEndpoint(name string) Endpoint {
return GetPolicyStatisticsDashboard
case "GetWorkloadDashboard":
return GetWorkloadDashboard
case "GetPolicyViolationTop5Dashboard":
return GetPolicyViolationTop5Dashboard
case "Admin_CreateSystemNotificationTemplate":
return Admin_CreateSystemNotificationTemplate
case "Admin_UpdateSystemNotificationTemplate":
Expand Down
51 changes: 51 additions & 0 deletions internal/delivery/http/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type IDashboardHandler interface {
GetPolicyViolationLog(w http.ResponseWriter, r *http.Request)
GetPolicyStatistics(w http.ResponseWriter, r *http.Request)
GetWorkload(w http.ResponseWriter, r *http.Request)
GetPolicyViolationTop5(w http.ResponseWriter, r *http.Request)
}

type DashboardHandler struct {
Expand Down Expand Up @@ -737,3 +738,53 @@ func (h *DashboardHandler) GetWorkload(w http.ResponseWriter, r *http.Request) {

ResponseJSON(w, r, http.StatusOK, dwr)
}

// GetPolicyViolationTop5 godoc
//
// @Tags Dashboard Widgets
// @Summary Get policy violation top5
// @Description Get policy violation top5
// @Accept json
// @Produce json
// @Param organizationId path string true "Organization ID"
// @Param duration query string true "duration"
// @Param interval query string true "interval"
// @Success 200 {object} domain.GetDashboardPolicyViolationTop5Response
// @Router /organizations/{organizationId}/dashboards/widgets/policy-violation-top5 [get]
// @Security JWT
func (h *DashboardHandler) GetPolicyViolationTop5(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
organizationId, ok := vars["organizationId"]
if !ok {
ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("%s: invalid organizationId", organizationId),
"C_INVALID_ORGANIZATION_ID", ""))
return
}

query := r.URL.Query()
duration := query.Get("duration")
if duration == "" {
duration = "1d" // default
}

interval := query.Get("interval")
if interval == "" {
interval = "1d" // default
}

bcd, err := h.usecase.GetPolicyViolationTop5(r.Context(), organizationId, duration, interval)
if err != nil {
log.Error(r.Context(), "Failed to make policy bar chart data", err)
ErrorJSON(w, r, err)
return
}

var out domain.GetDashboardPolicyViolationTop5Response
out.ChartType = "PolicyViolationTop5"
out.OrganizationId = organizationId
out.Name = "정책 위반 Top5"
out.Description = "정책 위반 Top5 데이터"
out.ChartData = *bcd
out.UpdatedAt = time.Now()
ResponseJSON(w, r, http.StatusOK, out)
}
1 change: 1 addition & 0 deletions internal/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/widgets/policy-violation-log", customMiddleware.Handle(internalApi.GetPolicyViolationLogDashboard, http.HandlerFunc(dashboardHandler.GetPolicyViolationLog))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/widgets/policy-statistics", customMiddleware.Handle(internalApi.GetPolicyStatisticsDashboard, http.HandlerFunc(dashboardHandler.GetPolicyStatistics))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/widgets/workload", customMiddleware.Handle(internalApi.GetWorkloadDashboard, http.HandlerFunc(dashboardHandler.GetWorkload))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/widgets/policy-violation-top5", customMiddleware.Handle(internalApi.GetPolicyViolationTop5Dashboard, http.HandlerFunc(dashboardHandler.GetPolicyViolationTop5))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards", customMiddleware.Handle(internalApi.CreateDashboard, http.HandlerFunc(dashboardHandler.CreateDashboard))).Methods(http.MethodPost)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/{dashboardKey}", customMiddleware.Handle(internalApi.GetDashboard, http.HandlerFunc(dashboardHandler.GetDashboard))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/{dashboardKey}", customMiddleware.Handle(internalApi.UpdateDashboard, http.HandlerFunc(dashboardHandler.UpdateDashboard))).Methods(http.MethodPut)
Expand Down
Loading

0 comments on commit 0abb93b

Please sign in to comment.