Skip to content

Commit

Permalink
Create EntryID for new artifacts and return EntryID to user (#623)
Browse files Browse the repository at this point in the history
Signed-off-by: Lily Sturmann <lsturman@redhat.com>
  • Loading branch information
lkatalin committed Apr 12, 2022
1 parent 408b752 commit 72a7b00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
14 changes: 11 additions & 3 deletions pkg/api/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,15 @@ func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middl
metricNewEntries.Inc()

queuedLeaf := resp.getAddResult.QueuedLeaf.Leaf

uuid := hex.EncodeToString(queuedLeaf.GetMerkleLeafHash())
activeTree := fmt.Sprintf("%x", tc.logID)
entryIDstruct, err := sharding.CreateEntryIDFromParts(activeTree, uuid)
if err != nil {
err := fmt.Errorf("error creating EntryID from active treeID %v and uuid %v: %w", activeTree, uuid, err)
return nil, handleRekorAPIError(params, http.StatusInternalServerError, err, fmt.Sprintf(validationError, err))
}
entryID := entryIDstruct.ReturnEntryIDString()

// The log index should be the virtual log index across all shards
virtualIndex := sharding.VirtualLogIndex(queuedLeaf.LeafIndex, api.logRanges.ActiveTreeID(), api.logRanges)
Expand All @@ -206,7 +214,7 @@ func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middl
return
}
for _, key := range keys {
if err := addToIndex(context.Background(), key, uuid); err != nil {
if err := addToIndex(context.Background(), key, entryID); err != nil {
log.RequestIDLogger(params.HTTPRequest).Error(err)
}
}
Expand All @@ -218,11 +226,11 @@ func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middl
go func() {
attestation := entry.Attestation()
if attestation == nil {
log.RequestIDLogger(params.HTTPRequest).Infof("no attestation for %s", uuid)
log.RequestIDLogger(params.HTTPRequest).Infof("no attestation for %s", entryID)
return
}
// TODO stop using uuid and use attestation hash
if err := storeAttestation(context.Background(), uuid, attestation); err != nil {
if err := storeAttestation(context.Background(), entryIDstruct.UUID, attestation); err != nil {
log.RequestIDLogger(params.HTTPRequest).Errorf("error storing attestation: %s", err)
}
}()
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ func TestGet(t *testing.T) {
out := runCli(t, "upload", "--artifact", artifactPath, "--signature", sigPath, "--public-key", pubPath)
outputContains(t, out, "Created entry at")

uuid := getUUIDFromUploadOutput(t, out)
uuid, err := sharding.GetUUIDFromIDString(getUUIDFromUploadOutput(t, out))
if err != nil {
t.Error(err)
}

// since we at least have 1 valid entry, check the log at index 0
runCli(t, "get", "--log-index", "0")
Expand Down

0 comments on commit 72a7b00

Please sign in to comment.