Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d4646d

Browse files
committed
## Changed
- AccessVerify 改成 NoAccessVerify (禁用权限限制, 默认为否, 如需禁用手动赋值true)
1 parentc303379 commit0d4646d

File tree

11 files changed

+83
-80
lines changed

11 files changed

+83
-80
lines changed

‎.github/workflows/todo.yml

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
name:Todo tests
2-
3-
on:
4-
push:
5-
branches:[ "main" ,"dev"]
6-
pull_request:
7-
branches:[ "main", "dev" ]
8-
9-
jobs:
10-
11-
build:
12-
runs-on:ubuntu-latest
13-
services:
14-
mysql:
15-
image:mysql:5.7.37
16-
env:
17-
MYSQL_ROOT_PASSWORD:'yourpassword'
18-
MYSQL_DATABASE:'my_apijson'
19-
ports:
20-
-3306:3306
21-
options:>-
22-
--health-cmd="mysqladmin ping"
23-
--health-interval=10s
24-
--health-timeout=5s
25-
--health-retries=3
26-
steps:
27-
-uses:actions/checkout@v3
28-
29-
-name:Set up Go
30-
uses:actions/setup-go@v3
31-
with:
32-
go-version:1.18
33-
34-
35-
36-
-name:Test
37-
run:|
38-
39-
mysql -uroot -h 127.0.0.1 --port 3306 -pyourpassword my_apijson < @demo/todo/doc/todo.sql
40-
41-
cd ./@demo/todo
42-
mv config.yaml.example config.yaml
43-
44-
cd tests
45-
go test -v
1+
#name: Todo tests
2+
#
3+
#on:
4+
# push:
5+
# branches: [ "main" ,"dev"]
6+
# pull_request:
7+
# branches: [ "main", "dev" ]
8+
#
9+
#jobs:
10+
#
11+
# build:
12+
# runs-on: ubuntu-latest
13+
# services:
14+
# mysql:
15+
# image: mysql:5.7.37
16+
# env:
17+
# MYSQL_ROOT_PASSWORD: 'yourpassword'
18+
# MYSQL_DATABASE: 'my_apijson'
19+
# ports:
20+
# - 3306:3306
21+
# options: >-
22+
# --health-cmd="mysqladmin ping"
23+
# --health-interval=10s
24+
# --health-timeout=5s
25+
# --health-retries=3
26+
# steps:
27+
# - uses: actions/checkout@v3
28+
#
29+
# - name: Set up Go
30+
# uses: actions/setup-go@v3
31+
# with:
32+
# go-version: 1.18
33+
#
34+
#
35+
#
36+
# - name: Test
37+
# run: |
38+
#
39+
# mysql -uroot -h 127.0.0.1 --port 3306 -pyourpassword my_apijson < @demo/todo/doc/todo.sql
40+
#
41+
# cd ./@demo/todo
42+
# mv config.yaml.example config.yaml
43+
#
44+
# cd tests
45+
# go test -v

‎action/action.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ type Action struct {
2525
childrenmap[string]*Node
2626
keyNodemap[string]*Node
2727

28-
AccessVerifybool
28+
// 关闭 access 权限验证, 默认否
29+
NoAccessVerifybool
30+
// 关闭 request 验证开关, 默认否
31+
NoRequestVerifybool
2932
}
3033

3134
funcNew(ctx context.Context,methodstring,req model.Map)*Action {

‎action/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (n *Node) parse(ctx context.Context, method string) error {
9797
returnerr
9898
}
9999

100-
ifn.action.AccessVerify {
100+
ifn.action.NoAccessVerify==false {
101101
// 1. 检查权限, 无权限就不用做参数检查了
102102
varaccessRoles []string
103103

‎config/access.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type AccessCondition func(ctx context.Context, req AccessConditionReq) (g.Map, e
2828
typeDefaultRolefunc(ctx context.Context,reqRoleReq) (string,error)
2929

3030
var (
31-
// AccessVerify是否权限验证
32-
AccessVerify=true
31+
// AccessVerify是否禁用权限验证
32+
NoAccessVerify=true
3333
// AccessConditionFunc 自定义权限限制条件
3434
AccessConditionFuncAccessCondition
3535
// DefaultRoleFunc 自定义获取节点的默认角色

‎config/executor/query.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ type QueryExecutor interface {
1515
EmptyResult()
1616
}
1717

18-
typequeryExecutorBuilderfunc(ctx context.Context,accessVerifybool,rolestring,access*db.Access) (QueryExecutor,error)
18+
typequeryExecutorBuilderfunc(ctx context.Context,noAccessVerifybool,rolestring,access*db.Access) (QueryExecutor,error)
1919

2020
varqueryExecutorBuilderMap=map[string]queryExecutorBuilder{}
2121

2222
funcRegQueryExecutor(namestring,equeryExecutorBuilder) {
2323
queryExecutorBuilderMap[name]=e
2424
}
2525

26-
funcNewQueryExecutor(namestring,ctx context.Context,accessVerifybool,rolestring,access*db.Access) (QueryExecutor,error) {
26+
funcNewQueryExecutor(namestring,ctx context.Context,noAccessVerifybool,rolestring,access*db.Access) (QueryExecutor,error) {
2727
ifv,exists:=queryExecutorBuilderMap[name];exists {
28-
returnv(ctx,accessVerify,role,access)
28+
returnv(ctx,noAccessVerify,role,access)
2929
}
30-
returnqueryExecutorBuilderMap["default"](ctx,accessVerify,role,access)
30+
returnqueryExecutorBuilderMap["default"](ctx,noAccessVerify,role,access)
3131
}
3232

3333
funcQueryExecutorList() []string {

‎framework/gf_orm/query.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ type SqlExecutor struct {
3232
// 是否最终为空结果, 用于node中中断数据获取
3333
WithEmptyResultbool
3434

35-
accessVerifybool
35+
noAccessVerifybool
3636

3737
access*db.Access
3838
}
3939

40-
funcNew(ctx context.Context,accessVerifybool,rolestring,access*db.Access) (executor.QueryExecutor,error) {
40+
funcNew(ctx context.Context,noAccessVerifybool,rolestring,access*db.Access) (executor.QueryExecutor,error) {
4141

4242
return&SqlExecutor{
4343
ctx:ctx,
@@ -47,7 +47,7 @@ func New(ctx context.Context, accessVerify bool, role string, access *db.Access)
4747
Order:"",
4848
Group:"",
4949
WithEmptyResult:false,
50-
accessVerify:accessVerify,
50+
noAccessVerify:noAccessVerify,
5151
access:access,
5252
},nil
5353
}
@@ -67,7 +67,7 @@ func (e *SqlExecutor) ParseCondition(conditions model.MapStrAny, accessVerify bo
6767
casestrings.HasSuffix(key,consts.OpRegexp):
6868
e.Where=append(e.Where, []any{key[0 :len(key)-1],consts.SqlRegexp,gconv.String(condition)})
6969

70-
casekey=="@raw"&&!accessVerify:
70+
casekey==consts.Raw&&!accessVerify:
7171
e.accessCondition=condition.(model.Map)
7272

7373
default:
@@ -79,7 +79,7 @@ func (e *SqlExecutor) ParseCondition(conditions model.MapStrAny, accessVerify bo
7979
returnnil
8080
}
8181

82-
if!e.accessVerify {// 可任意字段搜索
82+
ife.noAccessVerify {// 可任意字段搜索
8383
returnnil
8484
}
8585

@@ -302,7 +302,7 @@ func (e *SqlExecutor) column() []string {
302302
}
303303

304304
// 过滤可访问字段
305-
if!e.accessVerify||lo.Contains(outFields,dbStyle(e.ctx,tableName,fieldName))||
305+
ife.noAccessVerify||lo.Contains(outFields,dbStyle(e.ctx,tableName,fieldName))||
306306
len(outFields)==0/* 数据库中未设置, 则看成全部可访问 */ {
307307
fields=append(fields,column)
308308
}

‎framework/handler/handler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919

2020
funcGet(ctx context.Context,req model.Map) (res model.Map,errerror) {
2121
q:=query.New(ctx,req)
22-
q.AccessVerify=config.AccessVerify
22+
q.NoAccessVerify=config.NoAccessVerify
2323
q.AccessCondition=config.AccessConditionFunc
2424
returnq.Result()
2525
}
@@ -30,19 +30,19 @@ func Head(ctx context.Context, req model.Map) (res model.Map, err error) {
3030

3131
funcPost(ctx context.Context,req model.Map) (res model.Map,errerror) {
3232
act:=action.New(ctx,http.MethodPost,req)
33-
act.AccessVerify=config.AccessVerify
33+
act.NoAccessVerify=config.NoAccessVerify
3434
returnact.Result()
3535
}
3636

3737
funcPut(ctx context.Context,req model.Map) (res model.Map,errerror) {
3838
act:=action.New(ctx,http.MethodPut,req)
39-
act.AccessVerify=config.AccessVerify
39+
act.NoAccessVerify=config.NoAccessVerify
4040
returnact.Result()
4141
}
4242

4343
funcDelete(ctx context.Context,req model.Map) (res model.Map,errerror) {
4444
act:=action.New(ctx,http.MethodDelete,req)
45-
act.AccessVerify=config.AccessVerify
45+
act.NoAccessVerify=config.NoAccessVerify
4646
returnact.Result()
4747
}
4848

‎go.mod

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
modulegithub.com/glennliao/apijson-go
22

3-
go1.18
4-
53
require (
6-
github.com/glennliao/table-syncv0.0.0-00010101000000-000000000000
7-
github.com/gogf/gf/contrib/drivers/mysql/v2v2.3.1
8-
github.com/gogf/gf/v2v2.3.1
4+
github.com/glennliao/table-syncv0.2.0
5+
github.com/gogf/gf/contrib/drivers/mysql/v2v2.3.2
6+
github.com/gogf/gf/v2v2.3.2
97
github.com/iancoleman/orderedmapv0.2.0
108
github.com/samber/lov1.33.0
119
)
1210

13-
replacegithub.com/glennliao/table-sync =>../table-sync
14-
1511
require (
1612
github.com/BurntSushi/tomlv1.1.0// indirect
1713
github.com/clbanning/mxj/v2v2.5.5// indirect
@@ -36,3 +32,5 @@ require (
3632
golang.org/x/textv0.3.8-0.20211105212822-18b340fc7af2// indirect
3733
gopkg.in/yaml.v3v3.0.1// indirect
3834
)
35+
36+
go1.18

‎go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
1515
github.com/fsnotify/fsnotifyv1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
1616
github.com/fsnotify/fsnotifyv1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
1717
github.com/fsnotify/fsnotifyv1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
18+
github.com/glennliao/table-syncv0.2.0 h1:uxkrgNcDHCA/G27qk00+FqF2a832VVXmFX+/5zRHSkQ=
19+
github.com/glennliao/table-syncv0.2.0/go.mod h1:YgVRcaEqwZMQqjN0fuWqOCAo2vMkfbUE9OSXM6jgiYw=
1820
github.com/go-logr/logrv1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
1921
github.com/go-logr/logrv1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
2022
github.com/go-logr/logrv1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -24,11 +26,11 @@ github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Px
2426
github.com/go-sql-driver/mysqlv1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
2527
github.com/go-sql-driver/mysqlv1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
2628
github.com/go-task/slim-sprigv0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
27-
github.com/gogf/gf/contrib/drivers/mysql/v2v2.3.1 h1:uSZtDmlTFS51A98KPgZElPigSGDi7PPDN6mxeIXtsLo=
28-
github.com/gogf/gf/contrib/drivers/mysql/v2v2.3.1/go.mod h1:z+/0qiOwMroAnj5ESuobTv0l5P83rf+XR3r6Fj8WJyk=
29+
github.com/gogf/gf/contrib/drivers/mysql/v2v2.3.2 h1:BZww6QOFgiN/YvovUtN64sgnq59TIg8vtkG8AL6eSl0=
30+
github.com/gogf/gf/contrib/drivers/mysql/v2v2.3.2/go.mod h1:z+/0qiOwMroAnj5ESuobTv0l5P83rf+XR3r6Fj8WJyk=
2931
github.com/gogf/gf/v2v2.0.0/go.mod h1:apktt6TleWtCIwpz63vBqUnw8MX8gWKoZyxgDpXFtgM=
30-
github.com/gogf/gf/v2v2.3.1 h1:uptCJK47N6KSRwTBnFAqBWYnYa/OXBkZ0OlhO9CK7bQ=
31-
github.com/gogf/gf/v2v2.3.1/go.mod h1:tsbmtwcAl2chcYoq/fP9W2FZf06aw4i89X34nbSHo9Y=
32+
github.com/gogf/gf/v2v2.3.2 h1:nlJ0zuDWqFb93/faZmr7V+GADx/lzz5Unz/9x6OJ2u8=
33+
github.com/gogf/gf/v2v2.3.2/go.mod h1:tsbmtwcAl2chcYoq/fP9W2FZf06aw4i89X34nbSHo9Y=
3234
github.com/golang/protobufv1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
3335
github.com/golang/protobufv1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
3436
github.com/golang/protobufv1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=

‎query/node.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func newNode(query *Query, key string, path string, nodeReq any) *Node {
109109
}else {
110110
node.Type=NodeTypeStruct// 结构节点下应该必须存在查询节点
111111

112-
if!query.AccessVerify {
112+
ifquery.NoAccessVerify==false {
113113
iflo.Contains(db.GetTableNameList(),k) {
114114
node.Type=NodeTypeQuery
115115
}
@@ -210,7 +210,7 @@ func (n *Node) parse() {
210210
caseNodeTypeQuery:
211211
tableKey:=parseTableKey(n.Key,n.Path)
212212

213-
access,err:=db.GetAccess(tableKey,n.queryContext.AccessVerify)
213+
access,err:=db.GetAccess(tableKey,n.queryContext.NoAccessVerify)
214214
iferr!=nil {
215215
n.err=err
216216
return
@@ -225,7 +225,7 @@ func (n *Node) parse() {
225225
return
226226
}
227227

228-
ifn.queryContext.AccessVerify {
228+
ifn.queryContext.NoAccessVerify!=false {
229229
has,condition,err:=hasAccess(n,tableKey)
230230
iferr!=nil {
231231
n.err=err
@@ -240,7 +240,7 @@ func (n *Node) parse() {
240240
accessWhereCondition=condition
241241
}
242242

243-
queryExecutor,err:=executor.NewQueryExecutor(access.Executor,n.ctx,n.queryContext.AccessVerify,n.role,access)
243+
queryExecutor,err:=executor.NewQueryExecutor(access.Executor,n.ctx,n.queryContext.NoAccessVerify,n.role,access)
244244
iferr!=nil {
245245
n.err=err
246246
return

‎query/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type Query struct {
3232
// 输出过程
3333
PrintProcessLogbool
3434

35-
//是否权限验证
36-
AccessVerifybool
35+
//关闭权限验证 , 默认否
36+
NoAccessVerifybool
3737
// 自定义可访问权限的限定, 例如添加用户id的where条件
3838
AccessCondition config.AccessCondition
3939
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp