yats.git

ref: master

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)

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