diff --git a/.gitignore b/.gitignore index 9b16619e..17943495 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ /config.yml /build/ /apipark -/aoplatform diff --git a/init.go b/init.go index f0edbabf..3e398f85 100644 --- a/init.go +++ b/init.go @@ -1,5 +1,6 @@ package main +// init module import ( _ "github.com/APIParkLab/APIPark/frontend" _ "github.com/APIParkLab/APIPark/gateway/apinto" diff --git a/initialization-none.go b/initialization-none.go index f4c82193..c241316f 100644 --- a/initialization-none.go +++ b/initialization-none.go @@ -9,5 +9,4 @@ import ( ) func doCheck() { - } diff --git a/initialization.go b/initialization.go index ae49f334..297741be 100644 --- a/initialization.go +++ b/initialization.go @@ -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 } diff --git a/main.go b/main.go index 872a3616..52097fbc 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/middleware/permit/permit.go b/middleware/permit/permit.go index 41880740..428350b6 100644 --- a/middleware/permit/permit.go +++ b/middleware/permit/permit.go @@ -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 diff --git a/model/plugin_model/type.go b/model/plugin_model/type.go index a95cce28..b7fea1f6 100644 --- a/model/plugin_model/type.go +++ b/model/plugin_model/type.go @@ -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 diff --git a/scripts/Dockerfile b/scripts/Dockerfile index cd08cc73..f78900c8 100755 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -1,4 +1,4 @@ -# 名称:apinto通用镜像 +# 名称:apipark通用镜像 # 创建时间:2022-10-25 FROM centos:7.9.2009 MAINTAINER liujian diff --git a/scripts/prefix.sh b/scripts/prefix.sh old mode 100755 new mode 100644 index 800e9117..0ce4577f --- a/scripts/prefix.sh +++ b/scripts/prefix.sh @@ -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