• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include <grpc/support/port_platform.h>
19 
20 #include <map>
21 
22 #include "absl/types/optional.h"
23 
24 #include "src/core/lib/iomgr/endpoint.h"
25 #include "src/core/lib/security/context/security_context.h"
26 #include "src/core/lib/transport/metadata_batch.h"
27 
28 namespace grpc_core {
29 
30 class EvaluateArgs {
31  public:
32   // Caller is responsible for ensuring auth_context outlives PerChannelArgs
33   // struct.
34   struct PerChannelArgs {
35     PerChannelArgs(grpc_auth_context* auth_context, grpc_endpoint* endpoint);
36 
37     absl::string_view transport_security_type;
38     absl::string_view spiffe_id;
39     absl::string_view common_name;
40     std::string local_address;
41     int local_port = 0;
42     std::string peer_address;
43     int peer_port = 0;
44   };
45 
EvaluateArgs(grpc_metadata_batch * metadata,PerChannelArgs * channel_args)46   EvaluateArgs(grpc_metadata_batch* metadata, PerChannelArgs* channel_args)
47       : metadata_(metadata), channel_args_(channel_args) {}
48 
49   absl::string_view GetPath() const;
50   absl::string_view GetHost() const;
51   absl::string_view GetMethod() const;
52   std::multimap<absl::string_view, absl::string_view> GetHeaders() const;
53   // Returns metadata value(s) for the specified key.
54   // If the key is not present in the batch, returns absl::nullopt.
55   // If the key is present exactly once in the batch, returns a string_view of
56   // that value.
57   // If the key is present more than once in the batch, constructs a
58   // comma-concatenated string of all values in concatenated_value and returns a
59   // string_view of that string.
60   absl::optional<absl::string_view> GetHeaderValue(
61       absl::string_view key, std::string* concatenated_value) const;
62 
63   absl::string_view GetLocalAddress() const;
64   int GetLocalPort() const;
65   absl::string_view GetPeerAddress() const;
66   int GetPeerPort() const;
67   absl::string_view GetTransportSecurityType() const;
68   absl::string_view GetSpiffeId() const;
69   absl::string_view GetCommonName() const;
70 
71  private:
72   grpc_metadata_batch* metadata_;
73   PerChannelArgs* channel_args_;
74 };
75 
76 }  // namespace grpc_core
77 
78 #endif  // GRPC_CORE_LIB_SECURITY_AUTHORIZATION_EVALUATE_ARGS_H
79