Skip to content

Commit bd5a874

Browse files
committed
Preliminary draft of UUID parsing with todos
1 parent 41dd848 commit bd5a874

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

cmd/rekor-cli/app/get.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/spf13/viper"
3131

3232
"github.com/sigstore/rekor/cmd/rekor-cli/app/format"
33+
"github.com/sigstore/rekor/cmd/rekor-cli/app/sharding"
3334
"github.com/sigstore/rekor/pkg/client"
3435
"github.com/sigstore/rekor/pkg/generated/client/entries"
3536
"github.com/sigstore/rekor/pkg/generated/models"
@@ -110,15 +111,15 @@ var getCmd = &cobra.Command{
110111
if uuid != "" {
111112
params := entries.NewGetLogEntryByUUIDParams()
112113
params.SetTimeout(viper.GetDuration("timeout"))
113-
params.EntryUUID = uuid
114+
params.EntryUUID = uuid[sharding.ShardIdUuidLen-sharding.UuIdLen:]
114115

115116
resp, err := rekorClient.Entries.GetLogEntryByUUID(params)
116117
if err != nil {
117118
return nil, err
118119
}
119120

120121
for k, entry := range resp.Payload {
121-
if k != uuid {
122+
if k != params.EntryUUID {
122123
continue
123124
}
124125

cmd/rekor-cli/app/pflags.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
"github.com/sigstore/rekor/pkg/pki"
2626
"github.com/sigstore/rekor/pkg/util"
27+
//"github.com/sigstore/rekor/cmd/rekor-cli/app/sharding"
2728

2829
"github.com/spf13/pflag"
2930

@@ -56,8 +57,10 @@ var pflagValueFuncMap map[FlagType]newPFlagValueFunc
5657
func initializePFlagMap() {
5758
pflagValueFuncMap = map[FlagType]newPFlagValueFunc{
5859
uuidFlag: func() pflag.Value {
59-
// this corresponds to the merkle leaf hash of entries, which is represented by a 64 character hexadecimal string
60-
return valueFactory(uuidFlag, validateString("required,len=64,hexadecimal"), "")
60+
// this corresponds to the merkle leaf hash of entries, which is represented by a 64 character hexadecimal string, prepended by the 6-digit shard ID and '-' separator
61+
// TODO: does this have to be a literal? can we not use the const to define the len?
62+
// TODO: is there a way to validate only the UUID part of this string as hexadecimal? or validate different parts of the string differently? can / should they be split into different flags?
63+
return valueFactory(uuidFlag, validateString("required,len=71"), "")
6164
},
6265
shaFlag: func() pflag.Value {
6366
// this validates a valid sha256 checksum which is optionally prefixed with 'sha256:'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Copyright 2021 The Sigstore Authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
package sharding
17+
18+
const ShardIdLen = 6
19+
const UuIdLen = 64
20+
const SeparatorLen = 1
21+
const ShardIdUuidLen = ShardIdLen + UuIdLen + SeparatorLen
22+
23+
// TODO: The shardID will be part of the state and will be updated. Store it in state.go?
24+
var CurrentShardId = 0

pkg/api/entries.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"fmt"
2424
"net/http"
2525
"net/url"
26+
//"strconv"
2627

2728
"github.com/cyberphone/json-canonicalization/go/src/webpki.org/jsoncanonicalizer"
2829
"github.com/go-openapi/runtime/middleware"
@@ -183,7 +184,9 @@ func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middl
183184
metricNewEntries.Inc()
184185

185186
queuedLeaf := resp.getAddResult.QueuedLeaf.Leaf
186-
uuid := hex.EncodeToString(queuedLeaf.GetMerkleLeafHash())
187+
shardID := "000000"
188+
// TODO: grab global shardId and convert to 6 digit number / prepend with zeroes
189+
uuid := shardID + "-" + hex.EncodeToString(queuedLeaf.GetMerkleLeafHash())
187190

188191
logEntryAnon := models.LogEntryAnon{
189192
LogID: swag.String(api.pubkeyHash),

0 commit comments

Comments
 (0)