diff --git a/api/swagger/docs.go b/api/swagger/docs.go index 0832751f..14b5d8d0 100644 --- a/api/swagger/docs.go +++ b/api/swagger/docs.go @@ -22,6 +22,186 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/admin/audits": { + "get": { + "security": [ + { + "JWT": [] + } + ], + "description": "Get Audits", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Audits" + ], + "summary": "Get Audits", + "parameters": [ + { + "type": "string", + "description": "pageSize", + "name": "limit", + "in": "query" + }, + { + "type": "string", + "description": "pageNumber", + "name": "page", + "in": "query" + }, + { + "type": "string", + "description": "sortColumn", + "name": "soertColumn", + "in": "query" + }, + { + "type": "string", + "description": "sortOrder", + "name": "sortOrder", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv", + "description": "filters", + "name": "filter", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv", + "description": "filters", + "name": "or", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditsResponse" + } + } + } + }, + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "Create Audit", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Audits" + ], + "summary": "Create Audit", + "parameters": [ + { + "description": "create audit request", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditResponse" + } + } + } + } + }, + "/admin/audits/{auditId}": { + "get": { + "security": [ + { + "JWT": [] + } + ], + "description": "Get Audit", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Audits" + ], + "summary": "Get Audit", + "parameters": [ + { + "type": "string", + "description": "auditId", + "name": "auditId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditResponse" + } + } + } + }, + "delete": { + "security": [ + { + "JWT": [] + } + ], + "description": "Delete Audit", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Audits" + ], + "summary": "Delete Audit 'NOT IMPLEMENTED'", + "parameters": [ + { + "type": "string", + "description": "auditId", + "name": "auditId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/admin/organizations/{organizationId}/projects": { "get": { "security": [ @@ -2337,186 +2517,6 @@ const docTemplate = `{ } } }, - "/organizations/{organizationId}/audits": { - "get": { - "security": [ - { - "JWT": [] - } - ], - "description": "Get Audits", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Audits" - ], - "summary": "Get Audits", - "parameters": [ - { - "type": "string", - "description": "pageSize", - "name": "limit", - "in": "query" - }, - { - "type": "string", - "description": "pageNumber", - "name": "page", - "in": "query" - }, - { - "type": "string", - "description": "sortColumn", - "name": "soertColumn", - "in": "query" - }, - { - "type": "string", - "description": "sortOrder", - "name": "sortOrder", - "in": "query" - }, - { - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "csv", - "description": "filters", - "name": "filter", - "in": "query" - }, - { - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "csv", - "description": "filters", - "name": "or", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditsResponse" - } - } - } - }, - "post": { - "security": [ - { - "JWT": [] - } - ], - "description": "Create Audit", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Audits" - ], - "summary": "Create Audit", - "parameters": [ - { - "description": "create audit request", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditResponse" - } - } - } - } - }, - "/organizations/{organizationId}/audits/{auditId}": { - "get": { - "security": [ - { - "JWT": [] - } - ], - "description": "Get Audit", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Audits" - ], - "summary": "Get Audit", - "parameters": [ - { - "type": "string", - "description": "auditId", - "name": "auditId", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditResponse" - } - } - } - }, - "delete": { - "security": [ - { - "JWT": [] - } - ], - "description": "Delete Audit", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Audits" - ], - "summary": "Delete Audit 'NOT IMPLEMENTED'", - "parameters": [ - { - "type": "string", - "description": "auditId", - "name": "auditId", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK" - } - } - } - }, "/organizations/{organizationId}/cloud-accounts": { "get": { "security": [ diff --git a/api/swagger/swagger.json b/api/swagger/swagger.json index c02a7f9a..858188d9 100644 --- a/api/swagger/swagger.json +++ b/api/swagger/swagger.json @@ -16,6 +16,186 @@ "host": "tks-api-dev.taco-cat.xyz", "basePath": "/api/1.0/", "paths": { + "/admin/audits": { + "get": { + "security": [ + { + "JWT": [] + } + ], + "description": "Get Audits", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Audits" + ], + "summary": "Get Audits", + "parameters": [ + { + "type": "string", + "description": "pageSize", + "name": "limit", + "in": "query" + }, + { + "type": "string", + "description": "pageNumber", + "name": "page", + "in": "query" + }, + { + "type": "string", + "description": "sortColumn", + "name": "soertColumn", + "in": "query" + }, + { + "type": "string", + "description": "sortOrder", + "name": "sortOrder", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv", + "description": "filters", + "name": "filter", + "in": "query" + }, + { + "type": "array", + "items": { + "type": "string" + }, + "collectionFormat": "csv", + "description": "filters", + "name": "or", + "in": "query" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditsResponse" + } + } + } + }, + "post": { + "security": [ + { + "JWT": [] + } + ], + "description": "Create Audit", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Audits" + ], + "summary": "Create Audit", + "parameters": [ + { + "description": "create audit request", + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditResponse" + } + } + } + } + }, + "/admin/audits/{auditId}": { + "get": { + "security": [ + { + "JWT": [] + } + ], + "description": "Get Audit", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Audits" + ], + "summary": "Get Audit", + "parameters": [ + { + "type": "string", + "description": "auditId", + "name": "auditId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditResponse" + } + } + } + }, + "delete": { + "security": [ + { + "JWT": [] + } + ], + "description": "Delete Audit", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Audits" + ], + "summary": "Delete Audit 'NOT IMPLEMENTED'", + "parameters": [ + { + "type": "string", + "description": "auditId", + "name": "auditId", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK" + } + } + } + }, "/admin/organizations/{organizationId}/projects": { "get": { "security": [ @@ -2331,186 +2511,6 @@ } } }, - "/organizations/{organizationId}/audits": { - "get": { - "security": [ - { - "JWT": [] - } - ], - "description": "Get Audits", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Audits" - ], - "summary": "Get Audits", - "parameters": [ - { - "type": "string", - "description": "pageSize", - "name": "limit", - "in": "query" - }, - { - "type": "string", - "description": "pageNumber", - "name": "page", - "in": "query" - }, - { - "type": "string", - "description": "sortColumn", - "name": "soertColumn", - "in": "query" - }, - { - "type": "string", - "description": "sortOrder", - "name": "sortOrder", - "in": "query" - }, - { - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "csv", - "description": "filters", - "name": "filter", - "in": "query" - }, - { - "type": "array", - "items": { - "type": "string" - }, - "collectionFormat": "csv", - "description": "filters", - "name": "or", - "in": "query" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditsResponse" - } - } - } - }, - "post": { - "security": [ - { - "JWT": [] - } - ], - "description": "Create Audit", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Audits" - ], - "summary": "Create Audit", - "parameters": [ - { - "description": "create audit request", - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditRequest" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditResponse" - } - } - } - } - }, - "/organizations/{organizationId}/audits/{auditId}": { - "get": { - "security": [ - { - "JWT": [] - } - ], - "description": "Get Audit", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Audits" - ], - "summary": "Get Audit", - "parameters": [ - { - "type": "string", - "description": "auditId", - "name": "auditId", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditResponse" - } - } - } - }, - "delete": { - "security": [ - { - "JWT": [] - } - ], - "description": "Delete Audit", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "Audits" - ], - "summary": "Delete Audit 'NOT IMPLEMENTED'", - "parameters": [ - { - "type": "string", - "description": "auditId", - "name": "auditId", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "OK" - } - } - } - }, "/organizations/{organizationId}/cloud-accounts": { "get": { "security": [ diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index 166168a6..f2b856b8 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -2925,6 +2925,120 @@ info: title: tks-api service version: "1.0" paths: + /admin/audits: + get: + consumes: + - application/json + description: Get Audits + parameters: + - description: pageSize + in: query + name: limit + type: string + - description: pageNumber + in: query + name: page + type: string + - description: sortColumn + in: query + name: soertColumn + type: string + - description: sortOrder + in: query + name: sortOrder + type: string + - collectionFormat: csv + description: filters + in: query + items: + type: string + name: filter + type: array + - collectionFormat: csv + description: filters + in: query + items: + type: string + name: or + type: array + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditsResponse' + security: + - JWT: [] + summary: Get Audits + tags: + - Audits + post: + consumes: + - application/json + description: Create Audit + parameters: + - description: create audit request + in: body + name: body + required: true + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditResponse' + security: + - JWT: [] + summary: Create Audit + tags: + - Audits + /admin/audits/{auditId}: + delete: + consumes: + - application/json + description: Delete Audit + parameters: + - description: auditId + in: path + name: auditId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + security: + - JWT: [] + summary: Delete Audit 'NOT IMPLEMENTED' + tags: + - Audits + get: + consumes: + - application/json + description: Get Audit + parameters: + - description: auditId + in: path + name: auditId + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditResponse' + security: + - JWT: [] + summary: Get Audit + tags: + - Audits /admin/organizations/{organizationId}/projects: get: consumes: @@ -4397,120 +4511,6 @@ paths: summary: Create alert action tags: - Alerts - /organizations/{organizationId}/audits: - get: - consumes: - - application/json - description: Get Audits - parameters: - - description: pageSize - in: query - name: limit - type: string - - description: pageNumber - in: query - name: page - type: string - - description: sortColumn - in: query - name: soertColumn - type: string - - description: sortOrder - in: query - name: sortOrder - type: string - - collectionFormat: csv - description: filters - in: query - items: - type: string - name: filter - type: array - - collectionFormat: csv - description: filters - in: query - items: - type: string - name: or - type: array - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditsResponse' - security: - - JWT: [] - summary: Get Audits - tags: - - Audits - post: - consumes: - - application/json - description: Create Audit - parameters: - - description: create audit request - in: body - name: body - required: true - schema: - $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditRequest' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.CreateAuditResponse' - security: - - JWT: [] - summary: Create Audit - tags: - - Audits - /organizations/{organizationId}/audits/{auditId}: - delete: - consumes: - - application/json - description: Delete Audit - parameters: - - description: auditId - in: path - name: auditId - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - security: - - JWT: [] - summary: Delete Audit 'NOT IMPLEMENTED' - tags: - - Audits - get: - consumes: - - application/json - description: Get Audit - parameters: - - description: auditId - in: path - name: auditId - required: true - type: string - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/github_com_openinfradev_tks-api_pkg_domain.GetAuditResponse' - security: - - JWT: [] - summary: Get Audit - tags: - - Audits /organizations/{organizationId}/cloud-accounts: get: consumes: diff --git a/internal/delivery/http/audit.go b/internal/delivery/http/audit.go index 395d9112..2a7b2b99 100644 --- a/internal/delivery/http/audit.go +++ b/internal/delivery/http/audit.go @@ -34,7 +34,7 @@ func NewAuditHandler(h usecase.Usecase) *AuditHandler { // @Produce json // @Param body body domain.CreateAuditRequest true "create audit request" // @Success 200 {object} domain.CreateAuditResponse -// @Router /organizations/{organizationId}/audits [post] +// @Router /admin/audits [post] // @Security JWT func (h *AuditHandler) CreateAudit(w http.ResponseWriter, r *http.Request) { ErrorJSON(w, r, fmt.Errorf("need implementation")) @@ -54,19 +54,12 @@ func (h *AuditHandler) CreateAudit(w http.ResponseWriter, r *http.Request) { // @Param filter query []string false "filters" // @Param or query []string false "filters" // @Success 200 {object} domain.GetAuditsResponse -// @Router /organizations/{organizationId}/audits [get] +// @Router /admin/audits [get] // @Security JWT func (h *AuditHandler) GetAudits(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - organizationId, ok := vars["organizationId"] - if !ok { - ErrorJSON(w, r, httpErrors.NewBadRequestError(fmt.Errorf("Invalid organizationId"), "C_INVALID_ORGANIZATION_ID", "")) - return - } - urlParams := r.URL.Query() pg := pagination.NewPagination(&urlParams) - audits, err := h.usecase.Fetch(r.Context(), organizationId, pg) + audits, err := h.usecase.Fetch(r.Context(), pg) if err != nil { ErrorJSON(w, r, err) return @@ -96,7 +89,7 @@ func (h *AuditHandler) GetAudits(w http.ResponseWriter, r *http.Request) { // @Produce json // @Param auditId path string true "auditId" // @Success 200 {object} domain.GetAuditResponse -// @Router /organizations/{organizationId}/audits/{auditId} [get] +// @Router /admin/audits/{auditId} [get] // @Security JWT func (h *AuditHandler) GetAudit(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) @@ -137,7 +130,7 @@ func (h *AuditHandler) GetAudit(w http.ResponseWriter, r *http.Request) { // @Produce json // @Param auditId path string true "auditId" // @Success 200 {object} nil -// @Router /organizations/{organizationId}/audits/{auditId} [delete] +// @Router /admin/audits/{auditId} [delete] // @Security JWT func (h *AuditHandler) DeleteAudit(w http.ResponseWriter, r *http.Request) { ErrorJSON(w, r, fmt.Errorf("need implementation")) diff --git a/internal/repository/audit.go b/internal/repository/audit.go index c93de560..f7e0c5dd 100644 --- a/internal/repository/audit.go +++ b/internal/repository/audit.go @@ -14,7 +14,7 @@ import ( // Interfaces type IAuditRepository interface { Get(auditId uuid.UUID) (model.Audit, error) - Fetch(organizationId string, pg *pagination.Pagination) ([]model.Audit, error) + Fetch(pg *pagination.Pagination) ([]model.Audit, error) Create(dto model.Audit) (auditId uuid.UUID, err error) Delete(auditId uuid.UUID) (err error) } @@ -38,12 +38,12 @@ func (r *AuditRepository) Get(auditId uuid.UUID) (out model.Audit, err error) { return } -func (r *AuditRepository) Fetch(organizationId string, pg *pagination.Pagination) (out []model.Audit, err error) { +func (r *AuditRepository) Fetch(pg *pagination.Pagination) (out []model.Audit, err error) { if pg == nil { pg = pagination.NewPagination(nil) } - db := r.db.Model(&model.Audit{}).Preload(clause.Associations).Where("audits.organization_id = ?", organizationId) + db := r.db.Model(&model.Audit{}).Preload(clause.Associations) _, res := pg.Fetch(db, &out) if res.Error != nil { return nil, res.Error diff --git a/internal/route/route.go b/internal/route/route.go index 573ca3a1..9605b3cc 100644 --- a/internal/route/route.go +++ b/internal/route/route.go @@ -246,9 +246,9 @@ func SetupRouter(db *gorm.DB, argoClient argowf.ArgoClient, kc keycloak.IKeycloa r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/projects/{projectId}/kubeconfig", customMiddleware.Handle(internalApi.GetProjectKubeconfig, http.HandlerFunc(projectHandler.GetProjectKubeconfig))).Methods(http.MethodGet) auditHandler := delivery.NewAuditHandler(usecaseFactory) - r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/audits", customMiddleware.Handle(internalApi.GetAudits, http.HandlerFunc(auditHandler.GetAudits))).Methods(http.MethodGet) - r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/audits/{auditId}", customMiddleware.Handle(internalApi.GetAudit, http.HandlerFunc(auditHandler.GetAudit))).Methods(http.MethodGet) - r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/audits/{auditId}", customMiddleware.Handle(internalApi.DeleteAudit, http.HandlerFunc(auditHandler.DeleteAudit))).Methods(http.MethodDelete) + r.Handle(API_PREFIX+API_VERSION+"/admin/audits", customMiddleware.Handle(internalApi.GetAudits, http.HandlerFunc(auditHandler.GetAudits))).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/admin/audits/{auditId}", customMiddleware.Handle(internalApi.GetAudit, http.HandlerFunc(auditHandler.GetAudit))).Methods(http.MethodGet) + r.Handle(API_PREFIX+API_VERSION+"/admin/audits/{auditId}", customMiddleware.Handle(internalApi.DeleteAudit, http.HandlerFunc(auditHandler.DeleteAudit))).Methods(http.MethodDelete) roleHandler := delivery.NewRoleHandler(usecaseFactory) r.Handle(API_PREFIX+API_VERSION+"/organizations/{organizationId}/roles", customMiddleware.Handle(internalApi.CreateTksRole, http.HandlerFunc(roleHandler.CreateTksRole))).Methods(http.MethodPost) diff --git a/internal/usecase/audit.go b/internal/usecase/audit.go index 23744826..0e3e5165 100644 --- a/internal/usecase/audit.go +++ b/internal/usecase/audit.go @@ -13,7 +13,7 @@ import ( type IAuditUsecase interface { Get(ctx context.Context, auditId uuid.UUID) (model.Audit, error) - Fetch(ctx context.Context, organizationId string, pg *pagination.Pagination) ([]model.Audit, error) + Fetch(ctx context.Context, pg *pagination.Pagination) ([]model.Audit, error) Create(ctx context.Context, dto model.Audit) (auditId uuid.UUID, err error) Delete(ctx context.Context, dto model.Audit) error } @@ -51,8 +51,8 @@ func (u *AuditUsecase) Get(ctx context.Context, auditId uuid.UUID) (res model.Au return } -func (u *AuditUsecase) Fetch(ctx context.Context, organizationId string, pg *pagination.Pagination) (audits []model.Audit, err error) { - audits, err = u.repo.Fetch(organizationId, pg) +func (u *AuditUsecase) Fetch(ctx context.Context, pg *pagination.Pagination) (audits []model.Audit, err error) { + audits, err = u.repo.Fetch(pg) if err != nil { return nil, err }