Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create EntryID for new artifacts and return EntryID to user #623

Merged
merged 1 commit into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should getUUIDFromUploadOutput be renamed to getEntryIDFromUploadOutput?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, though this is a larger problem all throughout the code. #625 is tracking this. Pulling on that thread will definitely create enough changes for another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can save it for later then!

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