89 lines
3.9 KiB
Go
89 lines
3.9 KiB
Go
package engine
|
|
|
|
import "gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
|
|
|
type preparedInheritanceChild struct {
|
|
payload *document.Node
|
|
origins map[string]Origin
|
|
policyTemplates collectionPolicyScope
|
|
control *inheritanceControl
|
|
controlOrigin Origin
|
|
}
|
|
|
|
type preparedInheritanceParent struct {
|
|
payload *document.Node
|
|
historyParent *document.Node
|
|
policyTemplates []collectionPolicyScope
|
|
effectivePolicyTemplates []collectionPolicyScope
|
|
parentPolicyScope collectionPolicyScope
|
|
childPolicyScope collectionPolicyScope
|
|
replaced collectionReplacementPaths
|
|
transfer inheritanceTransfer
|
|
}
|
|
|
|
func prepareInheritanceChild(template inheritanceExecutionTemplate, inputOrigins map[string]Origin) preparedInheritanceChild {
|
|
policyTemplates := cloneCollectionPolicyScopeForInheritance(template.collectionPolicies)
|
|
payload := withoutInheritanceDirective(template.entry.Value)
|
|
prepared := preparedInheritanceChild{
|
|
payload: payload, origins: directInheritanceOrigins(payload, template.path, inputOrigins),
|
|
policyTemplates: policyTemplates,
|
|
}
|
|
if template.hasDirective {
|
|
control := inheritanceControl{
|
|
path: template.directivePath, locations: []Location{publicLocation(template.directive.Value.Location)},
|
|
cancelled: template.cancelled,
|
|
}
|
|
controlOrigins := directInheritanceOrigins(template.directive.Value, control.path, inputOrigins)
|
|
prepared.control = &control
|
|
prepared.controlOrigin = controlOrigins[control.path.String()]
|
|
}
|
|
return prepared
|
|
}
|
|
|
|
func prepareInheritanceParent(
|
|
template inheritanceExecutionTemplate,
|
|
parentPath Path,
|
|
parent *document.Node,
|
|
resolvedParentPolicyTemplates []collectionPolicyScope,
|
|
resolvedParentPolicies collectionPolicyScope,
|
|
child preparedInheritanceChild,
|
|
applicationPolicy sequencePolicy,
|
|
) preparedInheritanceParent {
|
|
parentPolicies := cloneInheritancePolicyTemplates(resolvedParentPolicyTemplates)
|
|
effectivePolicies := append(
|
|
cloneInheritancePolicyTemplates(parentPolicies),
|
|
cloneCollectionPolicyScopeForInheritance(child.policyTemplates),
|
|
)
|
|
parentPolicyScope := projectInheritanceCollectionPolicies(resolvedParentPolicies, template.path)
|
|
childPolicyScope := projectCurrentInheritanceCollectionPolicies(child.policyTemplates, template.path)
|
|
var replaced collectionReplacementPaths
|
|
if len(parentPolicyScope.collections) != 0 || len(childPolicyScope.collections) != 0 {
|
|
claims := compositionClaims{byPath: make(map[string][]compositionClaim)}
|
|
claims.append(child.payload, template.path, 0)
|
|
declarations := make(map[string][]sequenceDeclarationSpec, len(childPolicyScope.collections))
|
|
for key, entry := range childPolicyScope.collections {
|
|
declarations[key] = inheritanceDeclarationsAt(entry.destination, entry.policy)
|
|
}
|
|
parentPolicyScope, replaced = lowerCollectionPoliciesForClaims(parentPolicyScope, claims.ordered, declarations, applicationPolicy)
|
|
}
|
|
parentPayload := inheritanceParentPayload(parent, template.identityFields)
|
|
historyParent := parent
|
|
if len(template.identityFields) != 0 {
|
|
// The retained parent snapshot is the inherited payload, before child
|
|
// fields are applied, with parent identity excluded.
|
|
historyParent = document.Clone(parentPayload)
|
|
}
|
|
transfer := inheritanceTransfer{
|
|
from: parentPath, to: template.path, reference: template.directivePath,
|
|
locations: []Location{publicLocation(template.directive.Value.Location)},
|
|
policyTemplates: parentPolicies, templatePolicies: cloneCollectionPolicyScopeForInheritance(child.policyTemplates),
|
|
projectedPolicies: projectInheritancePolicyTemplates([]collectionPolicyScope{resolvedParentPolicies}, template.path),
|
|
}
|
|
return preparedInheritanceParent{
|
|
payload: parentPayload, historyParent: historyParent,
|
|
policyTemplates: parentPolicies, effectivePolicyTemplates: effectivePolicies,
|
|
parentPolicyScope: parentPolicyScope, childPolicyScope: childPolicyScope,
|
|
replaced: replaced, transfer: transfer,
|
|
}
|
|
}
|