feat(wasm-plugin): add tests and docs for hmac-auth-apisix (#2842)

This commit is contained in:
韩贤涛
2025-09-01 14:07:57 +08:00
committed by GitHub
parent fff5903007
commit 7e74eeb333
9 changed files with 1769 additions and 46 deletions

View File

@@ -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))
}