feat: (rbac) list permission api.
fix: (model/alerting) tag syntax error
This commit is contained in:
parent
a377918e9d
commit
844f091a13
|
@ -1,15 +1,15 @@
|
||||||
package alerting
|
package alerting
|
||||||
|
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
Enabled bool `json:"enabled" elastic_mapping:"enabled: {type:boolean}"`
|
Enabled bool `json:"enabled" elastic_mapping:"enabled: {type:boolean}"`
|
||||||
EnabledTime int64 `json:"enabled_time" elastic_mapping:"enabled_time:{type:date,format:strict_date_time||epoch_millis}"`
|
EnabledTime int64 `json:"enabled_time" elastic_mapping:"enabled_time:{type:date,format:strict_date_time||epoch_millis}"`
|
||||||
Inputs []MonitorInput `json:"inputs" elastic_mapping:"inputs:{type:nested}"`
|
Inputs []MonitorInput `json:"inputs" elastic_mapping:"inputs:{type:nested}"`
|
||||||
LastUpdateTime int64 `json:"last_update_time" elastic_mapping:"last_update_time:{type:date,format:strict_date_time||epoch_millis}"`
|
LastUpdateTime int64 `json:"last_update_time" elastic_mapping:"last_update_time:{type:date,format:strict_date_time||epoch_millis}"`
|
||||||
Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"`
|
Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"`
|
||||||
Schedule Schedule `json:"schedule" elastic_mapping:"schedule:{type:object}"`
|
Schedule Schedule `json:"schedule" elastic_mapping:"schedule:{type:object}"`
|
||||||
SchemaVersion int `json:"schema_version" elastic_mapping:"schema_version:{type:integer}"`
|
SchemaVersion int `json:"schema_version" elastic_mapping:"schema_version:{type:integer}"`
|
||||||
Triggers []Trigger `json:"triggers" elastic_mapping:"triggers:{type:nested}"`
|
Triggers []Trigger `json:"triggers" elastic_mapping:"triggers:{type:nested}"`
|
||||||
Type string `json:"type" elastic_mapping:"type:{type:keyword}`
|
Type string `json:"type" elastic_mapping:"type:{type:keyword}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MonitorInput struct {
|
type MonitorInput struct {
|
||||||
|
@ -17,47 +17,45 @@ type MonitorInput struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MonitorSearch struct {
|
type MonitorSearch struct {
|
||||||
Indices []string `json:"indices" elastic_mapping:"indices:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"`
|
Indices []string `json:"indices" elastic_mapping:"indices:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"`
|
||||||
Query map[string]interface{} `json:"query" elastic_mapping:"query:{type:object,enabled:false}"`
|
Query map[string]interface{} `json:"query" elastic_mapping:"query:{type:object,enabled:false}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Cron struct {
|
type Cron struct {
|
||||||
Expression string `json:"expression" elastic_mapping:"expression:{type:text}"`
|
Expression string `json:"expression" elastic_mapping:"expression:{type:text}"`
|
||||||
Timezone string `json:"timezone" elastic_mapping:"timezone:{type:keyword}"`
|
Timezone string `json:"timezone" elastic_mapping:"timezone:{type:keyword}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Period struct {
|
type Period struct {
|
||||||
Interval int `json:"interval" elastic_mapping:"interval:{type:integer}"`
|
Interval int `json:"interval" elastic_mapping:"interval:{type:integer}"`
|
||||||
Unit string `json:"unit" elastic_mapping:"unit:{type:keyword}"`
|
Unit string `json:"unit" elastic_mapping:"unit:{type:keyword}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type Schedule struct {
|
type Schedule struct {
|
||||||
Cron *Cron `json:"cron,omitempty" elastic_mapping:"cron:{type:object}"`
|
Cron *Cron `json:"cron,omitempty" elastic_mapping:"cron:{type:object}"`
|
||||||
Period *Period `json:"period,omitempty" elastic_mapping:"period:{type:object}"`
|
Period *Period `json:"period,omitempty" elastic_mapping:"period:{type:object}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type Throttle struct {
|
type Throttle struct {
|
||||||
Unit string `json:"unit" elastic_mapping:"unit:{type:keyword}"`
|
Unit string `json:"unit" elastic_mapping:"unit:{type:keyword}"`
|
||||||
Value int `json:"value" elastic_mapping:"value:{type:integer}"`
|
Value int `json:"value" elastic_mapping:"value:{type:integer}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Action struct {
|
type Action struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
DestinationId string `json:"destination_id" elastic_mapping:"destination_id:{type:keyword}"`
|
DestinationId string `json:"destination_id" elastic_mapping:"destination_id:{type:keyword}"`
|
||||||
MessageTemplate map[string]interface{} `json:"message_template" elastic_mapping:"message_template:{type:object}"`
|
MessageTemplate map[string]interface{} `json:"message_template" elastic_mapping:"message_template:{type:object}"`
|
||||||
Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"`
|
Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"`
|
||||||
SubjectTemplate map[string]interface{} `json:"subject_template" elastic_mapping:"subject_template:{type:object}"`
|
SubjectTemplate map[string]interface{} `json:"subject_template" elastic_mapping:"subject_template:{type:object}"`
|
||||||
ThrottleEnabled bool `json:"throttle_enabled" elastic_mapping:"throttle_enabled:{type:boolean}"`
|
ThrottleEnabled bool `json:"throttle_enabled" elastic_mapping:"throttle_enabled:{type:boolean}"`
|
||||||
Throttle *Throttle `json:"throttle,omitempty" elastic_mapping:"throttle:{type:object}"`
|
Throttle *Throttle `json:"throttle,omitempty" elastic_mapping:"throttle:{type:object}"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Trigger struct {
|
type Trigger struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Severity string `json:"severity" elastic_mapping:"severity:{type:keyword}"`
|
Severity string `json:"severity" elastic_mapping:"severity:{type:keyword}"`
|
||||||
Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"`
|
Name string `json:"name" elastic_mapping:"name:{type:text,fields: {keyword: {type: keyword, ignore_above: 256}}}"`
|
||||||
Condition map[string]interface{} `json:"condition" elastic_mapping:"condition:{type:object, enabled:false}"`
|
Condition map[string]interface{} `json:"condition" elastic_mapping:"condition:{type:object, enabled:false}"`
|
||||||
Actions []Action `json:"actions" elastic_mapping:"actions:{type:nested}"`
|
Actions []Action `json:"actions" elastic_mapping:"actions:{type:nested}"`
|
||||||
MinTimeBetweenExecutions int `json:"min_time_between_executions" elastic_mapping:"min_time_between_executions:{type:integer}"`
|
MinTimeBetweenExecutions int `json:"min_time_between_executions" elastic_mapping:"min_time_between_executions:{type:integer}"`
|
||||||
}
|
}
|
|
@ -30,6 +30,7 @@ func ListElasticsearchPermisson() (permisson ElasticsearchPermisson, err error)
|
||||||
|
|
||||||
permisson = ElasticsearchPermisson{
|
permisson = ElasticsearchPermisson{
|
||||||
ClusterPrivileges: CategoryApi["list"],
|
ClusterPrivileges: CategoryApi["list"],
|
||||||
|
IndexPrivileges: CategoryApi["indices"],
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package rbac
|
package rbac
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
log "github.com/cihub/seelog"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"infini.sh/console/plugin/api/rbac/biz"
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
@ -17,6 +20,26 @@ type Response struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h Permisson) ListPermission(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (h Permisson) ListPermission(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
typ := ps.MustGetParameter("type")
|
||||||
|
var err error
|
||||||
|
var permissons interface{}
|
||||||
|
switch typ {
|
||||||
|
case Console:
|
||||||
|
permissons, err = biz.ListConsolePermisson()
|
||||||
|
|
||||||
|
case Elastisearch:
|
||||||
|
permissons, err = biz.ListElasticsearchPermisson()
|
||||||
|
default:
|
||||||
|
err = errors.New("unsupport type parmeter " + typ)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
_ = log.Error(err.Error())
|
||||||
|
_ = h.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_ = h.WriteJSON(w, Response{
|
||||||
|
Hit: permissons,
|
||||||
|
}, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue