Google Cloud Storage C++ Client  1.42.0
A C++ Client Library for Google Cloud Storage
google_application_default_credentials_file.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_GOOGLE_APPLICATION_DEFAULT_CREDENTIALS_FILE_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_GOOGLE_APPLICATION_DEFAULT_CREDENTIALS_FILE_H
17 
18 #include "google/cloud/storage/version.h"
19 #include <string>
20 
21 namespace google {
22 namespace cloud {
23 namespace storage {
25 namespace oauth2 {
26 
27 /**
28  * Returns the Application Default %Credentials environment variable name.
29  *
30  * This environment variable should be checked for a valid file path when
31  * attempting to load Google Application Default %Credentials.
32  */
33 inline char const* GoogleAdcEnvVar() {
34  static constexpr char kEnvVarName[] = "GOOGLE_APPLICATION_CREDENTIALS";
35  return kEnvVarName;
36 }
37 
38 /**
39  * Returns the path to the Application Default %Credentials file, if set.
40  *
41  * If the Application Default %Credentials environment variable is set, we check
42  * the path specified by its value for a file containing ADCs. Returns an
43  * empty string if no such path exists or the environment variable is not set.
44  */
46 
47 /**
48  * Returns the path to the Application Default %Credentials file, if set.
49  *
50  * If the gcloud utility has configured an Application Default %Credentials
51  * file, the path to that file is returned. Returns an empty string if no such
52  * file exists at the well known path.
53  */
55 
56 /**
57  * Returns the environment variable to override the gcloud ADC path.
58  *
59  * This environment variable is used for testing to override the path that
60  * should be searched for the gcloud Application Default %Credentials file.
61  */
62 inline char const* GoogleGcloudAdcFileEnvVar() {
63  static constexpr char kEnvVarName[] = "GOOGLE_GCLOUD_ADC_PATH_OVERRIDE";
64  return kEnvVarName;
65 }
66 
67 /**
68  * Returns the environment variable used to construct the well known ADC path.
69  *
70  * The directory containing a user's application configuration data, indicated
71  * by this environment variable, varies across environments. That directory is
72  * used when constructing the well known path of the Application Default
73  * Credentials file.
74  */
75 inline char const* GoogleAdcHomeEnvVar() {
76 #ifdef _WIN32
77  static constexpr char kHomeEnvVar[] = "APPDATA";
78 #else
79  static constexpr char kHomeEnvVar[] = "HOME";
80 #endif
81  return kHomeEnvVar;
82 }
83 
84 } // namespace oauth2
86 } // namespace storage
87 } // namespace cloud
88 } // namespace google
89 
90 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_OAUTH2_GOOGLE_APPLICATION_DEFAULT_CREDENTIALS_FILE_H