Add local publication attempt discovery
This commit is contained in:
37
recovery.go
37
recovery.go
@@ -78,6 +78,37 @@ func LoadPublicationEvidence(path string) (PublicationEvidence, error) {
|
||||
return publicEvidence(evidence), publicRecoveryError(err, path)
|
||||
}
|
||||
|
||||
type PublicationAttemptsRequest struct {
|
||||
RepositoryDir string
|
||||
RecordDir string
|
||||
}
|
||||
type PublicationAttempt struct {
|
||||
RecordPath string
|
||||
Evidence PublicationEvidence
|
||||
}
|
||||
type PublicationAttemptsResult struct {
|
||||
RecordDir string
|
||||
Attempts []PublicationAttempt
|
||||
Diagnostics []*PublicationRecoveryError
|
||||
}
|
||||
|
||||
// ListPublicationAttempts discovers saved local records without querying a
|
||||
// remote or inferring which attempt should be reconciled.
|
||||
func ListPublicationAttempts(ctx context.Context, request PublicationAttemptsRequest) (PublicationAttemptsResult, error) {
|
||||
listed, err := publish.ListAttempts(ctx, request.RepositoryDir, request.RecordDir)
|
||||
result := PublicationAttemptsResult{RecordDir: listed.RecordDir, Attempts: make([]PublicationAttempt, 0, len(listed.Attempts)), Diagnostics: make([]*PublicationRecoveryError, 0, len(listed.Diagnostics))}
|
||||
for _, attempt := range listed.Attempts {
|
||||
result.Attempts = append(result.Attempts, PublicationAttempt{RecordPath: attempt.RecordPath, Evidence: publicEvidence(attempt.Evidence)})
|
||||
}
|
||||
for _, diagnostic := range listed.Diagnostics {
|
||||
converted := publicRecoveryError(diagnostic, diagnostic.RecordPath)
|
||||
if recovery, ok := converted.(*PublicationRecoveryError); ok {
|
||||
result.Diagnostics = append(result.Diagnostics, recovery)
|
||||
}
|
||||
}
|
||||
return result, publicRecoveryError(err, "")
|
||||
}
|
||||
|
||||
func internalEvidence(e PublicationEvidence) publish.Evidence { return publish.Evidence(e) }
|
||||
func publicEvidence(e publish.Evidence) PublicationEvidence { return PublicationEvidence(e) }
|
||||
func publicObservation(o publish.Observation) PublicationReconciliationResult {
|
||||
@@ -90,7 +121,11 @@ func publicRecoveryError(err error, path string) error {
|
||||
}
|
||||
var recovery *publish.RecoveryError
|
||||
if errors.As(err, &recovery) {
|
||||
return &PublicationRecoveryError{Kind: recovery.Kind, RecordPath: path, MissingFields: append([]string(nil), recovery.MissingFields...), cause: recovery}
|
||||
recordPath := path
|
||||
if recordPath == "" {
|
||||
recordPath = recovery.RecordPath
|
||||
}
|
||||
return &PublicationRecoveryError{Kind: recovery.Kind, RecordPath: recordPath, MissingFields: append([]string(nil), recovery.MissingFields...), cause: recovery}
|
||||
}
|
||||
return &PublicationRecoveryError{Kind: "remote_observation", RecordPath: path, cause: err}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user