Add catalog destination state schema
This commit is contained in:
@@ -14,8 +14,14 @@ import (
|
||||
)
|
||||
|
||||
type StateDocument struct {
|
||||
SingleOwner *DistributorState
|
||||
SharedRoot *SharedRootState
|
||||
SingleOwner *DistributorState
|
||||
SharedRoot *SharedRootState
|
||||
Catalog *CatalogState
|
||||
SupersededLegacy *SupersededLegacyState
|
||||
}
|
||||
|
||||
type SupersededLegacyState struct {
|
||||
SchemaVersion int
|
||||
}
|
||||
|
||||
type SharedRootState struct {
|
||||
@@ -103,18 +109,18 @@ func ParseDocument(data []byte) (StateDocument, error) {
|
||||
if err != nil {
|
||||
return StateDocument{}, err
|
||||
}
|
||||
if schemaVersion == SharedRootSchemaVersion {
|
||||
sharedRoot, err := ParseSharedRoot(data)
|
||||
switch schemaVersion {
|
||||
case legacySchemaVersion, SchemaVersion, SharedRootSchemaVersion:
|
||||
return StateDocument{SupersededLegacy: &SupersededLegacyState{SchemaVersion: schemaVersion}}, nil
|
||||
case CatalogSchemaVersion:
|
||||
catalog, err := ParseCatalog(data)
|
||||
if err != nil {
|
||||
return StateDocument{}, err
|
||||
}
|
||||
return StateDocument{SharedRoot: &sharedRoot}, nil
|
||||
return StateDocument{Catalog: &catalog}, nil
|
||||
default:
|
||||
return StateDocument{}, fmt.Errorf("state schema_version %d is unsupported", schemaVersion)
|
||||
}
|
||||
singleOwner, err := Parse(data)
|
||||
if err != nil {
|
||||
return StateDocument{}, err
|
||||
}
|
||||
return StateDocument{SingleOwner: &singleOwner}, nil
|
||||
}
|
||||
|
||||
func parseSchemaVersion(data []byte) (int, error) {
|
||||
@@ -125,6 +131,10 @@ func parseSchemaVersion(data []byte) (int, error) {
|
||||
if err := decoder.Decode(&raw); err != nil {
|
||||
return 0, fmt.Errorf("parse distributor state: %w", err)
|
||||
}
|
||||
var extra any
|
||||
if err := decoder.Decode(&extra); err != io.EOF {
|
||||
return 0, fmt.Errorf("parse distributor state: trailing data")
|
||||
}
|
||||
if raw.SchemaVersion == nil {
|
||||
return 0, fmt.Errorf("state schema_version is required")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user