GRPC C++  1.39.1
evaluate_args.h
Go to the documentation of this file.
1 // Copyright 2021 gRPC authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GRPC_CORE_LIB_SECURITY_AUTHORIZATION_EVALUATE_ARGS_H
16 #define GRPC_CORE_LIB_SECURITY_AUTHORIZATION_EVALUATE_ARGS_H
17 
19 
20 #include <map>
21 
22 #include "absl/types/optional.h"
23 
28 
29 namespace grpc_core {
30 
31 class EvaluateArgs {
32  public:
33  // Caller is responsible for ensuring auth_context outlives PerChannelArgs
34  // struct.
35  struct PerChannelArgs {
36  struct Address {
37  // The address in sockaddr form.
39  // The same address with only the host part.
40  std::string address_str;
41  int port = 0;
42  };
43 
44  PerChannelArgs(grpc_auth_context* auth_context, grpc_endpoint* endpoint);
45 
46  absl::string_view transport_security_type;
47  absl::string_view spiffe_id;
48  std::vector<absl::string_view> uri_sans;
49  std::vector<absl::string_view> dns_sans;
50  absl::string_view common_name;
53  };
54 
56  : metadata_(metadata), channel_args_(channel_args) {}
57 
58  absl::string_view GetPath() const;
59  absl::string_view GetHost() const;
60  absl::string_view GetMethod() const;
61  std::multimap<absl::string_view, absl::string_view> GetHeaders() const;
62  // Returns metadata value(s) for the specified key.
63  // If the key is not present in the batch, returns absl::nullopt.
64  // If the key is present exactly once in the batch, returns a string_view of
65  // that value.
66  // If the key is present more than once in the batch, constructs a
67  // comma-concatenated string of all values in concatenated_value and returns a
68  // string_view of that string.
69  absl::optional<absl::string_view> GetHeaderValue(
70  absl::string_view key, std::string* concatenated_value) const;
71 
73  absl::string_view GetLocalAddressString() const;
74  int GetLocalPort() const;
76  absl::string_view GetPeerAddressString() const;
77  int GetPeerPort() const;
78  absl::string_view GetTransportSecurityType() const;
79  absl::string_view GetSpiffeId() const;
80  std::vector<absl::string_view> GetUriSans() const;
81  std::vector<absl::string_view> GetDnsSans() const;
82  absl::string_view GetCommonName() const;
83 
84  private:
85  grpc_metadata_batch* metadata_;
86  PerChannelArgs* channel_args_;
87 };
88 
89 } // namespace grpc_core
90 
91 #endif // GRPC_CORE_LIB_SECURITY_AUTHORIZATION_EVALUATE_ARGS_H
Definition: evaluate_args.h:31
absl::string_view GetMethod() const
Definition: evaluate_args.cc:99
grpc_resolved_address GetPeerAddress() const
Definition: evaluate_args.cc:153
absl::string_view GetCommonName() const
Definition: evaluate_args.cc:202
EvaluateArgs(grpc_metadata_batch *metadata, PerChannelArgs *channel_args)
Definition: evaluate_args.h:55
grpc_resolved_address GetLocalAddress() const
Definition: evaluate_args.cc:132
std::multimap< absl::string_view, absl::string_view > GetHeaders() const
Definition: evaluate_args.cc:109
int GetPeerPort() const
Definition: evaluate_args.cc:167
absl::string_view GetPath() const
Definition: evaluate_args.cc:79
std::vector< absl::string_view > GetDnsSans() const
Definition: evaluate_args.cc:195
absl::string_view GetLocalAddressString() const
Definition: evaluate_args.cc:139
int GetLocalPort() const
Definition: evaluate_args.cc:146
absl::string_view GetHost() const
Definition: evaluate_args.cc:89
absl::string_view GetTransportSecurityType() const
Definition: evaluate_args.cc:174
std::vector< absl::string_view > GetUriSans() const
Definition: evaluate_args.cc:188
absl::string_view GetPeerAddressString() const
Definition: evaluate_args.cc:160
absl::string_view GetSpiffeId() const
Definition: evaluate_args.cc:181
absl::optional< absl::string_view > GetHeaderValue(absl::string_view key, std::string *concatenated_value) const
Definition: evaluate_args.cc:124
Round Robin Policy.
Definition: backend_metric.cc:26
Definition: security_context.h:51
grpc_resolved_address address
Definition: evaluate_args.h:38
std::string address_str
Definition: evaluate_args.h:40
int port
Definition: evaluate_args.h:41
Definition: evaluate_args.h:35
std::vector< absl::string_view > dns_sans
Definition: evaluate_args.h:49
Address local_address
Definition: evaluate_args.h:51
absl::string_view transport_security_type
Definition: evaluate_args.h:46
PerChannelArgs(grpc_auth_context *auth_context, grpc_endpoint *endpoint)
Definition: evaluate_args.cc:61
std::vector< absl::string_view > uri_sans
Definition: evaluate_args.h:48
Address peer_address
Definition: evaluate_args.h:52
absl::string_view spiffe_id
Definition: evaluate_args.h:47
absl::string_view common_name
Definition: evaluate_args.h:50
Definition: endpoint.h:106
Definition: metadata_batch.h:52
Definition: resolve_address.h:44