blob: 691661540d1226a23a89fe0a2ad51d1f76cf3e69 [file]
/**
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Package controller serves /api/v1/audit-events.
package controller
import (
"net/http"
"github.com/apache/airavata/internal/httpx"
"github.com/apache/airavata/api/audit/dto"
"github.com/apache/airavata/api/audit/service"
)
// EventController serves the audit log.
type EventController struct{ svc *service.EventService }
// NewEventController returns a handler delegating to svc.
func NewEventController(svc *service.EventService) *EventController {
return &EventController{svc: svc}
}
// Register mounts the audit routes.
func (h *EventController) Register(mux *http.ServeMux) {
mux.HandleFunc("GET /api/v1/audit-events", h.list)
mux.HandleFunc("GET /api/v1/audit-events/entity-types", h.entityTypes)
}
func (h *EventController) list(w http.ResponseWriter, r *http.Request) {
q, err := dto.ParseEventQuery(r.URL.Query())
if err != nil {
httpx.WriteError(w, r, err)
return
}
out, err := h.svc.List(r.Context(), q)
if err != nil {
httpx.WriteError(w, r, err)
return
}
httpx.WriteJSON(w, http.StatusOK, out)
}
func (h *EventController) entityTypes(w http.ResponseWriter, r *http.Request) {
out, err := h.svc.EntityTypes(r.Context())
if err != nil {
httpx.WriteError(w, r, err)
return
}
httpx.WriteJSON(w, http.StatusOK, out)
}