Require committed remote current state
This commit is contained in:
@@ -11,37 +11,23 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCurrentRunPointerMissing = errors.New("current run pointer missing")
|
||||
ErrCurrentManifestMissing = errors.New("current manifest missing")
|
||||
ErrCurrentCommitPointerMissing = errors.New("current commit pointer missing")
|
||||
)
|
||||
|
||||
type CurrentRunPointerMissingError struct {
|
||||
type CurrentCommitPointerMissingError struct {
|
||||
Key string
|
||||
}
|
||||
|
||||
func (e *CurrentRunPointerMissingError) Error() string {
|
||||
return fmt.Sprintf("%s: %q", ErrCurrentRunPointerMissing, e.Key)
|
||||
func (e *CurrentCommitPointerMissingError) Error() string {
|
||||
return fmt.Sprintf("%s: %q; republish this session to establish committed remote state", ErrCurrentCommitPointerMissing, e.Key)
|
||||
}
|
||||
|
||||
func (e *CurrentRunPointerMissingError) Unwrap() error {
|
||||
return ErrCurrentRunPointerMissing
|
||||
}
|
||||
|
||||
type CurrentManifestMissingError struct {
|
||||
Key string
|
||||
}
|
||||
|
||||
func (e *CurrentManifestMissingError) Error() string {
|
||||
return fmt.Sprintf("%s: %q", ErrCurrentManifestMissing, e.Key)
|
||||
}
|
||||
|
||||
func (e *CurrentManifestMissingError) Unwrap() error {
|
||||
return ErrCurrentManifestMissing
|
||||
func (e *CurrentCommitPointerMissingError) Unwrap() error {
|
||||
return ErrCurrentCommitPointerMissing
|
||||
}
|
||||
|
||||
type CurrentState struct {
|
||||
SessionPrefix string
|
||||
CurrentRunIDKey string
|
||||
CurrentManifestKey string
|
||||
CurrentPointerKey string
|
||||
RunID string
|
||||
@@ -77,10 +63,10 @@ func LoadCurrentState(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("check current commit pointer %q: %w", pointerKey, err)
|
||||
}
|
||||
if pointerExists {
|
||||
return loadCommittedCurrentState(ctx, store, prefix, pointerKey, validation)
|
||||
if !pointerExists {
|
||||
return nil, &CurrentCommitPointerMissingError{Key: pointerKey}
|
||||
}
|
||||
return loadLegacyCurrentState(ctx, store, prefix, validation)
|
||||
return loadCommittedCurrentState(ctx, store, prefix, pointerKey, validation)
|
||||
}
|
||||
|
||||
func ValidateCurrentStateIdentity(state *CurrentState, validation CurrentStateValidation) error {
|
||||
@@ -95,12 +81,12 @@ func ValidateCurrentStateIdentity(state *CurrentState, validation CurrentStateVa
|
||||
manifestRunID := strings.TrimSpace(state.Manifest.RunID)
|
||||
if manifestCampaign != "" {
|
||||
if err := ValidateSessionIdentity(manifestCampaign, manifestSessionID); err != nil {
|
||||
return fmt.Errorf("current manifest contains unsafe legacy identities; migrate remote state before use: %w", err)
|
||||
return fmt.Errorf("current manifest contains unsafe identities: %w", err)
|
||||
}
|
||||
}
|
||||
if manifestRunID != "" {
|
||||
if err := ValidateRunIdentity(manifestRunID); err != nil {
|
||||
return fmt.Errorf("current manifest contains an unsafe legacy run id; migrate remote state before use: %w", err)
|
||||
return fmt.Errorf("current manifest contains an unsafe run id: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +119,7 @@ func ValidateCurrentStateIdentity(state *CurrentState, validation CurrentStateVa
|
||||
if manifestRunID != expectedRunID {
|
||||
return fmt.Errorf(
|
||||
"current run pointer %q references run %q but current manifest run_id is %q",
|
||||
state.CurrentRunIDKey,
|
||||
state.CurrentPointerKey,
|
||||
expectedRunID,
|
||||
manifestRunID,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user