Merge pull request #114 from APIParkLab/feature/permission

update remark
This commit is contained in:
Dot.L
2024-10-28 18:41:17 +08:00
committed by GitHub
9 changed files with 26 additions and 30 deletions
-1
View File
@@ -3,4 +3,3 @@
/config.yml
/build/
/apipark
/aoplatform
+1
View File
@@ -1,5 +1,6 @@
package main
// init module
import (
_ "github.com/APIParkLab/APIPark/frontend"
_ "github.com/APIParkLab/APIPark/gateway/apinto"
-1
View File
@@ -9,5 +9,4 @@ import (
)
func doCheck() {
}
+14 -14
View File
@@ -6,6 +6,11 @@ import (
"bytes"
"encoding/csv"
"fmt"
"os"
"sort"
"strings"
"time"
_ "github.com/APIParkLab/APIPark/resources/access"
_ "github.com/APIParkLab/APIPark/resources/permit"
_ "github.com/APIParkLab/APIPark/resources/plugin"
@@ -14,19 +19,15 @@ import (
"github.com/eolinker/go-common/permit"
"github.com/eolinker/go-common/pm3"
"github.com/eolinker/go-common/utils"
"os"
"sort"
"strings"
"time"
)
const unsetValue = "-"
func doCheck() {
accessConf, unset := loadAccess()
drivers := pm3.List()
newAccess := 0
for _, p := range drivers {
if ac, ok := p.(pm3.AccessConfig); ok {
@@ -39,9 +40,9 @@ func doCheck() {
}
}
}
}
}
for asKey := range permit.All() {
key := strings.ToLower(asKey)
@@ -53,12 +54,11 @@ func doCheck() {
if newAccess > 0 || unset > 0 {
f := accessFile()
fmt.Printf("%d access need set, see : %s and %s", newAccess+unset, saveTemplate(accessConf, f), saveCsv(accessConf, f))
}
os.Exit(0)
}
func accessFile() string {
if version == "" {
return time.Now().Format("20060102-150405")
}
@@ -84,7 +84,7 @@ func saveCsv(as map[string]*Access, key string) string {
err = os.WriteFile(filePath, buf.Bytes(), 0666)
if err != nil {
log.Fatal(err)
}
return filePath
}
@@ -111,9 +111,9 @@ func (ls AccessListSort) Swap(i, j int) {
func saveTemplate(as map[string]*Access, key string) string {
out := make(map[string][]access.Access)
for _, a := range as {
out[a.Group] = append(out[a.Group], access.Access{
Name: a.Name,
CName: a.Cname,
@@ -130,7 +130,7 @@ func saveTemplate(as map[string]*Access, key string) string {
err = os.WriteFile(filePath, buf.Bytes(), 0666)
if err != nil {
log.Fatal(err)
}
return filePath
}
+3 -3
View File
@@ -3,13 +3,14 @@ package main
import (
"flag"
"fmt"
"net"
"net/http"
"github.com/eolinker/eosc/log"
"github.com/eolinker/go-common/autowire"
"github.com/eolinker/go-common/cftool"
"github.com/eolinker/go-common/permit"
"github.com/eolinker/go-common/server"
"net"
"net/http"
)
var (
@@ -54,7 +55,6 @@ func main() {
for access, paths := range srv.Permits() {
permit.AddPermitRule(access, paths...)
}
err = http.Serve(ln, srv)
if err != nil {
log.Fatal(err)
+5 -10
View File
@@ -3,7 +3,7 @@ package permit_middleware
import (
"net/http"
"reflect"
permit_identity "github.com/APIParkLab/APIPark/middleware/permit/identity"
"github.com/eolinker/eosc/log"
"github.com/eolinker/go-common/autowire"
@@ -42,11 +42,11 @@ func (p *PermitMiddleware) Sort() int {
func (p *PermitMiddleware) Check(method string, path string) (bool, []gin.HandlerFunc) {
// 当前路径是否有配置权限
accessRules, has := permit.GetPathRule(method, path)
if !has || len(accessRules) == 0 {
return false, nil
}
return true, []gin.HandlerFunc{
func(ginCtx *gin.Context) {
userId := utils.UserId(ginCtx)
@@ -56,19 +56,14 @@ func (p *PermitMiddleware) Check(method string, path string) (bool, []gin.Handle
ginCtx.Abort()
return
}
//if userId == "admin" {
// // 超级管理员不校验
// return
//}
for _, group := range checkSort {
accessList, has := accessRules[group]
if !has {
// 当前分组没有配置权限
continue
}
domainHandler, has := permit.SelectDomain(group)
if !has {
// 当前分组没有配置身份handler
+1
View File
@@ -9,6 +9,7 @@ type Kind int
func (k *Kind) UnmarshalJSON(bytes []byte) error {
str := ""
err := json.Unmarshal(bytes, &str)
if err != nil {
return err
+1 -1
View File
@@ -1,4 +1,4 @@
# 名称:apinto通用镜像
# 名称:apipark通用镜像
# 创建时间:2022-10-25
FROM centos:7.9.2009
MAINTAINER liujian
Executable → Regular
+1
View File
@@ -25,6 +25,7 @@ cd "./eosc" && git pull
# =========================================================================
echo "更新 aoaccount"
cd "${BASEPATH}/"
if [ ! -d "./aoaccount" ]; then
git clone http://gitlab.eolink.com/apinto/aoaccount.git
fi