Skip to content

Commit

Permalink
impl(oauth2): refactor application credentials file (#9708)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthart committed Aug 19, 2022
1 parent c4da072 commit 18937be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "google/cloud/storage/oauth2/google_application_default_credentials_file.h"
#include "google/cloud/internal/getenv.h"
#include "google/cloud/internal/oauth2_google_application_default_credentials_file.h"
#include <cstdlib>

namespace {
Expand All @@ -37,6 +38,10 @@ namespace storage {
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
namespace oauth2 {

char const* GoogleAdcEnvVar() {
return google::cloud::oauth2_internal::GoogleAdcEnvVar();
}

std::string GoogleAdcFilePathFromEnvVarOrEmpty() {
auto override_value = google::cloud::internal::GetEnv(GoogleAdcEnvVar());
if (override_value.has_value()) {
Expand All @@ -61,6 +66,14 @@ std::string GoogleAdcFilePathFromWellKnownPathOrEmpty() {
return "";
}

char const* GoogleGcloudAdcFileEnvVar() {
return google::cloud::oauth2_internal::GoogleGcloudAdcFileEnvVar();
}

char const* GoogleAdcHomeEnvVar() {
return google::cloud::oauth2_internal::GoogleAdcHomeEnvVar();
}

} // namespace oauth2
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
} // namespace storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ namespace oauth2 {
* This environment variable should be checked for a valid file path when
* attempting to load Google Application Default %Credentials.
*/
inline char const* GoogleAdcEnvVar() {
static constexpr char kEnvVarName[] = "GOOGLE_APPLICATION_CREDENTIALS";
return kEnvVarName;
}
char const* GoogleAdcEnvVar();

/**
* Returns the path to the Application Default %Credentials file, if set.
Expand All @@ -59,10 +56,7 @@ std::string GoogleAdcFilePathFromWellKnownPathOrEmpty();
* This environment variable is used for testing to override the path that
* should be searched for the gcloud Application Default %Credentials file.
*/
inline char const* GoogleGcloudAdcFileEnvVar() {
static constexpr char kEnvVarName[] = "GOOGLE_GCLOUD_ADC_PATH_OVERRIDE";
return kEnvVarName;
}
char const* GoogleGcloudAdcFileEnvVar();

/**
* Returns the environment variable used to construct the well known ADC path.
Expand All @@ -72,14 +66,7 @@ inline char const* GoogleGcloudAdcFileEnvVar() {
* used when constructing the well known path of the Application Default
* Credentials file.
*/
inline char const* GoogleAdcHomeEnvVar() {
#ifdef _WIN32
static constexpr char kHomeEnvVar[] = "APPDATA";
#else
static constexpr char kHomeEnvVar[] = "HOME";
#endif
return kHomeEnvVar;
}
char const* GoogleAdcHomeEnvVar();

} // namespace oauth2
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
Expand Down

0 comments on commit 18937be

Please sign in to comment.