Borrow lower collection policies during strict composition
This commit is contained in:
@@ -7,6 +7,23 @@ import "gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
||||
// operation at that exact path.
|
||||
type collectionReplacementPaths map[string]bool
|
||||
|
||||
type lowerCollectionPolicyView struct {
|
||||
scope collectionPolicyScope
|
||||
replacements collectionReplacementPaths
|
||||
}
|
||||
|
||||
func (view lowerCollectionPolicyView) at(path Path) (collectionPolicy, bool) {
|
||||
entry, found := view.scope.collections[path.String()]
|
||||
if !found {
|
||||
return collectionPolicy{}, false
|
||||
}
|
||||
policy := entry.policy
|
||||
if view.replacements.contains(path, true) {
|
||||
clearCollectionIdentity(&policy)
|
||||
}
|
||||
return policy, true
|
||||
}
|
||||
|
||||
func (paths collectionReplacementPaths) contains(path Path, includeExact bool) bool {
|
||||
for length := 0; length <= len(path.segments); length++ {
|
||||
prefix := Path{segments: path.segments[:length]}
|
||||
@@ -27,6 +44,26 @@ func lowerCollectionPoliciesForClaims(
|
||||
declarations map[string][]sequenceDeclarationSpec,
|
||||
application sequencePolicy,
|
||||
) (collectionPolicyScope, collectionReplacementPaths) {
|
||||
replaced := collectionReplacementPathsForClaims(lower, claims, declarations, application)
|
||||
// This materialization is used when inheritance creates an independently
|
||||
// owned local scope. Strict tier resolution uses lowerCollectionPolicyView
|
||||
// instead and keeps only its sparse current-scope result.
|
||||
result := cloneCollectionPolicyScope(lower)
|
||||
for key, entry := range result.collections {
|
||||
if replaced.contains(entry.destination, true) {
|
||||
clearCollectionIdentity(&entry.policy)
|
||||
result.collections[key] = entry
|
||||
}
|
||||
}
|
||||
return result, replaced
|
||||
}
|
||||
|
||||
func collectionReplacementPathsForClaims(
|
||||
lower collectionPolicyScope,
|
||||
claims []compositionClaim,
|
||||
declarations map[string][]sequenceDeclarationSpec,
|
||||
application sequencePolicy,
|
||||
) collectionReplacementPaths {
|
||||
byPath := make(map[string]compositionClaim, len(claims))
|
||||
rootPath := ""
|
||||
if len(claims) != 0 {
|
||||
@@ -62,14 +99,7 @@ func lowerCollectionPoliciesForClaims(
|
||||
replaced[key] = false
|
||||
}
|
||||
}
|
||||
result := cloneCollectionPolicyScope(lower)
|
||||
for key, entry := range result.collections {
|
||||
if replaced.contains(entry.destination, true) {
|
||||
clearCollectionIdentity(&entry.policy)
|
||||
result.collections[key] = entry
|
||||
}
|
||||
}
|
||||
return result, replaced
|
||||
return replaced
|
||||
}
|
||||
|
||||
func clearCollectionIdentity(policy *collectionPolicy) {
|
||||
|
||||
Reference in New Issue
Block a user