• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 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 "test/cpp/interop/server_helper.h"
20 
21 #include <memory>
22 
23 #include <gflags/gflags.h>
24 #include <grpcpp/security/server_credentials.h>
25 
26 #include "src/core/lib/surface/call_test_only.h"
27 #include "test/cpp/util/test_credentials_provider.h"
28 
29 DECLARE_bool(use_alts);
30 DECLARE_bool(use_tls);
31 DECLARE_string(custom_credentials_type);
32 
33 namespace grpc {
34 namespace testing {
35 
CreateInteropServerCredentials()36 std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() {
37   if (!FLAGS_custom_credentials_type.empty()) {
38     return GetCredentialsProvider()->GetServerCredentials(
39         FLAGS_custom_credentials_type);
40   } else if (FLAGS_use_alts) {
41     return GetCredentialsProvider()->GetServerCredentials(kAltsCredentialsType);
42   } else if (FLAGS_use_tls) {
43     return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType);
44   } else {
45     return GetCredentialsProvider()->GetServerCredentials(
46         kInsecureCredentialsType);
47   }
48 }
49 
InteropServerContextInspector(const::grpc::ServerContext & context)50 InteropServerContextInspector::InteropServerContextInspector(
51     const ::grpc::ServerContext& context)
52     : context_(context) {}
53 
54 grpc_compression_algorithm
GetCallCompressionAlgorithm() const55 InteropServerContextInspector::GetCallCompressionAlgorithm() const {
56   return grpc_call_test_only_get_compression_algorithm(context_.call_);
57 }
58 
GetEncodingsAcceptedByClient() const59 uint32_t InteropServerContextInspector::GetEncodingsAcceptedByClient() const {
60   return grpc_call_test_only_get_encodings_accepted_by_peer(context_.call_);
61 }
62 
GetMessageFlags() const63 uint32_t InteropServerContextInspector::GetMessageFlags() const {
64   return grpc_call_test_only_get_message_flags(context_.call_);
65 }
66 
67 std::shared_ptr<const AuthContext>
GetAuthContext() const68 InteropServerContextInspector::GetAuthContext() const {
69   return context_.auth_context();
70 }
71 
IsCancelled() const72 bool InteropServerContextInspector::IsCancelled() const {
73   return context_.IsCancelled();
74 }
75 
76 }  // namespace testing
77 }  // namespace grpc
78