mirror of
https://github.com/coredns/coredns.git
synced 2026-10-24 19:25:43 -04:00
plugin/rewrite: support opt-in metadata in regex name replacements (#8665)
* plugin/rewrite: support opt-in metadata in regex name replacements Signed-off-by: houyuwushang <180804215+houyuwushang@users.noreply.github.com> * test: separate CoreDNS and third-party imports Signed-off-by: houyuwushang <180804215+houyuwushang@users.noreply.github.com> --------- Signed-off-by: houyuwushang <180804215+houyuwushang@users.noreply.github.com>
This commit is contained in:
@@ -336,8 +336,16 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
|
||||
var err error
|
||||
var answers ResponseRules
|
||||
auto := false
|
||||
if len(args) > 3 {
|
||||
auto, answers, err = parseAnswerRules(matchType, args[3:])
|
||||
answerStart := 3
|
||||
withMetadata := len(args) > 3 && args[3] == "metadata"
|
||||
if withMetadata {
|
||||
if matchType != RegexMatch {
|
||||
return nil, fmt.Errorf("metadata is only supported for regex name rules")
|
||||
}
|
||||
answerStart++
|
||||
}
|
||||
if len(args) > answerStart {
|
||||
auto, answers, err = parseAnswerRules(matchType, args[answerStart:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -356,6 +364,9 @@ func newNameRule(nextAction string, args ...string) (Rule, error) {
|
||||
case SubstringMatch:
|
||||
return newSubstringNameRule(nextAction, auto, rewriteQuestionFrom, rewriteQuestionTo, answers), nil
|
||||
case RegexMatch:
|
||||
if withMetadata {
|
||||
return newMetadataNameRule(nextAction, auto, rewriteQuestionFrom, rewriteQuestionTo, answers)
|
||||
}
|
||||
rewriteQuestionFromPattern, err := isValidRegexPattern(rewriteQuestionFrom, rewriteQuestionTo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user