Skip to content

Commit

Permalink
go/common/entity: Make {Min,Max}DescriptorVersion constants public
Browse files Browse the repository at this point in the history
  • Loading branch information
tjanez committed Apr 10, 2021
1 parent 912001e commit 5416c9d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions .changelog/3845.feature.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/common/entity: Add `{Min,Max}DescriptorVersion` constants
20 changes: 11 additions & 9 deletions go/common/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ const (
// used for all new descriptors. Using earlier versions may be rejected.
LatestDescriptorVersion = 2

// Minimum and maximum descriptor versions that are allowed.
minDescriptorVersion = 1
maxDescriptorVersion = LatestDescriptorVersion
// MinDescriptorVersion is the minimum descriptor version that is allowed.
MinDescriptorVersion = 1
// MaxDescriptorVersion is the maximum descriptor version that is allowed.
MaxDescriptorVersion = LatestDescriptorVersion
)

// Entity represents an entity that controls one or more Nodes and or
Expand Down Expand Up @@ -100,17 +101,18 @@ func (e *Entity) ValidateBasic(strictVersion bool) error {
case true:
// Only the latest version is allowed.
if v != LatestDescriptorVersion {
return fmt.Errorf("invalid entity descriptor version (expected: %d got: %d)",
LatestDescriptorVersion,
return fmt.Errorf("invalid entity descriptor version: %d (expected: %d)",
v,
LatestDescriptorVersion,
)
}
case false:
// A range of versions is allowed.
if v < minDescriptorVersion || v > maxDescriptorVersion {
return fmt.Errorf("invalid entity descriptor version (min: %d max: %d)",
minDescriptorVersion,
maxDescriptorVersion,
if v < MinDescriptorVersion || v > MaxDescriptorVersion {
return fmt.Errorf("invalid entity descriptor version: %d (min: %d max: %d)",
v,
MinDescriptorVersion,
MaxDescriptorVersion,
)
}
}
Expand Down

0 comments on commit 5416c9d

Please sign in to comment.