From 9a2257dd1ef2e0d9955dc56f99c631ff30e34fa5 Mon Sep 17 00:00:00 2001 From: UlricQin Date: Tue, 4 Jan 2022 16:47:03 +0800 Subject: [PATCH 1/2] ldap user default role configuration --- etc/webapi.conf | 2 ++ src/models/user.go | 8 ++++++-- src/pkg/ldapx/ldapx.go | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/etc/webapi.conf b/etc/webapi.conf index 7f2e3aad..78166498 100644 --- a/etc/webapi.conf +++ b/etc/webapi.conf @@ -90,6 +90,8 @@ AuthFilter = "(&(uid=%s))" CoverAttributes = true TLS = false StartTLS = true +# ldap user default roles +DefaultRoles = ["Standard"] [LDAP.Attributes] Nickname = "cn" diff --git a/src/models/user.go b/src/models/user.go index 094c34f6..a336f0e0 100644 --- a/src/models/user.go +++ b/src/models/user.go @@ -259,10 +259,14 @@ func LdapLogin(username, pass string) (*User, error) { now := time.Now().Unix() + if len(config.C.LDAP.DefaultRoles) == 0 { + config.C.LDAP.DefaultRoles = []string{"Standard"} + } + user.Password = "******" user.Portrait = "" - user.Roles = "Standard" - user.RolesLst = []string{"Standard"} + user.Roles = strings.Join(config.C.LDAP.DefaultRoles, " ") + user.RolesLst = config.C.LDAP.DefaultRoles user.Contacts = []byte("{}") user.CreateAt = now user.UpdateAt = now diff --git a/src/pkg/ldapx/ldapx.go b/src/pkg/ldapx/ldapx.go index e8e4de77..a5366460 100644 --- a/src/pkg/ldapx/ldapx.go +++ b/src/pkg/ldapx/ldapx.go @@ -19,6 +19,7 @@ type LdapSection struct { CoverAttributes bool TLS bool StartTLS bool + DefaultRoles []string } type LdapAttributes struct { From 850a370f9d41f356463deb4ff5c1cdebc88cf0a6 Mon Sep 17 00:00:00 2001 From: UlricQin Date: Thu, 6 Jan 2022 11:48:30 +0800 Subject: [PATCH 2/2] add targets apis --- src/webapi/router/router.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/webapi/router/router.go b/src/webapi/router/router.go index 991f032e..5b631739 100644 --- a/src/webapi/router/router.go +++ b/src/webapi/router/router.go @@ -238,5 +238,13 @@ func configRoute(r *gin.Engine, version string) { { service.Any("/prometheus/*url", prometheusProxy) service.POST("/users", userAddPost) + + service.GET("/targets", targetGets) + service.DELETE("/targets", targetDel) + service.GET("/targets/tags", targetGetTags) + service.POST("/targets/tags", targetBindTags) + service.DELETE("/targets/tags", targetUnbindTags) + service.PUT("/targets/note", targetUpdateNote) + service.PUT("/targets/bgid", targetUpdateBgid) } }