Skip to content
/ gopa Public

open policy agent gin middleware for custom usage

Notifications You must be signed in to change notification settings

nkypy/gopa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gopa

使用

// 若要修改默认返回
// 修改包内 ErrResponse
//
// src: rego 文件内容
// data: yaml 文件内容
// path: 数据库路径,若为空,则角色权限在配置文件
// prefix: 路由前缀,写规则可以省略
r := gin.Default()
r.Use(gopa.Opa(src, data, "opa.db", "/api/v1"))

测试

# 新增测试可在 rego 文件中编辑
opa test -v examples/policy.rego examples/policy.yaml

网页访问

# 允许
http://127.0.0.1:8080/v1/orders/1?role=admin
# 不允许
http://127.0.0.1:8080/v1/users/1?role=admin
# 允许
http://127.0.0.1:8080/v1/users/1?role=super_admin

About

open policy agent gin middleware for custom usage

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages