-
Notifications
You must be signed in to change notification settings - Fork 37
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
pkg/rest: refactor and simplify #292
base: main
Are you sure you want to change the base?
Conversation
Reviewer's Guide by SourceryRefactored the REST package by removing unused code, simplifying URI parsing, and updating tests to reflect these changes. The URI parsing and validation logic has been consolidated into the Sequence diagram for Endpoint creationsequenceDiagram
participant Client
participant NewEndpoint
participant url.ParseRequestURI
participant toRestScheme
Client->>NewEndpoint: NewEndpoint(input)
NewEndpoint->>url.ParseRequestURI: url.ParseRequestURI(input)
url.ParseRequestURI-->>NewEndpoint: Returns URI
NewEndpoint->>toRestScheme: toRestScheme(URI.Scheme)
toRestScheme-->>NewEndpoint: Returns ServiceScheme
NewEndpoint-->>Client: Returns Endpoint, error
Updated class diagram for EndpointclassDiagram
class Endpoint {
Host: string
Path: string
Scheme: ServiceScheme
}
class ServiceScheme {
None
Unix
TCP
}
Endpoint -- ServiceScheme : has a
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Hi @kolyshkin. Thanks for your PR. I'm waiting for a crc-org member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
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.
Hey @kolyshkin - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding comments to the
ServiceScheme
enum to explain what each value represents. - The error messages in
NewEndpoint
could be improved to provide more context about the validation failure.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
return None, nil | ||
case "UNIX": | ||
case "unix": |
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 a const
be used?
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.
Do you mean, a const from the standard packages? I am not aware of any, please suggest.
Or do you mean to introduce and use own constant? If that's the case, I don't think it makes sense here.
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 thought they had... https://pkg.go.dev/net/url#pkg-constants "Section is emptry" :-/
func toRestScheme(s string) (ServiceScheme, error) { | ||
switch strings.ToUpper(s) { |
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.
This is to ensure no mistakes are made when this is specified manually.
Either use upper
or lower
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 point me out to a case in the code where it is specified manually?
From what I see, it is only used to parse a Scheme field from a structure obtained from url.ParseRequestURI, which ensures Scheme is lowercase, so we can expect the lowercased string here. This was noted in the commit message, too.
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'll let @cfergeau decide as he maintains this codebase.
I just notice that https://github.com/crc-org/vfkit/pull/292/files#diff-e8eb5f08837c85d4c2db17fa463051c4a787efb7cbc9883092f53b24a48514e1R32 uses the input that comes from the request parse; and it assumes the format to be returned always to be lower. Defensive programming is not wrong, as this is not code to be performant or such (and mistakes have been made before). Overall, this looks more maintainable.
Since it is used exclusively to parse a Scheme field from a structure obtained from url.ParseRequestURI, which ensures Scheme is lowercase, we can expect the lowercased string here. Fix the test accordingly. Signed-off-by: Kir Kolyshkin <[email protected]>
It is not used anywhere except in its own unit test. Signed-off-by: Kir Kolyshkin <[email protected]>
f987ceb
to
c44508a
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.
Haven't tested functionality, but looks cleaner.
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: gbraad The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
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.
3rd commit can be improved in my opinion, the first 2 look good to me.
c44508a
to
1e56123
Compare
New changes are detected. LGTM label has been removed. |
I have remove the third commit. |
Are you planning to do some work on it? Or should we merge this as is? |
/ok-to-test |
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
This removes unused code from pkg/rest, and simplifies it.
Should not change functionality in any way.
Please see individual commits for details.
Summary by Sourcery
Refactor and simplify the REST package by removing unused code and consolidating URI parsing logic
Enhancements:
Tests:
Chores: