Skip to content

Commit

Permalink
Merge remote-tracking branch 'gitlab/feature/add-label'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dot-Liu committed Jun 17, 2022
2 parents d360c0f + 58cc7de commit cb16d54
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 277 deletions.
2 changes: 0 additions & 2 deletions app/apinto/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
proxy_rewrite "github.com/eolinker/apinto/drivers/plugins/proxy-rewrite"
rate_limiting "github.com/eolinker/apinto/drivers/plugins/rate-limiting"
response_rewrite "github.com/eolinker/apinto/drivers/plugins/response-rewrite"
"github.com/eolinker/apinto/drivers/plugins/rewrite"
http_router "github.com/eolinker/apinto/drivers/router/http-router"
service_http "github.com/eolinker/apinto/drivers/service/service-http"
upstream_http "github.com/eolinker/apinto/drivers/upstream/upstream-http"
Expand Down Expand Up @@ -75,7 +74,6 @@ func Register(extenderRegister eosc.IExtenderDriverRegister) {
plugin_manager.Register(extenderRegister)

auth.Register(extenderRegister)
rewrite.Register(extenderRegister)

extra_params.Register(extenderRegister)
params_transformer.Register(extenderRegister)
Expand Down
8 changes: 4 additions & 4 deletions drivers/auth/aksk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ type akskUsers struct {
}

type AKSKConfig struct {
AK string `json:"ak"`
SK string `json:"sk"`
Labels map[string]string `json:"labels"`
Expire int64 `json:"expire" format:"date-time"`
AK string `json:"ak" label:"Access Key" nullable:"false"`
SK string `json:"sk" label:"Secret Access Key" nullable:"false"`
Labels map[string]string `json:"labels" label:"用户标签"`
Expire int64 `json:"expire" format:"date-time" label:"过期时间"`
}
6 changes: 3 additions & 3 deletions drivers/auth/apikey/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type apiKeyUsers struct {

//User 用户信息
type User struct {
Apikey string `json:"apikey"`
Labels map[string]string `json:"labels"`
Expire int64 `json:"expire" format:"date-time"`
Apikey string `json:"apikey" label:"密钥(Apikey)" nullable:"false"`
Labels map[string]string `json:"labels" label:"用户标签"`
Expire int64 `json:"expire" format:"date-time" label:"过期时间"`
}
8 changes: 4 additions & 4 deletions drivers/auth/basic/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type Config struct {

//User 用户信息
type User struct {
Username string `json:"username"`
Password string `json:"password"`
Labels map[string]string `json:"labels"`
Expire int64 `json:"expire" format:"date-time"`
Username string `json:"username" label:"用户名(username)" nullable:"false"`
Password string `json:"password" label:"密码(password)" nullable:"false"`
Labels map[string]string `json:"labels" label:"用户标签"`
Expire int64 `json:"expire" format:"date-time" label:"过期时间"`
}
10 changes: 5 additions & 5 deletions drivers/auth/jwt/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ type jwtUsers struct {

//JwtCredential JWT验证信息
type JwtCredential struct {
Iss string `json:"iss"`
Secret string `json:"secret"`
RSAPublicKey string `json:"rsa_public_key"`
Algorithm string `json:"algorithm"`
Labels map[string]string `json:"labels"`
Iss string `json:"iss" label:"证书签发者" description:"playload计算内容之一"`
Secret string `json:"secret" label:"密钥" description:"加密算法是HS时必填,用于校验token"`
RSAPublicKey string `json:"rsa_public_key" label:"RSA公钥" description:"加密算法是RS或ES时必填,用于校验token"`
Algorithm string `json:"algorithm" enum:"HS256,HS384,HS512,RS256,RS384,RS512,ES256,ES384,ES512" label:"签名算法"`
Labels map[string]string `json:"labels" label:"用户标签"`
}
10 changes: 5 additions & 5 deletions drivers/discovery/static/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
//Config 静态服务发现配置
type Config struct {
Scheme string `json:"scheme" enum:"HTTP,HTTPS" label:"请求协议"`
HealthOn bool `json:"health_on" label:"健康检查"`
Health *HealthConfig `json:"health" switch:"health_on===true"`
HealthOn bool `json:"health_on" label:"是否开启健康检查"`
Health *HealthConfig `json:"health" label:"健康检查配置" switch:"health_on===true"`
}

func (c *Config) getScheme() string {
Expand All @@ -25,7 +25,7 @@ type HealthConfig struct {
Scheme string `json:"scheme" enum:"HTTP,HTTPS" label:"请求协议"`
Method string `json:"method" enum:"GET,POST,PUT" label:"请求方式"`
URL string `json:"url" label:"请求URL"`
SuccessCode int `json:"success_code" label:"成功状态码" minimum:"99"`
Period int `json:"period" label:"检查频率(单位:s)" minimum:"1" default:"30"`
Timeout int `json:"timeout" label:"超时时间单位:ms"`
SuccessCode int `json:"success_code" label:"成功状态码" minimum:"100" description:"最小值:100"`
Period int `json:"period" label:"检查频率" minimum:"1" default:"30" description:"单位:s,最小值:1"`
Timeout int `json:"timeout" label:"超时时间" label:"单位:ms"`
}
2 changes: 1 addition & 1 deletion drivers/output/httpoutput/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type Config struct {
Method string `json:"method" yaml:"method" enum:"GET,POST,PUT,DELETE,PATCH,HEAD,OPTIONS" label:"请求方式"`
Method string `json:"method" yaml:"method" enum:"GET,POST,PUT" label:"请求方式"`
Url string `json:"url" yaml:"url" format:"uri" label:"请求Url"`
Headers map[string]string `json:"headers" yaml:"headers" label:"请求头部"`
Type string `json:"type" yaml:"type" enum:"json,line" label:"输出格式"`
Expand Down
2 changes: 1 addition & 1 deletion drivers/plugins/access-log/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package access_log
import "github.com/eolinker/eosc"

type Config struct {
Output []eosc.RequireId `json:"output" skill:"github.com/eolinker/apinto/http-entry.http-entry.IOutput"`
Output []eosc.RequireId `json:"output" skill:"github.com/eolinker/apinto/http-entry.http-entry.IOutput" label:"输出器列表"`
}
2 changes: 1 addition & 1 deletion drivers/plugins/auth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package auth
import "github.com/eolinker/eosc"

type Config struct {
Auth []eosc.RequireId `json:"auth" skill:"github.com/eolinker/apinto/auth.auth.IAuth"`
Auth []eosc.RequireId `json:"auth" skill:"github.com/eolinker/apinto/auth.auth.IAuth" label:"用户列表"`
}
18 changes: 9 additions & 9 deletions drivers/plugins/circuit-breaker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package circuit_breaker
import "fmt"

type Config struct {
MatchCodes string `json:"match_codes"`
MonitorPeriod int `json:"monitor_period"`
MinimumRequests int `json:"minimum_requests"`
FailurePercent float64 `json:"failure_percent"`
BreakPeriod int64 `json:"break_period"`
SuccessCounts int `json:"success_counts"`
BreakerCode int `json:"breaker_code"`
Headers map[string]string `json:"headers"`
Body string `json:"body"`
MatchCodes string `json:"match_codes" label:"匹配状态码" description:"多个状态码之间使用英文逗号隔开"`
MonitorPeriod int `json:"monitor_period" label:"监控期" minimum:"1" description:"单位:秒,最小值:1"`
MinimumRequests int `json:"minimum_requests" label:"最低熔断阀值,达到熔断状态的最少请求次数" minimum:"1" description:"最小值:1"`
FailurePercent float64 `json:"failure_percent" label:"监控期内的请求错误率" minimum:"0" maximum:"1" description:"最小值:0,最大值:1"`
BreakPeriod int64 `json:"break_period" label:"熔断期" minimum:"1" description:"最小值:1"`
SuccessCounts int `json:"success_counts" label:"连续请求成功次数,半开放状态下请求成功次数达到后会转变成健康状态" minimum:"1" description:"最小值:1"`
BreakerCode int `json:"breaker_code" label:"熔断状态下返回的响应状态码" minimum:"100" description:"最小值:100"`
Headers map[string]string `json:"headers" label:"熔断状态下新增的返回头部值"`
Body string `json:"body" label:"熔断状态下的返回响应体"`
}

var (
Expand Down
16 changes: 6 additions & 10 deletions drivers/plugins/cors/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ var (
)

type Config struct {
AllowOrigins string `json:"allow_origins"`
AllowMethods string `json:"allow_methods"`
AllowCredentials bool `json:"allow_credentials"`
AllowHeaders string `json:"allow_headers"`
ExposeHeaders string `json:"expose_headers"`
MaxAge int32 `json:"max_age"`
ResponseType string `json:"response_type"`
AllowOrigins string `json:"allow_origins" label:"允许跨域访问的Origin" default:"*"`
AllowMethods string `json:"allow_methods" label:"允许通过的请求方式" default:"*" description:"多种请求方式用英文逗号隔开"`
AllowCredentials bool `json:"allow_credentials" label:"请求中是否携带cookie"`
AllowHeaders string `json:"allow_headers" label:"允许跨域访问时请求方携带的非CORS规范以外的Header" default:"*" description:"多种请求方式用英文逗号隔开"`
ExposeHeaders string `json:"expose_headers" label:"允许跨域访问时响应方携带的非CORS规范以外的Header" default:"*" description:"多种请求方式用英文逗号隔开"`
MaxAge int32 `json:"max_age" description:"浏览器缓存CORS结果的最大时间" description:"单位:s,最小值:1" default:"5" minimum:"1"`
}

func (c *Config) doCheck() error {
Expand All @@ -43,9 +42,6 @@ func (c *Config) doCheck() error {
if c.MaxAge == 0 {
c.MaxAge = 5
}
if c.ResponseType != "json" {
c.ResponseType = "text"
}
return nil
}

Expand Down
1 change: 0 additions & 1 deletion drivers/plugins/cors/cors.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func (c *CorsFilter) Reset(conf interface{}, workers map[eosc.RequireId]interfac
c.methodChecker = NewChecker(cfg.AllowMethods, "Access-Control-Allow-Methods")
c.headerChecker = NewChecker(cfg.AllowHeaders, "Access-Control-Allow-Headers")
c.exposeChecker = NewChecker(cfg.ExposeHeaders, "Access-Control-Expose-Headers")
c.responseType = cfg.ResponseType
c.allowCredentials = cfg.AllowCredentials
return nil
}
Expand Down
1 change: 0 additions & 1 deletion drivers/plugins/cors/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (d *Driver) Create(id, name string, v interface{}, workers map[eosc.Require
methodChecker: NewChecker(conf.AllowMethods, "Access-Control-Allow-Methods"),
headerChecker: NewChecker(conf.AllowHeaders, "Access-Control-Allow-Headers"),
exposeChecker: NewChecker(conf.ExposeHeaders, "Access-Control-Expose-Headers"),
responseType: conf.ResponseType,
allowCredentials: conf.AllowCredentials,
}
return c, nil
Expand Down
12 changes: 6 additions & 6 deletions drivers/plugins/extra-params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
)

type Config struct {
Params []*ExtraParam `json:"params"`
ErrorType string `json:"error_type"`
Params []*ExtraParam `json:"params" label:"参数列表"`
ErrorType string `json:"error_type" enum:"text,json" label:"报错输出格式" `
}

type ExtraParam struct {
Name string `json:"name"`
Position string `json:"position"`
Value interface{} `json:"value"`
Conflict string `json:"conflict"`
Name string `json:"name" label:"参数名"`
Position string `json:"position" enum:"header,query,body" label:"参数位置"`
Value interface{} `json:"value" label:"参数值"`
Conflict string `json:"conflict" label:"参数冲突时的处理方式" enum:"origin,convert,error"`
}

func (c *Config) doCheck() error {
Expand Down
6 changes: 3 additions & 3 deletions drivers/plugins/gzip/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ var (
)

type Config struct {
Types []string `json:"types"`
MinLength int `json:"min_length"`
Vary bool `json:"vary"`
Types []string `json:"types" label:"content-type列表" description:"需要压缩的响应content-type类型列表"`
MinLength int `json:"min_length" label:"长度" description:"待压缩内容的最小长度" `
Vary bool `json:"vary" label:"是否加上Vary头部"`
}

func (c *Config) doCheck() error {
Expand Down
15 changes: 6 additions & 9 deletions drivers/plugins/ip-restriction/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
)

var (
ErrorConfigTypeError = errors.New("unknown ip list type")
ErrorIpIllegal = errors.New("[ip_restriction] Illegal IP!")
ErrorConfigTypeError = errors.New("unknown ip list type")
ErrorIpIllegal = errors.New("[ip_restriction] Illegal IP!")
)

type Config struct {
IPListType string `json:"ip_list_type"`
IPWhiteList []string `json:"ip_white_list"`
IPBlackList []string `json:"ip_black_list"`
ResponseType string `json:"response_type"`
IPListType string `json:"ip_list_type" enum:"white,black" label:"列表类型"`
IPWhiteList []string `json:"ip_white_list" label:"ip白名单列表"`
IPBlackList []string `json:"ip_black_list" label:"ip黑名单列表"`
}

func (c *Config) doCheck() error {
Expand All @@ -26,7 +25,6 @@ func (c *Config) doCheck() error {
return ErrorConfigTypeError
}


type IPFilter func(ip string) (bool, error)

func (c *Config) genFilter() IPFilter {
Expand Down Expand Up @@ -114,7 +112,6 @@ func convertIP(ip string) (string, error) {
}
}


func ip2binary(ip string) string {
str := strings.Split(ip, ".")
var ipstr string
Expand All @@ -139,4 +136,4 @@ func match(ip, iprange string) bool {
}
iprb := ip2binary(ipr[0])
return strings.EqualFold(ipb[0:masklen], iprb[0:masklen])
}
}
7 changes: 3 additions & 4 deletions drivers/plugins/ip-restriction/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ func (d *Driver) Create(id, name string, v interface{}, workers map[eosc.Require
return nil, err
}
h := &IPHandler{
Driver: d,
id: id,
filter: conf.genFilter(),
responseType: conf.ResponseType,
Driver: d,
id: id,
filter: conf.genFilter(),
}
return h, nil
}
1 change: 0 additions & 1 deletion drivers/plugins/ip-restriction/restriction.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (I *IPHandler) Reset(conf interface{}, workers map[eosc.RequireId]interface
return err
}
I.filter = confObj.genFilter()
I.responseType = confObj.ResponseType
return nil
}

Expand Down
17 changes: 8 additions & 9 deletions drivers/plugins/params-transformer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import (
)

type Config struct {
Params []*TransParam `json:"params"`
Remove bool `json:"remove"`
ErrorType string `json:"error_type"`
Params []*TransParam `json:"params" label:"参数列表"`
Remove bool `json:"remove" label:"映射后删除原参数"`
ErrorType string `json:"error_type" enum:"text,json" label:"报错输出格式" `
}

type TransParam struct {
Name string `json:"name"`
Position string `json:"position"`
ProxyName string `json:"proxy_name"`
ProxyPosition string `json:"proxy_position"`
Required bool `json:"required"`
Conflict string `json:"conflict"`
Name string `json:"name" label:"待映射参数名称"`
Position string `json:"position" label:"待映射参数所在位置" enum:"header,query,body"`
ProxyName string `json:"proxy_name" label:"目标参数名称"`
ProxyPosition string `json:"proxy_position" label:"目标参数所在位置" enum:"header,query,body"`
Required bool `json:"required" label:"待映射参数是否必含"`
}

func (c *Config) doCheck() error {
Expand Down
10 changes: 5 additions & 5 deletions drivers/plugins/proxy-rewrite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package proxy_rewrite
import "fmt"

type Config struct {
Scheme string `json:"scheme"`
URI string `json:"uri"`
RegexURI []string `json:"regex_uri"`
Host string `json:"host"`
Headers map[string]string `json:"headers"`
Scheme string `json:"scheme" label:"协议"`
URI string `json:"uri" label:"URI"`
RegexURI []string `json:"regex_uri" label:"正则替换URI(regex_uri)"`
Host string `json:"host" label:"Host"`
Headers map[string]string `json:"headers" label:"请求头部"`
}

func (c *Config) doCheck() error {
Expand Down
14 changes: 6 additions & 8 deletions drivers/plugins/rate-limiting/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package rate_limiting

type Config struct {
Second int64 `json:"second,omitempty"` // 每秒请求次数限制
Minute int64 `json:"minute,omitempty"` // 每分钟请求次数限制
Hour int64 `json:"hour,omitempty"` // 每小时请求次数限制
Day int64 `json:"day,omitempty"` // 每天请求次数限制
HideClientHeader bool `json:"hideClientHeader"` // 请求结果是否隐藏流控信息
ResponseType string `json:"responseType"` // 插件返回报错的类型
Second int64 `json:"second,omitempty" label:"每秒请求次数限制"` // 每秒请求次数限制
Minute int64 `json:"minute,omitempty" label:"每分钟请求次数限制"` // 每分钟请求次数限制
Hour int64 `json:"hour,omitempty" label:"每小时请求次数限制"` // 每小时请求次数限制
Day int64 `json:"day,omitempty" label:"每天请求次数限制"` // 每天请求次数限制
HideClientHeader bool `json:"hide_client_header" label:"是否隐藏流控信息"` // 请求结果是否隐藏流控信息
ResponseType string `json:"response_type" label:"报错格式" enum:"text,json"` // 插件返回报错的类型
}


12 changes: 6 additions & 6 deletions drivers/plugins/response-rewrite/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package response_rewrite
import "fmt"

type Config struct {
StatusCode int `json:"status_code"`
Body string `json:"body"`
BodyBase64 bool `json:"body_base64"`
Headers map[string]string `json:"headers"`
Match *MatchConf `json:"match"`
StatusCode int `json:"status_code" label:"响应状态码" minimum:"100" description:"最小值:100"`
Body string `json:"body" label:"响应内容"`
BodyBase64 bool `json:"body_base64" label:"是否base64加密"`
Headers map[string]string `json:"headers" label:"响应头部"`
Match *MatchConf `json:"match" label:"匹配状态码列表"`
}

type MatchConf struct {
Code []int `json:"code"`
Code []int `json:"code" label:"状态码" minimum:"100" description:"最小值:100"`
}

var (
Expand Down
5 changes: 0 additions & 5 deletions drivers/plugins/rewrite/config.go

This file was deleted.

Loading

0 comments on commit cb16d54

Please sign in to comment.