use configuration file to control AnonymousAccess

This commit is contained in:
Ulric Qin 2021-12-09 16:59:02 +08:00
parent bf4e0ca7c0
commit 32fea64f3e
4 changed files with 43 additions and 20 deletions

View File

@ -72,6 +72,10 @@ RedisKeyPrefix = "/jwt/"
[BasicAuth] [BasicAuth]
user001 = "ccc26da7b9aba533cbb263a36c07dcc5" user001 = "ccc26da7b9aba533cbb263a36c07dcc5"
[AnonymousAccess]
PromQuerier = false
AlertDetail = false
[LDAP] [LDAP]
Enable = false Enable = false
Host = "ldap.example.org" Host = "ldap.example.org"

View File

@ -72,6 +72,10 @@ RedisKeyPrefix = "/jwt/"
[BasicAuth] [BasicAuth]
user001 = "ccc26da7b9aba533cbb263a36c07dcc5" user001 = "ccc26da7b9aba533cbb263a36c07dcc5"
[AnonymousAccess]
PromQuerier = false
AlertDetail = false
[LDAP] [LDAP]
Enable = false Enable = false
Host = "ldap.example.org" Host = "ldap.example.org"

View File

@ -74,22 +74,23 @@ func MustLoad(fpaths ...string) {
} }
type Config struct { type Config struct {
RunMode string RunMode string
I18N string I18N string
AdminRole string AdminRole string
ContactKeys []ContactKey ContactKeys []ContactKey
NotifyChannels []string NotifyChannels []string
Log logx.Config Log logx.Config
HTTP httpx.Config HTTP httpx.Config
JWTAuth JWTAuth JWTAuth JWTAuth
BasicAuth gin.Accounts BasicAuth gin.Accounts
LDAP ldapx.LdapSection AnonymousAccess AnonymousAccess
Redis storage.RedisConfig LDAP ldapx.LdapSection
Gorm storage.Gorm Redis storage.RedisConfig
MySQL storage.MySQL Gorm storage.Gorm
Postgres storage.Postgres MySQL storage.MySQL
Clusters []prom.Options Postgres storage.Postgres
Ibex Ibex Clusters []prom.Options
Ibex Ibex
} }
type ContactKey struct { type ContactKey struct {
@ -104,6 +105,11 @@ type JWTAuth struct {
RedisKeyPrefix string RedisKeyPrefix string
} }
type AnonymousAccess struct {
PromQuerier bool
AlertDetail bool
}
type Ibex struct { type Ibex struct {
Address string Address string
BasicAuthUser string BasicAuthUser string

View File

@ -100,7 +100,11 @@ func configRoute(r *gin.Engine, version string) {
pages := r.Group(pagesPrefix) pages := r.Group(pagesPrefix)
{ {
pages.Any("/prometheus/*url", prometheusProxy) if config.C.AnonymousAccess.PromQuerier {
pages.Any("/prometheus/*url", prometheusProxy)
} else {
pages.Any("/prometheus/*url", jwtAuth(), prometheusProxy)
}
pages.GET("/version", func(c *gin.Context) { pages.GET("/version", func(c *gin.Context) {
c.String(200, version) c.String(200, version)
@ -201,12 +205,17 @@ func configRoute(r *gin.Engine, version string) {
// pages.GET("/busi-group/:id/collect-rule/:crid", jwtAuth(), user(), bgro(), collectRuleGet) // pages.GET("/busi-group/:id/collect-rule/:crid", jwtAuth(), user(), bgro(), collectRuleGet)
// pages.PUT("/busi-group/:id/collect-rule/:crid", jwtAuth(), user(), bgrw(), collectRulePut) // pages.PUT("/busi-group/:id/collect-rule/:crid", jwtAuth(), user(), bgrw(), collectRulePut)
pages.GET("/busi-group/:id/alert-his-events", jwtAuth(), user(), bgro(), alertHisEventGets)
pages.GET("/busi-group/:id/alert-cur-events", jwtAuth(), user(), bgro(), alertCurEventGets) pages.GET("/busi-group/:id/alert-cur-events", jwtAuth(), user(), bgro(), alertCurEventGets)
pages.DELETE("/busi-group/:id/alert-cur-events", jwtAuth(), user(), bgrw(), alertCurEventDel) pages.DELETE("/busi-group/:id/alert-cur-events", jwtAuth(), user(), bgrw(), alertCurEventDel)
pages.GET("/alert-cur-event/:eid", alertCurEventGet)
pages.GET("/busi-group/:id/alert-his-events", jwtAuth(), user(), bgro(), alertHisEventGets) if config.C.AnonymousAccess.AlertDetail {
pages.GET("/alert-his-event/:eid", alertHisEventGet) pages.GET("/alert-cur-event/:eid", alertCurEventGet)
pages.GET("/alert-his-event/:eid", alertHisEventGet)
} else {
pages.GET("/alert-cur-event/:eid", jwtAuth(), alertCurEventGet)
pages.GET("/alert-his-event/:eid", jwtAuth(), alertHisEventGet)
}
pages.GET("/busi-group/:id/task-tpls", jwtAuth(), user(), bgro(), taskTplGets) pages.GET("/busi-group/:id/task-tpls", jwtAuth(), user(), bgro(), taskTplGets)
pages.POST("/busi-group/:id/task-tpls", jwtAuth(), user(), bgrw(), taskTplAdd) pages.POST("/busi-group/:id/task-tpls", jwtAuth(), user(), bgrw(), taskTplAdd)