Add logic to GET artifacts via old or new UUID#587
Conversation
pkg/sharding/sharding.go
Outdated
|
|
||
| // Returns UUID (with no prepended TreeID) from a UUID or FullID string | ||
| func GetUUIDFromIDString(id string) string { | ||
| return id[len(id)-UUIDHexStringLen:] |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
You are right @bobcallaway , sorry I missed it.
|
I'm still going to try to add an e2e test in here. |
23db617 to
45454a3
Compare
cmd/rekor-cli/app/get.go
Outdated
| entryUUID, err := sharding.GetUUIDFromIDString(uuid) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("unable to parse uuid: %w", err) | ||
| } | ||
| params.EntryUUID = entryUUID |
There was a problem hiding this comment.
| 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) | |
| } |
cmd/rekor-cli/app/get.go
Outdated
|
|
||
| for k, entry := range resp.Payload { | ||
| if k != uuid { | ||
| if k != entryUUID { |
There was a problem hiding this comment.
| 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I guess this function could also just move into pflags.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I ended up using hex.DecodeString instead of moving the pflags logic around.
pkg/sharding/sharding.go
Outdated
| } | ||
|
|
||
| func CreateFullID(treeid string, uuid string) (FullID, error) { | ||
| func CreateEntryID(treeid string, uuid string) (EntryID, error) { |
There was a problem hiding this comment.
can you please add unit tests for this package?
There was a problem hiding this comment.
Done: the unit tests have their own commit.
Signed-off-by: Lily Sturmann <lsturman@redhat.com>
Signed-off-by: Lily Sturmann <lsturman@redhat.com>
6ca60c3 to
b461d47
Compare
bobcallaway
left a comment
There was a problem hiding this comment.
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.
pkg/api/entries.go
Outdated
|
|
||
| entryUUID, err := sharding.GetUUIDFromIDString(params.EntryUUID) | ||
| if err != nil { | ||
| return handleRekorAPIError(params, http.StatusInternalServerError, err, "") |
There was a problem hiding this comment.
If the UUID isn't valid, this should return an http.StatusBadRequestError since the problem is invalid input from the client.
pkg/sharding/sharding.go
Outdated
| err := fmt.Errorf("id %v is not a valid hex string: %v", id, err) | ||
| return "", err |
There was a problem hiding this comment.
| 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>
@bobcallaway Thanks for catching these! |
Signed-off-by: Lily Sturmann <lsturman@redhat.com>
Signed-off-by: Lily Sturmann <lsturman@redhat.com>
bobcallaway
left a comment
There was a problem hiding this comment.
i'd like @dlorenc to take one final look but LGTM
Summary
This PR has 5 commits:
ranges.goand its testing into the sharding package because it is related to sharding and I was getting import cycle errors otherwise.tests/e2e_test.go?Ticket Link
Related to #487
(needs another PR before that can be closed)