userver: userver/ugrpc/server/middlewares/field_mask/component.hpp Source File
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/ugrpc/server/middlewares/field_mask/component.hpp
4/// @brief @copybrief ugrpc::server::middlewares::field_mask::Component
5
6#include <userver/ugrpc/server/middlewares/base.hpp>
7
8#include <memory>
9#include <string>
10#include <string_view>
11
12#include <userver/components/component_fwd.hpp>
13#include <userver/components/raw_component_base.hpp>
14#include <userver/ugrpc/field_mask.hpp>
15#include <userver/ugrpc/server/storage_context.hpp>
16#include <userver/utils/any_storage.hpp>
17
18USERVER_NAMESPACE_BEGIN
19
20/// Server field-mask metadata field middleware
21namespace ugrpc::server::middlewares::field_mask {
22
23/// @see ugrpc::server::middlewares::field_mask::Component
24inline const utils::AnyStorageDataTag<ugrpc::server::StorageContext, FieldMask> kFieldMaskStorageDataTag;
25
26/// @see ugrpc::server::middlewares::field_mask::Component
27inline const std::string kDefaultMetadataFieldName = "field-mask";
28
29// clang-format off
30
31/// @ingroup userver_components userver_base_classes
32///
33/// @brief Component for gRPC server field-mask parsing and trimming
34///
35/// ## Static options:
36/// Name | Description | Default value
37/// ---- | ----------- | -------------
38/// metadata-field-name | the metadata field name to read the mask from | field-mask
39///
40/// @warning Masking messages that contain optional fields in protobuf prior to v3.13
41/// causes a segmentation fault. If this is the case for you, you should not use
42/// this middleware. See https://github.com/protocolbuffers/protobuf/issues/7801
43///
44/// ## Static configuration example:
45///
46/// @snippet grpc/functional_tests/basic_chaos/static_config.yaml Sample grpc server field-mask middleware component config
47
48// clang-format on
49
50class Component final : public MiddlewareComponentBase {
51public:
52 /// @ingroup userver_component_names
53 /// @brief The default name of
54 /// ugrpc::server::middlewares::field_mask::Component
55 static constexpr std::string_view kName = "grpc-server-field-mask";
56
57 Component(const components::ComponentConfig& config, const components::ComponentContext& context);
58
59 std::shared_ptr<MiddlewareBase> GetMiddleware() override;
60
61 static yaml_config::Schema GetStaticConfigSchema();
62
63private:
64 std::string metadata_field_name_;
65};
66
67} // namespace ugrpc::server::middlewares::field_mask
68
69USERVER_NAMESPACE_END