Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

Server-side address validation #62

Merged
merged 9 commits into from
Jan 12, 2022
Merged

Server-side address validation #62

merged 9 commits into from
Jan 12, 2022

Conversation

hartsick
Copy link
Contributor

@hartsick hartsick commented Jan 11, 2022

Sets up a first pass at validating the address on the server based on understood deliverability—wanted to get it up for review and merge.

This saves user input if it's determined to be deliverable based on match code, but also stores the whole returned result from the Smarty API as an encrypted JSON blob for reference if we need it in the future. This is different than what's currently outlined in #43 (but just confirmed this approach with Porta and Em!)

Particularly invite feedback on validation service design and test setup; the stubbing is kind of painful so suggests things could be improved.

My developer account credentials for backend and frontend are in the credentials.yml, so we should have whatever secrets we need for testing the client-side APIs, as well.

Will still need:

And ideally would have:

Progress on #57

@hartsick hartsick force-pushed the ch/smarty-streets branch 6 times, most recently from 5ae5451 to 3f089cd Compare January 11, 2022 06:10
@hartsick hartsick changed the title [WIP] Proof of concept server-side address validation Server-side address validation Jan 11, 2022
@hartsick hartsick requested review from rahearn and hursey013 January 11, 2022 21:37
Copy link
Collaborator

@rahearn rahearn left a comment

Choose a reason for hiding this comment

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

couple small things, and we talked on the phone about being aggressive with a timeout if smarty streets stop responding.

Overall, and if this were a normal-scale app, this is good

app/controllers/kit_requests_controller.rb Outdated Show resolved Hide resolved
app/services/us_street_address_validator.rb Outdated Show resolved Hide resolved
app/services/us_street_address_validator.rb Show resolved Hide resolved
db/migrate/20220111184143_store_smarty_response.rb Outdated Show resolved Hide resolved
Also changes default json column value to match expeced format (hash
from array).
If Smarty is returning errors (timeout, unavailable, bad requests, etc)
for any reason, aggressively switch to just accepting any provided
address. This flags in the database if the address was pre-validated or
not so that we can retroactively address any submissions while the API
was down.

Keeps timeout and retry configuration in the environment so we can
more easily adjust them if needed.
@hartsick hartsick requested a review from rahearn January 12, 2022 19:31
puts err
return
# Send to New Relic
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this comment is indication of where I was thinking about sending errors in future, though we could do this in the validator catch instead?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think here is better because we have the original problem. If we did it in the validator we'd want to be sure to wrap the original reason within the ServiceIssueError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed!

build_us_street_api_client
@client = SmartyStreets::ClientBuilder.new(credentials)
.with_licenses(["us-core-cloud"])
.with_max_timeout(MAX_TIMEOUT)
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, that's wonderful that it's built-in. you're double sure that the timeout is given in seconds, and not in milliseconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just double checked and since it passes to Net::HTTP, can confirm it's seconds

puts err
return
# Send to New Relic
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think here is better because we have the original problem. If we did it in the validator we'd want to be sure to wrap the original reason within the ServiceIssueError

@hartsick hartsick merged commit 57e5c53 into main Jan 12, 2022
@hartsick hartsick deleted the ch/smarty-streets branch January 12, 2022 21:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants