|
|
@ -69,19 +69,27 @@ class CredentialsProvider { |
|
|
|
|
|
|
|
|
|
|
|
class DefaultCredentialsProvider : public CredentialsProvider { |
|
|
|
class DefaultCredentialsProvider : public CredentialsProvider { |
|
|
|
public: |
|
|
|
public: |
|
|
|
~DefaultCredentialsProvider() override {} |
|
|
|
~DefaultCredentialsProvider() GRPC_OVERRIDE {} |
|
|
|
|
|
|
|
|
|
|
|
void AddSecureType( |
|
|
|
void AddSecureType(const grpc::string& type, |
|
|
|
const grpc::string& type, |
|
|
|
std::unique_ptr<CredentialTypeProvider> type_provider) |
|
|
|
std::unique_ptr<CredentialTypeProvider> type_provider) override { |
|
|
|
GRPC_OVERRIDE { |
|
|
|
// This clobbers any existing entry for type, except the defaults, which
|
|
|
|
// This clobbers any existing entry for type, except the defaults, which
|
|
|
|
// can't be clobbered.
|
|
|
|
// can't be clobbered.
|
|
|
|
grpc::unique_lock<grpc::mutex> lock(mu_); |
|
|
|
grpc::unique_lock<grpc::mutex> lock(mu_); |
|
|
|
added_secure_types_[type] = std::move(type_provider); |
|
|
|
auto it = std::find(added_secure_type_names_.begin(), |
|
|
|
|
|
|
|
added_secure_type_names_.end(), type); |
|
|
|
|
|
|
|
if (it == added_secure_type_names_.end()) { |
|
|
|
|
|
|
|
added_secure_type_names_.push_back(type); |
|
|
|
|
|
|
|
added_secure_type_providers_.push_back(std::move(type_provider)); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
added_secure_type_providers_[it - added_secure_type_names_.begin()] = |
|
|
|
|
|
|
|
std::move(type_provider); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ChannelCredentials> GetChannelCredentials( |
|
|
|
std::shared_ptr<ChannelCredentials> GetChannelCredentials( |
|
|
|
const grpc::string& type, ChannelArguments* args) override { |
|
|
|
const grpc::string& type, ChannelArguments* args) GRPC_OVERRIDE { |
|
|
|
if (type == grpc::testing::kInsecureCredentialsType) { |
|
|
|
if (type == grpc::testing::kInsecureCredentialsType) { |
|
|
|
return InsecureChannelCredentials(); |
|
|
|
return InsecureChannelCredentials(); |
|
|
|
} else if (type == grpc::testing::kTlsCredentialsType) { |
|
|
|
} else if (type == grpc::testing::kTlsCredentialsType) { |
|
|
@ -90,17 +98,19 @@ class DefaultCredentialsProvider : public CredentialsProvider { |
|
|
|
return SslCredentials(ssl_opts); |
|
|
|
return SslCredentials(ssl_opts); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
grpc::unique_lock<grpc::mutex> lock(mu_); |
|
|
|
grpc::unique_lock<grpc::mutex> lock(mu_); |
|
|
|
auto it(added_secure_types_.find(type)); |
|
|
|
auto it(std::find(added_secure_type_names_.begin(), |
|
|
|
if (it == added_secure_types_.end()) { |
|
|
|
added_secure_type_names_.end(), type)); |
|
|
|
|
|
|
|
if (it == added_secure_type_names_.end()) { |
|
|
|
gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); |
|
|
|
gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); |
|
|
|
return nullptr; |
|
|
|
return grpc::nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
return it->second->GetChannelCredentials(args); |
|
|
|
return added_secure_type_providers_[it - added_secure_type_names_.begin()] |
|
|
|
|
|
|
|
->GetChannelCredentials(args); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ServerCredentials> GetServerCredentials( |
|
|
|
std::shared_ptr<ServerCredentials> GetServerCredentials( |
|
|
|
const grpc::string& type) override { |
|
|
|
const grpc::string& type) GRPC_OVERRIDE { |
|
|
|
if (type == grpc::testing::kInsecureCredentialsType) { |
|
|
|
if (type == grpc::testing::kInsecureCredentialsType) { |
|
|
|
return InsecureServerCredentials(); |
|
|
|
return InsecureServerCredentials(); |
|
|
|
} else if (type == grpc::testing::kTlsCredentialsType) { |
|
|
|
} else if (type == grpc::testing::kTlsCredentialsType) { |
|
|
@ -112,32 +122,36 @@ class DefaultCredentialsProvider : public CredentialsProvider { |
|
|
|
return SslServerCredentials(ssl_opts); |
|
|
|
return SslServerCredentials(ssl_opts); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
grpc::unique_lock<grpc::mutex> lock(mu_); |
|
|
|
grpc::unique_lock<grpc::mutex> lock(mu_); |
|
|
|
auto it(added_secure_types_.find(type)); |
|
|
|
auto it(std::find(added_secure_type_names_.begin(), |
|
|
|
if (it == added_secure_types_.end()) { |
|
|
|
added_secure_type_names_.end(), type)); |
|
|
|
|
|
|
|
if (it == added_secure_type_names_.end()) { |
|
|
|
gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); |
|
|
|
gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str()); |
|
|
|
return nullptr; |
|
|
|
return grpc::nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
return it->second->GetServerCredentials(); |
|
|
|
return added_secure_type_providers_[it - added_secure_type_names_.begin()] |
|
|
|
|
|
|
|
->GetServerCredentials(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
std::vector<grpc::string> GetSecureCredentialsTypeList() override { |
|
|
|
std::vector<grpc::string> GetSecureCredentialsTypeList() GRPC_OVERRIDE { |
|
|
|
std::vector<grpc::string> types; |
|
|
|
std::vector<grpc::string> types; |
|
|
|
types.push_back(grpc::testing::kTlsCredentialsType); |
|
|
|
types.push_back(grpc::testing::kTlsCredentialsType); |
|
|
|
grpc::unique_lock<grpc::mutex> lock(mu_); |
|
|
|
grpc::unique_lock<grpc::mutex> lock(mu_); |
|
|
|
for (const auto& type_pair : added_secure_types_) { |
|
|
|
for (auto it = added_secure_type_names_.begin(); |
|
|
|
types.push_back(type_pair.first); |
|
|
|
it != added_secure_type_names_.end(); it++) { |
|
|
|
|
|
|
|
types.push_back(*it); |
|
|
|
} |
|
|
|
} |
|
|
|
return types; |
|
|
|
return types; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
private: |
|
|
|
grpc::mutex mu_; |
|
|
|
grpc::mutex mu_; |
|
|
|
std::unordered_map<grpc::string, std::unique_ptr<CredentialTypeProvider> > |
|
|
|
std::vector<grpc::string> added_secure_type_names_; |
|
|
|
added_secure_types_; |
|
|
|
std::vector<std::unique_ptr<CredentialTypeProvider>> |
|
|
|
|
|
|
|
added_secure_type_providers_; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
gpr_once g_once_init_provider = GPR_ONCE_INIT; |
|
|
|
gpr_once g_once_init_provider = GPR_ONCE_INIT; |
|
|
|
CredentialsProvider* g_provider = nullptr; |
|
|
|
CredentialsProvider* g_provider = grpc::nullptr; |
|
|
|
|
|
|
|
|
|
|
|
void CreateDefaultProvider() { g_provider = new DefaultCredentialsProvider; } |
|
|
|
void CreateDefaultProvider() { g_provider = new DefaultCredentialsProvider; } |
|
|
|
|
|
|
|
|
|
|
|