Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc-cloned / deps / grpc / src / core / lib / security / credentials / google_default / google_default_credentials.h
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_GOOGLE_DEFAULT_GOOGLE_DEFAULT_CREDENTIALS_H
20 #define GRPC_CORE_LIB_SECURITY_CREDENTIALS_GOOGLE_DEFAULT_GOOGLE_DEFAULT_CREDENTIALS_H
21
22 #include <grpc/support/port_platform.h>
23
24 #include "src/core/lib/gprpp/ref_counted_ptr.h"
25 #include "src/core/lib/security/credentials/credentials.h"
26
27 #define GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY "gcloud"
28 #define GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE \
29   "application_default_credentials.json"
30
31 #ifdef GPR_WINDOWS
32 #define GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR "APPDATA"
33 #define GRPC_GOOGLE_CREDENTIALS_PATH_SUFFIX \
34   GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY    \
35   "/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE
36 #else
37 #define GRPC_GOOGLE_CREDENTIALS_PATH_ENV_VAR "HOME"
38 #define GRPC_GOOGLE_CREDENTIALS_PATH_SUFFIX         \
39   ".config/" GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY \
40   "/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE
41 #endif
42
43 class grpc_google_default_channel_credentials
44     : public grpc_channel_credentials {
45  public:
46   grpc_google_default_channel_credentials(
47       grpc_core::RefCountedPtr<grpc_channel_credentials> alts_creds,
48       grpc_core::RefCountedPtr<grpc_channel_credentials> ssl_creds)
49       : grpc_channel_credentials(GRPC_CHANNEL_CREDENTIALS_TYPE_GOOGLE_DEFAULT),
50         alts_creds_(std::move(alts_creds)),
51         ssl_creds_(std::move(ssl_creds)) {}
52
53   ~grpc_google_default_channel_credentials() override = default;
54
55   grpc_core::RefCountedPtr<grpc_channel_security_connector>
56   create_security_connector(
57       grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
58       const char* target, const grpc_channel_args* args,
59       grpc_channel_args** new_args) override;
60
61   grpc_channel_args* update_arguments(grpc_channel_args* args) override;
62
63   const grpc_channel_credentials* alts_creds() const {
64     return alts_creds_.get();
65   }
66   const grpc_channel_credentials* ssl_creds() const { return ssl_creds_.get(); }
67
68  private:
69   grpc_core::RefCountedPtr<grpc_channel_credentials> alts_creds_;
70   grpc_core::RefCountedPtr<grpc_channel_credentials> ssl_creds_;
71 };
72
73 namespace grpc_core {
74 namespace internal {
75
76 typedef bool (*grpc_gce_tenancy_checker)(void);
77
78 void set_gce_tenancy_checker_for_testing(grpc_gce_tenancy_checker checker);
79
80 // TEST-ONLY. Reset the internal global state.
81 void grpc_flush_cached_google_default_credentials(void);
82
83 }  // namespace internal
84 }  // namespace grpc_core
85
86 #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_GOOGLE_DEFAULT_GOOGLE_DEFAULT_CREDENTIALS_H \
87         */