mirror of
https://github.com/alibaba/higress.git
synced 2026-05-27 22:27:29 +08:00
feat(wasm-plugin): add tests and docs for hmac-auth-apisix (#2842)
This commit is contained in:
@@ -8,19 +8,15 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
var (
|
||||
// RuleSet 插件是否至少在一个 domain 或 route 上生效
|
||||
RuleSet bool
|
||||
// allowed_algorithms 配置中允许的算法
|
||||
validAlgorithms = map[string]bool{
|
||||
"hmac-sha1": true,
|
||||
"hmac-sha256": true,
|
||||
"hmac-sha512": true,
|
||||
}
|
||||
)
|
||||
// validAlgorithms allowed_algorithms 配置中允许的算法
|
||||
var validAlgorithms = map[string]bool{
|
||||
"hmac-sha1": true,
|
||||
"hmac-sha256": true,
|
||||
"hmac-sha512": true,
|
||||
}
|
||||
|
||||
type HmacAuthConfig struct {
|
||||
Consumers []Consumer `json:"consumers,omitempty" yaml:"consumers,omitempty"`
|
||||
Consumers []Consumer `json:"consumers" yaml:"consumers"`
|
||||
GlobalAuth *bool `json:"global_auth,omitempty" yaml:"global_auth,omitempty"`
|
||||
AllowedAlgorithms []string `json:"allowed_algorithms,omitempty" yaml:"allowed_algorithms,omitempty"`
|
||||
ClockSkew int `json:"clock_skew,omitempty" yaml:"clock_skew,omitempty"`
|
||||
@@ -28,7 +24,9 @@ type HmacAuthConfig struct {
|
||||
ValidateRequestBody bool `json:"validate_request_body,omitempty" yaml:"validate_request_body,omitempty"`
|
||||
HideCredentials bool `json:"hide_credentials,omitempty" yaml:"hide_credentials,omitempty"`
|
||||
AnonymousConsumer string `json:"anonymous_consumer,omitempty" yaml:"anonymous_consumer,omitempty"`
|
||||
Allow []string `json:"allow" yaml:"allow"`
|
||||
Allow []string `json:"allow,omitempty" yaml:"allow,omitempty"`
|
||||
// RuleSet 插件是否至少在一个 domain 或 route 上生效
|
||||
RuleSet bool `json:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
type Consumer struct {
|
||||
@@ -39,7 +37,7 @@ type Consumer struct {
|
||||
|
||||
func ParseGlobalConfig(jsonData gjson.Result, global *HmacAuthConfig) error {
|
||||
log.Debug("global config")
|
||||
RuleSet = false
|
||||
global.RuleSet = false
|
||||
|
||||
// 处理 consumers 配置
|
||||
consumers := jsonData.Get("consumers")
|
||||
@@ -170,7 +168,7 @@ func ParseOverrideRuleConfig(jsonData gjson.Result, global HmacAuthConfig, confi
|
||||
}
|
||||
}
|
||||
|
||||
RuleSet = true
|
||||
config.RuleSet = true
|
||||
if configBytes, err := json.Marshal(config); err == nil {
|
||||
log.Debugf("config: %s", string(configBytes))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user