3 * Copyright 2016 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
22 #include <grpc/support/port_platform.h>
24 #include "src/core/lib/gprpp/ref_counted_ptr.h"
25 #include "src/core/lib/security/credentials/credentials.h"
27 #define GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY "gcloud"
28 #define GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE \
29 "application_default_credentials.json"
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
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
43 class grpc_google_default_channel_credentials
44 : public grpc_channel_credentials {
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)) {}
53 ~grpc_google_default_channel_credentials() override = default;
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;
61 grpc_channel_args* update_arguments(grpc_channel_args* args) override;
63 const grpc_channel_credentials* alts_creds() const {
64 return alts_creds_.get();
66 const grpc_channel_credentials* ssl_creds() const { return ssl_creds_.get(); }
69 grpc_core::RefCountedPtr<grpc_channel_credentials> alts_creds_;
70 grpc_core::RefCountedPtr<grpc_channel_credentials> ssl_creds_;
76 typedef bool (*grpc_gce_tenancy_checker)(void);
78 void set_gce_tenancy_checker_for_testing(grpc_gce_tenancy_checker checker);
80 // TEST-ONLY. Reset the internal global state.
81 void grpc_flush_cached_google_default_credentials(void);
83 } // namespace internal
84 } // namespace grpc_core
86 #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_GOOGLE_DEFAULT_GOOGLE_DEFAULT_CREDENTIALS_H \