-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add geoblock
tower middleware
#4
Conversation
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.
Looks good, but I would change Vec
-> HashSet
and preformat the blocked country list to match the format of the returned country ISO code (upper- or lower-case).
Another thing, which is a bit out of scope of this PR: I think it would be nice if this struct returned borrowed strings (as the maxmind
/geoip2
API returns them), and leave it up to the consumer whether to convert them to owned strings. Otherwise we're cloning them for no good reason, since we only need to check if there's a match.
examples/geoblock.rs
Outdated
if IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)) == caller { | ||
GeoData { | ||
continent: Some("Asia".to_string().into()), | ||
country: Some("Derkaderkastan".to_string().into()), |
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.
Nice!
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.
Hold on, this seems incorrect. The data returned by the actual API would be an ISO code. Can you come up with an example that resolves an actual IP to an actual GeoData
?
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.
Also, I think we should return 500
for all error cases, except "BlockedCountry" (which is 401
)
Btw, there are clippy warnings in tests |
@xDarksome For some reason can't reply to your comment, but I agree that the error is too detailed. Though it's not that big of a deal, since these errors should be rather rare. |
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.
Looks good, thanks!
There are still some clippy warnings in the tests though
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.
Looks good, though I think we should update the tests too to use country codes.
Description
Add Tower middleware for blocking requests based on clients' IP origin.
How Has This Been Tested?
example
Due Diligence