Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

20240415 policy violation #386

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions api/swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3435,7 +3435,7 @@ const docTemplate = `{
"JWT": []
}
],
"description": "Get the number of policy enforcement",
"description": "Get the number of policy violation",
"consumes": [
"application/json"
],
Expand All @@ -3445,21 +3445,35 @@ const docTemplate = `{
"tags": [
"Dashboard Widgets"
],
"summary": "Get the number of policy enforcement",
"summary": "Get the number of policy violation",
"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.GetDashboardPolicyEnforcementResponse"
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationResponse"
}
}
}
Expand Down Expand Up @@ -12426,6 +12440,35 @@ const docTemplate = `{
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationResponse": {
"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
49 changes: 46 additions & 3 deletions api/swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3429,7 +3429,7 @@
"JWT": []
}
],
"description": "Get the number of policy enforcement",
"description": "Get the number of policy violation",
"consumes": [
"application/json"
],
Expand All @@ -3439,21 +3439,35 @@
"tags": [
"Dashboard Widgets"
],
"summary": "Get the number of policy enforcement",
"summary": "Get the number of policy violation",
"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.GetDashboardPolicyEnforcementResponse"
"$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationResponse"
}
}
}
Expand Down Expand Up @@ -12420,6 +12434,35 @@
}
}
},
"github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationResponse": {
"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
35 changes: 32 additions & 3 deletions api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,25 @@ definitions:
updatedResources:
$ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.DashboardPolicyUpdate'
type: object
github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationResponse:
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 @@ -6377,23 +6396,33 @@ paths:
get:
consumes:
- application/json
description: Get the number of policy enforcement
description: Get the number of policy violation
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.GetDashboardPolicyEnforcementResponse'
$ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetDashboardPolicyViolationResponse'
security:
- JWT: []
summary: Get the number of policy enforcement
summary: Get the number of policy violation
tags:
- Dashboard Widgets
/organizations/{organizationId}/dashboards/policy-status:
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 @@ -120,6 +120,7 @@ const (
GetPolicyStatusDashboard
GetPolicyUpdateDashboard
GetPolicyEnforcementDashboard
GetPolicyViolationDashboard

// 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 @@ -367,6 +367,10 @@ var ApiMap = map[Endpoint]EndpointInfo{
Name: "GetPolicyEnforcementDashboard",
Group: "Dashboard",
},
GetPolicyViolationDashboard: {
Name: "GetPolicyViolationDashboard",
Group: "Dashboard",
},
Admin_CreateSystemNotificationTemplate: {
Name: "Admin_CreateSystemNotificationTemplate",
Group: "SystemNotificationTemplate",
Expand Down Expand Up @@ -1084,6 +1088,8 @@ func (e Endpoint) String() string {
return "GetPolicyUpdateDashboard"
case GetPolicyEnforcementDashboard:
return "GetPolicyEnforcementDashboard"
case GetPolicyViolationDashboard:
return "GetPolicyViolationDashboard"
case Admin_CreateSystemNotificationTemplate:
return "Admin_CreateSystemNotificationTemplate"
case Admin_UpdateSystemNotificationTemplate:
Expand Down Expand Up @@ -1538,6 +1544,8 @@ func GetEndpoint(name string) Endpoint {
return GetPolicyUpdateDashboard
case "GetPolicyEnforcementDashboard":
return GetPolicyEnforcementDashboard
case "GetPolicyViolationDashboard":
return GetPolicyViolationDashboard
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 @@ -27,6 +27,7 @@ type IDashboardHandler interface {
GetPolicyStatus(w http.ResponseWriter, r *http.Request)
GetPolicyUpdate(w http.ResponseWriter, r *http.Request)
GetPolicyEnforcement(w http.ResponseWriter, r *http.Request)
GetPolicyViolation(w http.ResponseWriter, r *http.Request)
}

type DashboardHandler struct {
Expand Down Expand Up @@ -570,3 +571,53 @@ func (h *DashboardHandler) GetPolicyEnforcement(w http.ResponseWriter, r *http.R
out.UpdatedAt = time.Now()
ResponseJSON(w, r, http.StatusOK, out)
}

// GetPolicyViolation godoc
//
// @Tags Dashboard Widgets
// @Summary Get the number of policy violation
// @Description Get the number of policy violation
// @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.GetDashboardPolicyViolationResponse
// @Router /organizations/{organizationId}/dashboards/policy-enforcement [get]
// @Security JWT
func (h *DashboardHandler) GetPolicyViolation(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.GetPolicyViolation(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.GetDashboardPolicyViolationResponse
out.ChartType = "PolicyViolation"
out.OrganizationId = organizationId
out.Name = "정책 위반 현황"
out.Description = "정책 위반 현황 통계 데이터"
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 @@ -208,6 +208,7 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/policy-status", customMiddleware.Handle(internalApi.GetPolicyStatusDashboard, http.HandlerFunc(dashboardHandler.GetPolicyStatus))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/policy-update", customMiddleware.Handle(internalApi.GetPolicyUpdateDashboard, http.HandlerFunc(dashboardHandler.GetPolicyUpdate))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/policy-enforcement", customMiddleware.Handle(internalApi.GetPolicyEnforcementDashboard, http.HandlerFunc(dashboardHandler.GetPolicyEnforcement))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards/policy-violation", customMiddleware.Handle(internalApi.GetPolicyViolationDashboard, http.HandlerFunc(dashboardHandler.GetPolicyViolation))).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", customMiddleware.Handle(internalApi.GetDashboard, http.HandlerFunc(dashboardHandler.GetDashboard))).Methods(http.MethodGet)
r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/dashboards", customMiddleware.Handle(internalApi.UpdateDashboard, http.HandlerFunc(dashboardHandler.UpdateDashboard))).Methods(http.MethodPut)
Expand Down
Loading
Loading