Skip to content

Commit

Permalink
Prepare AuthPolicy type for the merge strategy
Browse files Browse the repository at this point in the history
* Structure of named patterns changed from `patterns: map[string][]PatternExpression` to `patterns: map[string]{allOf: []PatternExpression}`.
* `spec.response.success.dynamicMetadata` field renamed `spec.response.success.filters`, documented as meant for exporting data to other filters managed by Kuadrant only.

Signed-off-by: Guilherme Cassolato <[email protected]>
  • Loading branch information
guicassolato committed Oct 23, 2024
1 parent b771a77 commit 2670b85
Show file tree
Hide file tree
Showing 29 changed files with 1,633 additions and 3,398 deletions.
22 changes: 15 additions & 7 deletions api/v1/merge_strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,20 @@ const (
PolicyRuleMergeStrategy = "merge"
)

type MergeableRule struct {
Spec any
Source string
// NewMergeableRule creates a new MergeableRule with a default source if the rule does not have one.
func NewMergeableRule(rule MergeableRule, defaultSource string) MergeableRule {
if rule.GetSource() == "" {
return rule.WithSource(defaultSource)
}
return rule
}

// MergeableRule is a policy rule that contains a spec which can be traced back to its source,
// i.e. to the policy where the rule spec was defined.
type MergeableRule interface {
GetSpec() any
GetSource() string
WithSource(string) MergeableRule
}

// +kubebuilder:object:generate=false
Expand Down Expand Up @@ -99,10 +110,7 @@ func PolicyRuleDefaultsMergeStrategy(source, target machinery.Policy) machinery.
// add extra rules from the source
for ruleID, rule := range sourceMergeablePolicy.Rules() {
if _, ok := targetMergeablePolicy.Rules()[ruleID]; !ok {
rules[ruleID] = MergeableRule{
Spec: rule.Spec,
Source: source.GetLocator(),
}
rules[ruleID] = rule.WithSource(source.GetLocator())
}
}

Expand Down
Loading

0 comments on commit 2670b85

Please sign in to comment.