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

Fix search without sha prefix #767

Merged
merged 1 commit into from
Apr 11, 2022

Conversation

eddiezane
Copy link
Member

Summary

Rekor API searches without a SHA prefix (sha1:, sha256:) do not currently work as the hash is stored in Redis with the prefix. rekor-cli infers the prefix when using --sha.

This PR reuses that logic when searching with /index/retrieve.

Ticket Link

Fixes #699

Release Note

Fixed searching the index by SHA without a prefix.

Signed-off-by: Eddie Zaneski <[email protected]>
@eddiezane eddiezane requested a review from a team as a code owner April 9, 2022 01:18
@@ -38,8 +38,9 @@ func SearchIndexHandler(params index.SearchIndexParams) middleware.Responder {
var result []string
if params.Query.Hash != "" {
// This must be a valid sha256 hash
Copy link
Member Author

Choose a reason for hiding this comment

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

SHA1 still seems to be supported?

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, I think that actually came later because we wanted to support git. So the comment is just out of date.

}
}
params.Query.Hash = fmt.Sprintf("%v%v", prefix, sha)
params.Query.Hash = util.PrefixSHA(sha)
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this still needed here? Probably if folks update the cli but not the server?

Copy link
Member

Choose a reason for hiding this comment

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

Right, safe to keep!

@codecov-commenter
Copy link

Codecov Report

Merging #767 (780bc9e) into main (4dabcda) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #767      +/-   ##
==========================================
- Coverage   48.95%   48.93%   -0.02%     
==========================================
  Files          61       62       +1     
  Lines        5585     5587       +2     
==========================================
  Hits         2734     2734              
- Misses       2556     2558       +2     
  Partials      295      295              
Impacted Files Coverage Δ
cmd/rekor-cli/app/search.go 19.69% <0.00%> (+0.99%) ⬆️
pkg/util/sha.go 0.00% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4dabcda...780bc9e. Read the comment docs.

@@ -38,8 +38,9 @@ func SearchIndexHandler(params index.SearchIndexParams) middleware.Responder {
var result []string
if params.Query.Hash != "" {
// This must be a valid sha256 hash
Copy link
Member

Choose a reason for hiding this comment

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

Good catch, I think that actually came later because we wanted to support git. So the comment is just out of date.

@dlorenc dlorenc merged commit 72add53 into sigstore:main Apr 11, 2022
@github-actions github-actions bot added this to the v1.0.0 milestone Apr 11, 2022
@eddiezane eddiezane deleted the ez/fix-search-sha-prefix branch April 12, 2022 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rekor API: searching for an artifact using SHA256 fails if not prepended with sha256:
4 participants