diff --git a/cmd/rekor-server/app/flags.go b/cmd/rekor-server/app/flags.go index c2040d8b60a804efde730487bf29024b7059a2c1..76705f285eeb7bc034c1ffcbad2a1ea7630c2315 100644 --- a/cmd/rekor-server/app/flags.go +++ b/cmd/rekor-server/app/flags.go @@ -104,3 +104,8 @@ func (l *LogRanges) ResolveVirtualIndex(index int) (uint64, uint64) { // Return the last one! return l.Ranges[len(l.Ranges)-1].TreeID, uint64(indexLeft) } + +// ActiveIndex returns the active shard index, always the last shard in the range +func (l *LogRanges) ActiveIndex() uint64 { + return l.Ranges[len(l.Ranges)-1].TreeID +} diff --git a/cmd/rekor-server/app/flags_test.go b/cmd/rekor-server/app/flags_test.go index 5c9990f2e7cd139e5155c25ab953fce53bda7f06..ab82b261e3177565c40b5a61d3e3ea7fe048e942 100644 --- a/cmd/rekor-server/app/flags_test.go +++ b/cmd/rekor-server/app/flags_test.go @@ -23,9 +23,10 @@ import ( func TestLogRanges_Set(t *testing.T) { tests := []struct { - name string - arg string - want []LogRange + name string + arg string + want []LogRange + active uint64 }{ { name: "one, no length", @@ -36,6 +37,7 @@ func TestLogRanges_Set(t *testing.T) { TreeLength: 0, }, }, + active: 1234, }, { name: "two", @@ -50,6 +52,7 @@ func TestLogRanges_Set(t *testing.T) { TreeLength: 0, }, }, + active: 7234, }, } for _, tt := range tests { @@ -62,6 +65,11 @@ func TestLogRanges_Set(t *testing.T) { if diff := cmp.Diff(tt.want, l.Ranges); diff != "" { t.Errorf(diff) } + + active := l.ActiveIndex() + if active != tt.active { + t.Errorf("LogRanges.Active() expected %d no error, got %d", tt.active, active) + } }) } }