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

Add logic to GET artifacts via old or new UUID #587

Merged
merged 5 commits into from
Jan 25, 2022

Conversation

lkatalin
Copy link
Contributor

@lkatalin lkatalin commented Jan 7, 2022

Summary

This PR has 5 commits:

  1. Moves ranges.go and its testing into the sharding package because it is related to sharding and I was getting import cycle errors otherwise.
  2. Updates the name FullID to EntryID
  3. Adds unit tests and a few more helper functions to sharding package
  4. Adds logic to handle both new and old UUIDs during a GET request
  5. Adds an e2e test to make sure a GET request with a longer EntryID is still handled properly
  • TODO: I think this would benefit from an integration test before being merged, but I'm still looking into how to add that. I assume it should have its own function is tests/e2e_test.go?

Ticket Link

Related to #487
(needs another PR before that can be closed)


// Returns UUID (with no prepended TreeID) from a UUID or FullID string
func GetUUIDFromIDString(id string) string {
return id[len(id)-UUIDHexStringLen:]
Copy link
Member

Choose a reason for hiding this comment

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

what happens here if someone passes in a string that isn't a valid ID? you could end up panicking if the lengths are wrong. I think we need some sort of a defensive check here (with potentially an error return value as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right @bobcallaway , sorry I missed it.

@lkatalin
Copy link
Contributor Author

I'm still going to try to add an e2e test in here.

Comment on lines 115 to 123
entryUUID, err := sharding.GetUUIDFromIDString(uuid)
if err != nil {
return nil, fmt.Errorf("unable to parse uuid: %w", err)
}
params.EntryUUID = entryUUID
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
entryUUID, err := sharding.GetUUIDFromIDString(uuid)
if err != nil {
return nil, fmt.Errorf("unable to parse uuid: %w", err)
}
params.EntryUUID = entryUUID
params.EntryUUID, err = sharding.GetUUIDFromIDString(uuid)
if err != nil {
return nil, fmt.Errorf("unable to parse UUID: %w", err)
}


resp, err := rekorClient.Entries.GetLogEntryByUUID(params)
if err != nil {
return nil, err
}

for k, entry := range resp.Payload {
if k != uuid {
if k != entryUUID {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if k != entryUUID {
if k != params.entryUUID {

}

// Returns UUID (with no prepended TreeID) from a UUID or EntryID string
func GetUUIDFromIDString(id string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to move validateID logic from CLI into this package and just re-use it here? As written this doesn't check that id is a valid hex string. Its a tad paranoid given that the API layer will check the input values, but since its a exported function I think it would be good to be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is a good idea. I'm just not sure yet how to do it without tearing out the entire pflags.go logic and moving it into sharding. validateID relies on validateString, which uses the validationFunc, baseValue, etc. and I can't import those into sharding because rekor-cli has sharding as a dependency. Writing a duplicate version of validateString in sharding also seems suboptimal. Possibly would make sense to move pflags.go into a package accessible to both sharding and rekor-cli? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess this function could also just move into pflags.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think in order to do this, pflags.go and related files would have to move "up" and out of rekor-cli into a new pkg/validation or cmd/validation because that way GetUUIDFromIDString could be used in both cmd/rekor-cli/app/get.go and pkg/api/entries.go without import cycles. Still experimenting with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ended up using hex.DecodeString instead of moving the pflags logic around.

TreeID string
UUID string
}

func CreateFullID(treeid string, uuid string) (FullID, error) {
func CreateEntryID(treeid string, uuid string) (EntryID, error) {
Copy link
Member

Choose a reason for hiding this comment

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

can you please add unit tests for this package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Definitely!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done: the unit tests have their own commit.

Signed-off-by: Lily Sturmann <lsturman@redhat.com>
Signed-off-by: Lily Sturmann <lsturman@redhat.com>
Copy link
Member

@bobcallaway bobcallaway left a comment

Choose a reason for hiding this comment

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

2 minor nits. otherwise thanks for addressing all of the other comments and i think this should be good to merge once these two are fixed.


entryUUID, err := sharding.GetUUIDFromIDString(params.EntryUUID)
if err != nil {
return handleRekorAPIError(params, http.StatusInternalServerError, err, "")
Copy link
Member

Choose a reason for hiding this comment

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

If the UUID isn't valid, this should return an http.StatusBadRequestError since the problem is invalid input from the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense!

Comment on lines 122 to 123
err := fmt.Errorf("id %v is not a valid hex string: %v", id, err)
return "", err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := fmt.Errorf("id %v is not a valid hex string: %v", id, err)
return "", err
return "", fmt.Errorf("id %v is not a valid hex string: %v", id, err)

Also add a few helper functions and update names.

Signed-off-by: Lily Sturmann <lsturman@redhat.com>
@lkatalin
Copy link
Contributor Author

2 minor nits. otherwise thanks for addressing all of the other comments and i think this should be good to merge once these two are fixed.

@bobcallaway Thanks for catching these!

Signed-off-by: Lily Sturmann <lsturman@redhat.com>
Signed-off-by: Lily Sturmann <lsturman@redhat.com>
Copy link
Member

@bobcallaway bobcallaway left a comment

Choose a reason for hiding this comment

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

i'd like @dlorenc to take one final look but LGTM

@dlorenc dlorenc merged commit adab5c5 into sigstore:main Jan 25, 2022
@github-actions github-actions bot added this to the v1.0.0 milestone Jan 25, 2022
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.

3 participants