Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ namespace google {

namespace {

json::value ReadCredentials(const std::string& credentials_file) throw(json::Exception) {
class NoCredentials {

Choose a reason for hiding this comment

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

The spacing for this class seems unusual. Is that on purpose? Also, how about naming this NoCredentialsException?

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 is just an informational class to convey a specific (non-exceptional) status. The code catches and ignores it, modulo info logging.
What's unusual about the spacing?

Choose a reason for hiding this comment

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

Per conversation offline, this is the expected formatting. public and private should have one-space indentation per convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

public:
NoCredentials(const std::string& filename) : filename_(filename) {}
const std::string& filename() const { return filename_; }
private:
std::string filename_;
};

json::value ReadCredentials(const std::string& credentials_file)
throw(json::Exception, NoCredentials) {
std::string filename = credentials_file;
if (filename.empty()) {
const char* creds_env_var = std::getenv("GOOGLE_APPLICATION_CREDENTIALS");
Expand All @@ -41,7 +50,7 @@ json::value ReadCredentials(const std::string& credentials_file) throw(json::Exc
std::ifstream input(filename);
if (!input.good()) {
LOG(INFO) << "Missing credentials file " << filename;
return nullptr;
throw NoCredentials(filename);
}
LOG(INFO) << "Reading credentials from " << filename;
json::value creds_json = json::Parser::FromStream(input);
Expand Down Expand Up @@ -187,6 +196,8 @@ void Environment::ReadApplicationDefaultCredentials() const {
LOG(INFO) << "Retrieved private key from application default credentials";
} catch (const json::Exception& e) {
LOG(ERROR) << e.what();
} catch (const NoCredentials& e) {
LOG(INFO) << "No credentials found at " << e.filename();
}
application_default_credentials_read_ = true;
}
Expand Down