Skip to content
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

Improve error messages when loading credentials. #1212

Merged
merged 7 commits into from
Oct 4, 2018

Conversation

coryan
Copy link
Contributor

@coryan coryan commented Oct 3, 2018

This fixes #974. The error messages when loading an invalid or missing
credentials file were sometimes very obscure (typically some parsing
problem in the JSON library). The new error messages should make it
easier to diagnose the problem.


This change is Reviewable

This fixes googleapis#974. The error messages when loading an invalid or missing
credentials file were sometimes very obscure (typically some parsing
problem in the JSON library). The new error messages should make it
easier to diagnose the problem.
@coryan coryan added the api: storage Issues related to the Cloud Storage API. label Oct 3, 2018
@coryan coryan requested a review from houglum October 3, 2018 19:05
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 3, 2018
@codecov
Copy link

codecov bot commented Oct 3, 2018

Codecov Report

Merging #1212 into master will increase coverage by 0.03%.
The diff coverage is 97.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1212      +/-   ##
==========================================
+ Coverage    92.2%   92.23%   +0.03%     
==========================================
  Files         224      226       +2     
  Lines       12313    12370      +57     
==========================================
+ Hits        11353    11410      +57     
  Misses        960      960
Impacted Files Coverage Δ
google/cloud/storage/oauth2/google_credentials.cc 97.22% <100%> (+7.56%) ⬆️
...loud/storage/oauth2/service_account_credentials.cc 100% <100%> (ø)
...loud/storage/oauth2/authorized_user_credentials.cc 100% <100%> (ø)
...cloud/storage/oauth2/authorized_user_credentials.h 95.65% <94.73%> (-1.97%) ⬇️
...cloud/storage/oauth2/service_account_credentials.h 96.22% <95%> (-1.89%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update edce377...7f9255e. Read the comment docs.

char const REFRESH_TOKEN_KEY[] = "refresh_token";
for (auto const& key :
{CLIENT_ID_KEY, CLIENT_SECRET_KEY, REFRESH_TOKEN_KEY}) {
if (credentials.count(key) == 0U) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this new logic could be factored out into its own function, which would (probably) make testing it easier. If you had something like ParseAndValidateCredentialContent(), it could check if the content is valid/parseable JSON, check that the required fields exist, and make sure that those fields aren't empty (meaning we don't have to change the .get() calls below)... returning the nl::json object if all went well, or raising/dying at the first error it finds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored, let me know what you think.

Copy link
Contributor

@houglum houglum left a comment

Choose a reason for hiding this comment

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

LGTM

@coryan coryan merged commit 2a7c3ee into googleapis:master Oct 4, 2018
@coryan coryan deleted the improve-credential-loading-errors branch October 4, 2018 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error messages when failing to load credentials
3 participants