test_credentials_provider.h
Go to the documentation of this file.
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_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H
20 #define GRPC_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H
21 
22 #include <memory>
23 
27 
28 namespace grpc {
29 namespace testing {
30 
31 const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS";
32 // For real credentials, like tls/ssl, this name should match the AuthContext
33 // property "transport_security_type".
34 const char kTlsCredentialsType[] = "ssl";
35 const char kAltsCredentialsType[] = "alts";
36 const char kGoogleDefaultCredentialsType[] = "google_default_credentials";
37 
38 // Provide test credentials of a particular type.
40  public:
42 
43  virtual std::shared_ptr<ChannelCredentials> GetChannelCredentials(
44  ChannelArguments* args) = 0;
45  virtual std::shared_ptr<ServerCredentials> GetServerCredentials() = 0;
46 };
47 
48 // Provide test credentials. Thread-safe.
50  public:
51  virtual ~CredentialsProvider() {}
52 
53  // Add a secure type in addition to the defaults. The default provider has
54  // (kInsecureCredentialsType, kTlsCredentialsType).
55  virtual void AddSecureType(
56  const std::string& type,
57  std::unique_ptr<CredentialTypeProvider> type_provider) = 0;
58 
59  // Provide channel credentials according to the given type. Alter the channel
60  // arguments if needed. Return nullptr if type is not registered.
61  virtual std::shared_ptr<ChannelCredentials> GetChannelCredentials(
62  const std::string& type, ChannelArguments* args) = 0;
63 
64  // Provide server credentials according to the given type.
65  // Return nullptr if type is not registered.
66  virtual std::shared_ptr<ServerCredentials> GetServerCredentials(
67  const std::string& type) = 0;
68 
69  // Provide a list of secure credentials type.
70  virtual std::vector<std::string> GetSecureCredentialsTypeList() = 0;
71 };
72 
73 // Get the current provider. Create a default one if not set.
74 // Not thread-safe.
75 CredentialsProvider* GetCredentialsProvider();
76 
77 // Set the global provider. Takes ownership. The previous set provider will be
78 // destroyed.
79 // Not thread-safe.
80 void SetCredentialsProvider(CredentialsProvider* provider);
81 
82 } // namespace testing
83 } // namespace grpc
84 
85 #endif // GRPC_TEST_CPP_UTIL_TEST_CREDENTIALS_PROVIDER_H
grpc::testing::kTlsCredentialsType
const char kTlsCredentialsType[]
Definition: test_credentials_provider.h:34
testing
Definition: aws_request_signer_test.cc:25
grpc::testing::kGoogleDefaultCredentialsType
const char kGoogleDefaultCredentialsType[]
Definition: test_credentials_provider.h:36
grpc::testing::CredentialsProvider::GetChannelCredentials
virtual std::shared_ptr< ChannelCredentials > GetChannelCredentials(const std::string &type, ChannelArguments *args)=0
grpc
Definition: grpcpp/alarm.h:33
grpc::testing::CredentialsProvider::AddSecureType
virtual void AddSecureType(const std::string &type, std::unique_ptr< CredentialTypeProvider > type_provider)=0
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc::testing::CredentialTypeProvider::~CredentialTypeProvider
virtual ~CredentialTypeProvider()
Definition: test_credentials_provider.h:41
grpc::testing::CredentialsProvider
Definition: test_credentials_provider.h:49
grpc::testing::CredentialsProvider::~CredentialsProvider
virtual ~CredentialsProvider()
Definition: test_credentials_provider.h:51
grpc::testing::kInsecureCredentialsType
const char kInsecureCredentialsType[]
Definition: test_credentials_provider.h:31
grpc::testing::CredentialTypeProvider
Definition: test_credentials_provider.h:39
grpc::testing::CredentialsProvider::GetServerCredentials
virtual std::shared_ptr< ServerCredentials > GetServerCredentials(const std::string &type)=0
grpc::testing::CredentialTypeProvider::GetChannelCredentials
virtual std::shared_ptr< ChannelCredentials > GetChannelCredentials(ChannelArguments *args)=0
grpc::testing::SetCredentialsProvider
void SetCredentialsProvider(CredentialsProvider *provider)
Definition: test_credentials_provider.cc:176
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
channel_arguments.h
grpc::testing::kAltsCredentialsType
const char kAltsCredentialsType[]
Definition: test_credentials_provider.h:35
server_credentials.h
grpc::ChannelArguments
Definition: grpcpp/support/channel_arguments.h:39
credentials.h
grpc::testing::GetCredentialsProvider
CredentialsProvider * GetCredentialsProvider()
Definition: test_credentials_provider.cc:169
grpc::testing::CredentialTypeProvider::GetServerCredentials
virtual std::shared_ptr< ServerCredentials > GetServerCredentials()=0
grpc::testing::CredentialsProvider::GetSecureCredentialsTypeList
virtual std::vector< std::string > GetSecureCredentialsTypeList()=0
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:31