Publish inspection through one frozen history model
This commit is contained in:
@@ -82,7 +82,6 @@ func resolveLoadInput[T any](schema *schemaDescriptor, definition Definition[T],
|
||||
}
|
||||
if builder != nil {
|
||||
builder.model.final = final
|
||||
builder.registerDocumentRoot(final)
|
||||
}
|
||||
if refreshReferenceInput {
|
||||
referenceInput = documentWithMetadataLocations(final, metadata, input.document)
|
||||
@@ -120,44 +119,24 @@ func prepareInspectionHistory[T any](resolved resolvedLoad[T], counter *retained
|
||||
metadata := resolved.metadata
|
||||
if resolved.historyBuilder != nil {
|
||||
metadata.historyBuilder = resolved.historyBuilder
|
||||
} else if resolved.inheritance != nil {
|
||||
builder := newHistoryBuilder()
|
||||
if resolved.decoded.baseline != nil {
|
||||
builder.observeBaseline(resolved.decoded.baseline)
|
||||
}
|
||||
builder.setScratch(resolved.final)
|
||||
builder.observeInheritanceEvidence(resolved.inheritance.operations)
|
||||
metadata.historyBuilder = builder
|
||||
}
|
||||
metadata.inheritance = nil
|
||||
finalizeMetadataPathsWithResolution(
|
||||
&metadata, resolved.final, resolved.applications, resolved.snapshots,
|
||||
resolved.decoded.baseline, resolved.structuralInput, resolved.preCLI, resolved.decoded.final,
|
||||
)
|
||||
model := metadata.historyModel
|
||||
inspection := &Inspection{
|
||||
metadata: metadata,
|
||||
baseline: resolved.decoded.baseline,
|
||||
input: resolved.decoded.final,
|
||||
inputOrigins: cloneOriginIndex(resolved.decoded.origins),
|
||||
preCLI: resolved.preCLI,
|
||||
preCLIOrigins: cloneOrigins(resolved.preCLIOrigins),
|
||||
final: resolved.final,
|
||||
resolution: resolved.snapshots,
|
||||
resolutionReplay: coalescedResolutionSnapshots(resolved.snapshots),
|
||||
}
|
||||
if !addInspectionHistory(counter, inspection) {
|
||||
return nil, false
|
||||
}
|
||||
var ok bool
|
||||
inspection.applications, ok = cloneHistoryApplicationsWithinLimit(resolved.applications, counter)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
inspection.postDecodeApps, ok = cloneHistoryApplicationsWithinLimit(resolved.postDecodeApps, counter)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
if resolved.inheritance != nil {
|
||||
roots := inheritanceOperationDocumentRoots(resolved.inheritance.operations)
|
||||
if !counter.canAddClones(roots, 2) {
|
||||
return nil, false
|
||||
}
|
||||
inspection.metadata.inheritance = cloneInheritanceOperations(resolved.inheritance.operations)
|
||||
if !addInheritanceOperationDocuments(counter, inspection.metadata.inheritance) {
|
||||
return nil, false
|
||||
}
|
||||
inspection.inheritance = cloneInheritanceOperations(resolved.inheritance.operations)
|
||||
if !addInheritanceOperationDocuments(counter, inspection.inheritance) {
|
||||
return nil, false
|
||||
}
|
||||
metadata: metadata,
|
||||
history: model,
|
||||
final: resolved.final,
|
||||
}
|
||||
if !addInspectionHistory(counter, inspection) {
|
||||
return nil, false
|
||||
@@ -165,33 +144,7 @@ func prepareInspectionHistory[T any](resolved resolvedLoad[T], counter *retained
|
||||
return inspection, true
|
||||
}
|
||||
|
||||
func cloneHistoryApplicationsWithinLimit(values []historyApplication, counter *retainedNodeCounter) ([]historyApplication, bool) {
|
||||
for _, value := range values {
|
||||
if !counter.add(value.value) {
|
||||
return nil, false
|
||||
}
|
||||
}
|
||||
return cloneHistoryApplications(values), true
|
||||
}
|
||||
|
||||
func inheritanceOperationDocumentRoots(operations []inheritanceOperation) []*document.Node {
|
||||
roots := make([]*document.Node, 0, len(operations)*2)
|
||||
for _, operation := range operations {
|
||||
roots = append(roots, operation.parent, operation.effective)
|
||||
}
|
||||
return roots
|
||||
}
|
||||
|
||||
func addInheritanceOperationDocuments(counter *retainedNodeCounter, operations []inheritanceOperation) bool {
|
||||
for _, operation := range operations {
|
||||
if !counter.add(operation.parent) || !counter.add(operation.effective) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func publishLoadResult[T any](schema *schemaDescriptor, definition Definition[T], resolved resolvedLoad[T], inspection *Inspection, applications []historyApplication, references map[string]string, accumulator *diagnosticAccumulator) (*Loaded[T], error) {
|
||||
func publishLoadResult[T any](schema *schemaDescriptor, definition Definition[T], resolved resolvedLoad[T], inspection *Inspection, references map[string]string, accumulator *diagnosticAccumulator) (*Loaded[T], error) {
|
||||
// A read-only validator can replace a value with an equal borrowed object.
|
||||
// Detach without re-reading the environment or discarding validated state.
|
||||
configuration, issue := detachLoadConfiguration(schema, resolved.configuration, cloneValidatedSecrets)
|
||||
@@ -199,21 +152,13 @@ func publishLoadResult[T any](schema *schemaDescriptor, definition Definition[T]
|
||||
accumulator.add(*issue)
|
||||
return nil, accumulator.loadError()
|
||||
}
|
||||
decoded := resolved.decoded
|
||||
metadata, final, preCLI := inspection.metadata, inspection.final, inspection.preCLI
|
||||
finalizeMetadataPathsWithResolution(&metadata, final, applications, resolved.snapshots, decoded.baseline, resolved.structuralInput, resolved.preCLI, decoded.final)
|
||||
secrets := classifySecretPathsWithEvidence(schema, definition.Secret, metadata, final, applications, resolved.versionEvidence, decoded.baseline, resolved.structuralInput, resolved.preCLI, decoded.final)
|
||||
metadata, final := inspection.metadata, inspection.final
|
||||
secrets := classifySecretPathsWithEvidence(schema, definition.Secret, metadata, final, nil, resolved.versionEvidence)
|
||||
sources := sourceInfosWithVersionEvidence(accumulator.sources, resolved.versionEvidence, secrets, false)
|
||||
retainedTrees := make([]*document.Node, 0, len(applications)+4)
|
||||
retainedTrees = append(retainedTrees, decoded.final, final, preCLI)
|
||||
for _, application := range applications {
|
||||
retainedTrees = append(retainedTrees, application.value)
|
||||
}
|
||||
inspection.metadata = metadata
|
||||
inspection.sources = sources
|
||||
inspection.contexts = cloneResourceContexts(resolved.contexts)
|
||||
inspection.diagnostics = canonicalDiagnostics(accumulator.diagnostics)
|
||||
inspection.immutableLookup = buildDocumentLookup(retainedTrees...)
|
||||
inspection.secrets = secrets
|
||||
inspection.secretReferences = cloneSecretReferences(references)
|
||||
return &Loaded[T]{Config: configuration, Inspection: inspection}, nil
|
||||
|
||||
Reference in New Issue
Block a user