yats.git

ref: 0102aa21efe7d4d94a56fc48566c89232fb68064

server/rest/rest-permissions.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * Yats - yats
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Paolo Lulli <kevwe.com>
 * @copyright Paolo Lulli 2024
 */

package rest

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"yats-server/config"
	"yats-server/db"
)

// ShowPermissions godoc
// @Param X-SSL-Client-CN header string true "clientCN"
// @Summary Show available Metrics and Event for current user
// @Schemes
// @Description Show available Metrics and Event for current user
// @Tags Permissions
// @Produce json
// @Success 200 {object} []model.AvailableMetric
// @Router /perms [get]
func ShowPermissions(cfg config.Configuration) gin.HandlerFunc {
	return func(c *gin.Context) {

		clientCN := GetClientCN(c, cfg)

		availableMetrics := db.GetAvailableMetrics(db.Session, clientCN)
		externalSources := db.GetExternalSources(db.Session, clientCN)

		JsonPrint(cfg, c, http.StatusAccepted, gin.H{"metrics": availableMetrics, "externalSources": externalSources})
	}
}