-
Notifications
You must be signed in to change notification settings - Fork 164
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
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.
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)
There was a problem hiding this comment.
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
|
||
resp, err := rekorClient.Entries.GetLogEntryByUUID(params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for k, entry := range resp.Payload { | ||
if k != uuid { | ||
if k != entryUUID { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if k != entryUUID { | |
if k != params.entryUUID { |
pkg/sharding/sharding.go
Outdated
} | ||
|
||
// 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.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/sharding/sharding.go
Outdated
TreeID string | ||
UUID string | ||
} | ||
|
||
func CreateFullID(treeid string, uuid string) (FullID, error) { | ||
func CreateEntryID(treeid string, uuid string) (EntryID, error) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely!
There was a problem hiding this comment.
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>
6ca60c3
to
b461d47
Compare
There was a problem hiding this 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.
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this 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
Summary
This PR has 5 commits:
ranges.go
and 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)