grpc
src
core
ext
xds
certificate_provider_store.cc
Go to the documentation of this file.
1
//
2
//
3
// Copyright 2020 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
#include <
grpc/support/port_platform.h
>
20
21
#include "
src/core/ext/xds/certificate_provider_store.h
"
22
23
#include <
grpc/support/log.h
>
24
25
#include "
src/core/ext/xds/certificate_provider_registry.h
"
26
27
namespace
grpc_core
{
28
29
//
30
// CertificateProviderStore::CertificateProviderWrapper
31
//
32
33
UniqueTypeName
CertificateProviderStore::CertificateProviderWrapper::type
()
34
const
{
35
static
UniqueTypeName::Factory
kFactory(
"Wrapper"
);
36
return
kFactory.
Create
();
37
}
38
39
// If a certificate provider is created, the CertificateProviderStore
40
// maintains a raw pointer to the created CertificateProviderWrapper so that
41
// future calls to `CreateOrGetCertificateProvider()` with the same key result
42
// in returning a ref to this created certificate provider. This entry is
43
// deleted when the refcount to this provider reaches zero.
44
RefCountedPtr<grpc_tls_certificate_provider>
45
CertificateProviderStore::CreateOrGetCertificateProvider
(
46
absl::string_view
key
) {
47
RefCountedPtr<CertificateProviderWrapper>
result
;
48
MutexLock
lock(&
mu_
);
49
auto
it
= certificate_providers_map_.find(
key
);
50
if
(
it
== certificate_providers_map_.end()) {
51
result
=
CreateCertificateProviderLocked
(
key
);
52
if
(
result
!=
nullptr
) {
53
certificate_providers_map_.insert({
result
->key(),
result
.get()});
54
}
55
}
else
{
56
result
=
it
->second->RefIfNonZero();
57
if
(
result
==
nullptr
) {
58
result
=
CreateCertificateProviderLocked
(
key
);
59
it
->second =
result
.get();
60
}
61
}
62
return
result
;
63
}
64
65
RefCountedPtr<CertificateProviderStore::CertificateProviderWrapper>
66
CertificateProviderStore::CreateCertificateProviderLocked
(
67
absl::string_view
key
) {
68
auto
plugin_config_it =
plugin_config_map_
.find(
std::string
(
key
));
69
if
(plugin_config_it ==
plugin_config_map_
.end()) {
70
return
nullptr
;
71
}
72
CertificateProviderFactory
* factory =
73
CertificateProviderRegistry::LookupCertificateProviderFactory
(
74
plugin_config_it->second.plugin_name);
75
if
(factory ==
nullptr
) {
76
// This should never happen since an entry is only inserted in the
77
// plugin_config_map_ if the corresponding factory was found when parsing
78
// the xDS bootstrap file.
79
gpr_log
(
GPR_ERROR
,
"Certificate provider factory %s not found"
,
80
plugin_config_it->second.plugin_name.c_str());
81
return
nullptr
;
82
}
83
return
MakeRefCounted<CertificateProviderWrapper>(
84
factory->
CreateCertificateProvider
(plugin_config_it->second.config),
85
Ref
(), plugin_config_it->first);
86
}
87
88
void
CertificateProviderStore::ReleaseCertificateProvider
(
89
absl::string_view
key
,
CertificateProviderWrapper
*
wrapper
) {
90
MutexLock
lock(&
mu_
);
91
auto
it
= certificate_providers_map_.find(
key
);
92
if
(
it
!= certificate_providers_map_.end()) {
93
if
(
it
->second ==
wrapper
) {
94
certificate_providers_map_.erase(
it
);
95
}
96
}
97
}
98
99
}
// namespace grpc_core
_gevent_test_main.result
result
Definition:
_gevent_test_main.py:96
grpc_core::UniqueTypeName::Factory::Create
UniqueTypeName Create()
Definition:
unique_type_name.h:67
regen-readme.it
it
Definition:
regen-readme.py:15
log.h
certificate_provider_store.h
grpc_core
Definition:
call_metric_recorder.h:31
grpc_core::MutexLock
Definition:
src/core/lib/gprpp/sync.h:88
absl::string_view
Definition:
abseil-cpp/absl/strings/string_view.h:167
testing::internal::string
::std::string string
Definition:
bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::CertificateProviderStore::CreateOrGetCertificateProvider
RefCountedPtr< grpc_tls_certificate_provider > CreateOrGetCertificateProvider(absl::string_view key)
Definition:
certificate_provider_store.cc:45
grpc_core::RefCountedPtr< grpc_tls_certificate_provider >
grpc_core::InternallyRefCounted< CertificateProviderStore >::Ref
RefCountedPtr< CertificateProviderStore > Ref() GRPC_MUST_USE_RESULT
Definition:
orphanable.h:90
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
grpc_core::CertificateProviderStore::CertificateProviderWrapper
Definition:
certificate_provider_store.h:73
grpc_core::CertificateProviderStore::ReleaseCertificateProvider
void ReleaseCertificateProvider(absl::string_view key, CertificateProviderWrapper *wrapper)
Definition:
certificate_provider_store.cc:88
wrapper
grpc_channel_wrapper * wrapper
Definition:
src/php/ext/grpc/channel.h:48
GPR_ERROR
#define GPR_ERROR
Definition:
include/grpc/impl/codegen/log.h:57
grpc_core::CertificateProviderStore::mu_
Mutex mu_
Definition:
certificate_provider_store.h:120
key
const char * key
Definition:
hpack_parser_table.cc:164
grpc_core::UniqueTypeName
Definition:
unique_type_name.h:56
grpc_core::CertificateProviderStore::CertificateProviderWrapper::type
UniqueTypeName type() const override
Definition:
certificate_provider_store.cc:33
certificate_provider_registry.h
grpc_core::CertificateProviderFactory
Definition:
certificate_provider_factory.h:37
grpc_core::CertificateProviderStore::CreateCertificateProviderLocked
RefCountedPtr< CertificateProviderWrapper > CreateCertificateProviderLocked(absl::string_view key) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_)
Definition:
certificate_provider_store.cc:66
grpc_core::UniqueTypeName::Factory
Definition:
unique_type_name.h:60
grpc_core::CertificateProviderFactory::CreateCertificateProvider
virtual RefCountedPtr< grpc_tls_certificate_provider > CreateCertificateProvider(RefCountedPtr< Config > config)=0
grpc_core::CertificateProviderRegistry::LookupCertificateProviderFactory
static CertificateProviderFactory * LookupCertificateProviderFactory(absl::string_view name)
Definition:
certificate_provider_registry.cc:70
grpc_core::CertificateProviderStore::plugin_config_map_
const PluginDefinitionMap plugin_config_map_
Definition:
certificate_provider_store.h:122
port_platform.h
grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:52