192 lines
6.8 KiB
Go
192 lines
6.8 KiB
Go
package configkit
|
|
|
|
import "gitea.maximumdirect.net/eric/ConfigKit/internal/engine"
|
|
|
|
func fromEngineLocation(value engine.Location) Location {
|
|
return Location{SourceID: value.SourceID, Line: value.Line, Column: value.Column}
|
|
}
|
|
func toEngineLocation(value Location) engine.Location {
|
|
return engine.Location{SourceID: value.SourceID, Line: value.Line, Column: value.Column}
|
|
}
|
|
func fromEngineLocationPointer(value *engine.Location) *Location {
|
|
if value == nil {
|
|
return nil
|
|
}
|
|
result := fromEngineLocation(*value)
|
|
return &result
|
|
}
|
|
func toEngineLocationPointer(value *Location) *engine.Location {
|
|
if value == nil {
|
|
return nil
|
|
}
|
|
result := toEngineLocation(*value)
|
|
return &result
|
|
}
|
|
func fromEngineLocations(values []engine.Location) []Location {
|
|
if values == nil {
|
|
return nil
|
|
}
|
|
result := make([]Location, len(values))
|
|
for i := range values {
|
|
result[i] = fromEngineLocation(values[i])
|
|
}
|
|
return result
|
|
}
|
|
func toEngineLocations(values []Location) []engine.Location {
|
|
if values == nil {
|
|
return nil
|
|
}
|
|
result := make([]engine.Location, len(values))
|
|
for i := range values {
|
|
result[i] = toEngineLocation(values[i])
|
|
}
|
|
return result
|
|
}
|
|
func fromEngineSourceInfo(value engine.SourceInfo) SourceInfo {
|
|
return SourceInfo{
|
|
ID: value.ID, Label: value.Label, Path: value.Path, Destination: fromEnginePath(value.Destination),
|
|
PlacementMode: PlacementMode(engine.SourceInfoPlacementModeForFacade(value)),
|
|
DestinationUnresolved: engine.SourceInfoDestinationUnresolvedForFacade(value),
|
|
Layer: Layer(value.Layer), Kind: SourceKind(value.Kind), UnderlayIndex: value.UnderlayIndex,
|
|
ImportedFrom: fromEngineLocationPointer(value.ImportedFrom), VersionCheck: fromEngineSourceVersionCheck(value.VersionCheck),
|
|
ImportSelections: fromEngineImportSelections(engine.SourceInfoImportSelectionsForFacade(value)),
|
|
}
|
|
}
|
|
func fromEngineImportSelections(values []engine.ImportSelectionForFacade) []ImportSelection {
|
|
if values == nil {
|
|
return nil
|
|
}
|
|
result := make([]ImportSelection, len(values))
|
|
for index, value := range values {
|
|
result[index] = ImportSelection{
|
|
Path: fromEnginePath(value.Path), Location: fromEngineLocation(value.Location),
|
|
Selector: ImportSelector(value.Selector), Outcome: ImportSelectionOutcome(value.Outcome),
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func toEngineOverrides(values []Override) []engine.Override {
|
|
if values == nil {
|
|
return nil
|
|
}
|
|
result := make([]engine.Override, len(values))
|
|
for index, value := range values {
|
|
result[index] = engine.Override{
|
|
Path: toEnginePath(value.Path), Value: value.Value, Flag: value.Flag,
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func toEngineImportDefaults(value ImportDefaults) engine.ImportDefaults {
|
|
return engine.ImportDefaults{
|
|
Required: value.Required,
|
|
Follow: value.Follow,
|
|
Hidden: value.Hidden,
|
|
Recursive: value.Recursive,
|
|
Pattern: value.Pattern,
|
|
}
|
|
}
|
|
|
|
func fromEngineSourceVersionCheck(value *engine.SourceVersionCheck) *SourceVersionCheck {
|
|
if value == nil {
|
|
return nil
|
|
}
|
|
return &SourceVersionCheck{
|
|
Path: fromEnginePath(value.Path),
|
|
Version: Version{Present: value.Version.Present, Null: value.Version.Null, Text: value.Version.Text},
|
|
Location: fromEngineLocationPointer(value.Location), Redacted: value.Redacted,
|
|
}
|
|
}
|
|
func fromEngineOrigin(value engine.Origin) Origin {
|
|
result := Origin{Layer: Layer(value.Layer), Locations: fromEngineLocations(value.Locations), Operation: ChangeKind(value.Operation)}
|
|
if value.Inheritance != nil {
|
|
result.Inheritance = make([]InheritanceStep, len(value.Inheritance))
|
|
for index, step := range value.Inheritance {
|
|
result.Inheritance[index] = InheritanceStep{
|
|
From: fromEnginePath(step.From), To: fromEnginePath(step.To), Reference: fromEnginePath(step.Reference),
|
|
Locations: fromEngineLocations(step.Locations),
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
func fromEngineDiagnostic(value engine.Diagnostic) Diagnostic {
|
|
return Diagnostic{Code: Code(value.Code), Severity: Severity(value.Severity), Path: fromEnginePath(value.Path), Message: value.Message, Primary: fromEngineLocationPointer(value.Primary), Related: fromEngineLocations(value.Related)}
|
|
}
|
|
func toEngineDiagnostic(value Diagnostic) engine.Diagnostic {
|
|
return engine.Diagnostic{Code: engine.Code(value.Code), Severity: engine.Severity(value.Severity), Path: toEnginePath(value.Path), Message: value.Message, Primary: toEngineLocationPointer(value.Primary), Related: toEngineLocations(value.Related)}
|
|
}
|
|
func toEngineDiagnostics(values []Diagnostic) []engine.Diagnostic {
|
|
if values == nil {
|
|
return nil
|
|
}
|
|
result := make([]engine.Diagnostic, len(values))
|
|
for i := range values {
|
|
result[i] = toEngineDiagnostic(values[i])
|
|
}
|
|
return result
|
|
}
|
|
func fromEngineFieldInfo(value engine.FieldInfo) FieldInfo {
|
|
return FieldInfo{Explicit: value.Explicit, Null: value.Null, Origin: fromEngineOrigin(value.Origin)}
|
|
}
|
|
func fromEngineChange(value engine.Change) Change {
|
|
result := Change{Path: fromEnginePath(value.Path), Origin: fromEngineOrigin(value.Origin), Reasons: append([]string(nil), value.Reasons...)}
|
|
if value.Previous != nil {
|
|
result.Previous = make([]Origin, len(value.Previous))
|
|
for i := range value.Previous {
|
|
result.Previous[i] = fromEngineOrigin(value.Previous[i])
|
|
}
|
|
}
|
|
if value.Dependencies != nil {
|
|
result.Dependencies = make([]Path, len(value.Dependencies))
|
|
for i := range value.Dependencies {
|
|
result.Dependencies[i] = fromEnginePath(value.Dependencies[i])
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func fromEngineValueSnapshot(value engine.ValueSnapshot) ValueSnapshot {
|
|
return ValueSnapshot{Present: value.Present, Redacted: value.Redacted, YAML: value.YAML}
|
|
}
|
|
|
|
func fromEngineValueChange(value engine.ValueChange) ValueChange {
|
|
result := ValueChange{
|
|
Before: fromEngineValueSnapshot(value.Before),
|
|
After: fromEngineValueSnapshot(value.After),
|
|
Origin: fromEngineOrigin(value.Origin),
|
|
Reasons: append([]string(nil), value.Reasons...),
|
|
}
|
|
if value.Dependencies != nil {
|
|
result.Dependencies = make([]Path, len(value.Dependencies))
|
|
for index := range value.Dependencies {
|
|
result.Dependencies[index] = fromEnginePath(value.Dependencies[index])
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func fromEngineExplanation(value engine.Explanation) Explanation {
|
|
result := Explanation{
|
|
Path: fromEnginePath(value.Path),
|
|
Effective: fromEngineValueSnapshot(value.Effective),
|
|
Origin: fromEngineOrigin(value.Origin),
|
|
}
|
|
if value.History != nil {
|
|
result.History = make([]ValueChange, len(value.History))
|
|
for index := range value.History {
|
|
result.History[index] = fromEngineValueChange(value.History[index])
|
|
}
|
|
}
|
|
if value.SecretReference != nil {
|
|
result.SecretReference = &SecretReferenceInfo{Name: value.SecretReference.Name}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func fromEngineSecretFileResult(value engine.SecretFileResult) SecretFileResult {
|
|
return SecretFileResult{Name: value.Name, Path: value.Path, Status: SecretFileStatus(value.Status), ExistingEmpty: value.ExistingEmpty}
|
|
}
|