Skip to content

Conversation

@Roguelazer
Copy link
Contributor

allows users to just pass True for verify and verify_strict instead of having to pass [True]. Also properly quotes in case a user accidentally passes something icky.

as always, I am a firm believer that functions should be functions, not classmethods

value = [value]
verify_params[key] = value
if verify_params:
url += '?' + _urlencode_list(verify_params)

Choose a reason for hiding this comment

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

It's not clear to me why this list encoding needs its own special function, as opposed to passing the list as a parameter to requestor.request. It looks like _urlencode_list behaves slightly differently than the default list encoder in that it doesn't include an index inside the [], and our API docs do not indicate that an index should be included in the param name. Perhaps the other list encoder is incorrect?

Copy link
Contributor Author

@Roguelazer Roguelazer Jun 3, 2021

Choose a reason for hiding this comment

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

frankly I think we should just switch to encoding the bodies to JSON and get rid of all of this (absolutely awful) urlencoding crap

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that we should eventually move away from the nasty URL encoding for URL params. I looked into it some more, and part of the challenge is that our underlying HTTP library has to support both Python Requests (the good one), and also Google App Engine's urlfetcher (which is somewhat non-standard, and probably enforced for performance/security reasons on their cloud compute environment).

The way the client library is structured now has it so that URL parameters are encoded earlier on, before we get to the part where the HTTP library is even engaged.

Python Requests has a clean interface to encode URL params that also takes care of the URL encoding issues, but we aren't taking advantage of this.

In a future iteration of this library, I'd like to see the URL encoding logic pushed as far down as possible, and maintain a Python dictionary for the URL parameters and payload throughout most of the code, and do the necessary conversions only where necessary.

I would like to see the "multiple-path handling" logic for accommodating the two different HTTP libraries eventually be implemented as two different adapters or strategies hidden behind a wrapper for cleaner abstraction.

  1. For the second part, regarding lists of params, I had a hard time finding an official spec, but this SO details some of the issues.

To pass in a list of params, the two common practices are to do one of:

a) base/url?fav_foods=pizza&fav_foods=ice_cream&fav_foods=sushi OR
b) base/url?fav_foods[]=pizza&fav_foods[]=ice_cream&fav_foods[]=sushi

It's very wrong to have a list index inside the param. The former works, but various HTTP frameworks aren't implemented correctly to handle it, and the latter is also not idea, being a pattern that is used by some popular HTTP frameworks like Django and others, but again, not ubiquitous.

frankly I think we should just switch to encoding the bodies to JSON and get rid of all of this

James's suggestion to do away with URL parameters and just encode the whole thing and pass as a JSON body is the most correct/ideal.

In Conclusion

Given all of the options (and the difficulty in implementing them right now), and that this change is correct, I am comfortable accepting and merging this code as is.

Choose a reason for hiding this comment

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

I strongly agree with moving away from URL-encoding request parameters.

@jontsai putting an adapter in front of the HTTP request logic is a good idea, whether or not we stick with URL encoding parameters. In addition to that, I would love to drop support for urlfetch, as it's not in the GAE Python 3 runtime. Sadly, however, Google has stated that they will continue to support the 2.7 runtime indefinitely, so it's not clear when we'll be able to do that.

jontsai
jontsai previously approved these changes Jun 15, 2021
Copy link
Contributor

@jontsai jontsai left a comment

Choose a reason for hiding this comment

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

LGTM

value = [value]
verify_params[key] = value
if verify_params:
url += '?' + _urlencode_list(verify_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree that we should eventually move away from the nasty URL encoding for URL params. I looked into it some more, and part of the challenge is that our underlying HTTP library has to support both Python Requests (the good one), and also Google App Engine's urlfetcher (which is somewhat non-standard, and probably enforced for performance/security reasons on their cloud compute environment).

The way the client library is structured now has it so that URL parameters are encoded earlier on, before we get to the part where the HTTP library is even engaged.

Python Requests has a clean interface to encode URL params that also takes care of the URL encoding issues, but we aren't taking advantage of this.

In a future iteration of this library, I'd like to see the URL encoding logic pushed as far down as possible, and maintain a Python dictionary for the URL parameters and payload throughout most of the code, and do the necessary conversions only where necessary.

I would like to see the "multiple-path handling" logic for accommodating the two different HTTP libraries eventually be implemented as two different adapters or strategies hidden behind a wrapper for cleaner abstraction.

  1. For the second part, regarding lists of params, I had a hard time finding an official spec, but this SO details some of the issues.

To pass in a list of params, the two common practices are to do one of:

a) base/url?fav_foods=pizza&fav_foods=ice_cream&fav_foods=sushi OR
b) base/url?fav_foods[]=pizza&fav_foods[]=ice_cream&fav_foods[]=sushi

It's very wrong to have a list index inside the param. The former works, but various HTTP frameworks aren't implemented correctly to handle it, and the latter is also not idea, being a pattern that is used by some popular HTTP frameworks like Django and others, but again, not ubiquitous.

frankly I think we should just switch to encoding the bodies to JSON and get rid of all of this

James's suggestion to do away with URL parameters and just encode the whole thing and pass as a JSON body is the most correct/ideal.

In Conclusion

Given all of the options (and the difficulty in implementing them right now), and that this change is correct, I am comfortable accepting and merging this code as is.

Justintime50
Justintime50 previously approved these changes Jun 15, 2021
Copy link
Member

@Justintime50 Justintime50 left a comment

Choose a reason for hiding this comment

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

lftm based on our convos reviewing. Looks like this will need to be rebased against master?

allows users to just pass `True` for verify and verify_strict instead of
having to pass `[True]`. Also properly quotes in case a user
accidentally passes something icky.

as always, I am a firm believer that functions should be functions, not classmethods
@Roguelazer Roguelazer dismissed stale reviews from Justintime50 and jontsai via e1f0b7e June 22, 2021 22:22
@Roguelazer Roguelazer force-pushed the true_verifications branch from 26c5466 to e1f0b7e Compare June 22, 2021 22:22
@Roguelazer
Copy link
Contributor Author

rebased

@Justintime50 Justintime50 merged commit cf03dc7 into master Jul 20, 2021
@jontsai jontsai deleted the true_verifications branch July 20, 2021 19:39
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.

5 participants