call_creds_util.cc
Go to the documentation of this file.
1 //
2 // Copyright 2022 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
18 
20 
21 #include <string.h>
22 
23 #include "absl/strings/str_cat.h"
24 #include "absl/strings/string_view.h"
25 
26 #include <grpc/support/log.h>
28 
33 
34 namespace grpc_core {
35 
36 namespace {
37 
38 struct ServiceUrlAndMethod {
41 };
42 
43 ServiceUrlAndMethod MakeServiceUrlAndMethod(
44  const ClientMetadataHandle& initial_metadata,
46  auto service =
47  initial_metadata->get_pointer(HttpPathMetadata())->as_string_view();
48  auto last_slash = service.find_last_of('/');
50  if (last_slash == absl::string_view::npos) {
51  gpr_log(GPR_ERROR, "No '/' found in fully qualified method name");
52  service = "";
53  method_name = "";
54  } else if (last_slash == 0) {
55  method_name = "";
56  } else {
57  method_name = service.substr(last_slash + 1);
58  service = service.substr(0, last_slash);
59  }
60  auto host_and_port =
61  initial_metadata->get_pointer(HttpAuthorityMetadata())->as_string_view();
62  absl::string_view url_scheme = args->security_connector->url_scheme();
64  // Remove the port if it is 443.
65  auto port_delimiter = host_and_port.find_last_of(':');
66  if (port_delimiter != absl::string_view::npos &&
67  host_and_port.substr(port_delimiter + 1) == "443") {
68  host_and_port = host_and_port.substr(0, port_delimiter);
69  }
70  }
71  return ServiceUrlAndMethod{
72  absl::StrCat(url_scheme, "://", host_and_port, service), method_name};
73 }
74 
75 } // namespace
76 
78  const ClientMetadataHandle& initial_metadata,
80  return MakeServiceUrlAndMethod(initial_metadata, args).service_url;
81 }
82 
84  const ClientMetadataHandle& initial_metadata,
86  auto fields = MakeServiceUrlAndMethod(initial_metadata, args);
88  memset(&ctx, 0, sizeof(ctx));
89  ctx.channel_auth_context = args->auth_context != nullptr
90  ? args->auth_context->Ref().release()
91  : nullptr;
92  ctx.service_url = gpr_strdup(fields.service_url.c_str());
93  ctx.method_name = gpr_strdup(std::string(fields.method_name).c_str());
94  return ctx;
95 }
96 
97 } // namespace grpc_core
grpc_call_credentials::GetRequestMetadataArgs
Definition: src/core/lib/security/credentials/credentials.h:196
log.h
metadata_batch.h
ctx
Definition: benchmark-async.c:30
absl::StrCat
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: abseil-cpp/absl/strings/str_cat.cc:98
memset
return memset(p, 0, total)
grpc_core
Definition: call_metric_recorder.h:31
string.h
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
ctx
static struct test_ctx ctx
Definition: test-ipc-send-recv.c:65
service_url
std::string service_url
Definition: call_creds_util.cc:39
string_util.h
asyncio_get_stats.args
args
Definition: asyncio_get_stats.py:40
url_scheme
const char * url_scheme
Definition: core/security/credentials_test.cc:2051
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
security_connector.h
GPR_ERROR
#define GPR_ERROR
Definition: include/grpc/impl/codegen/log.h:57
grpc_core::MetadataHandle
Definition: transport.h:94
grpc_core::MakeJwtServiceUrl
std::string MakeJwtServiceUrl(const ClientMetadataHandle &initial_metadata, const grpc_call_credentials::GetRequestMetadataArgs *args)
Definition: call_creds_util.cc:77
security_context.h
profile_analyzer.fields
list fields
Definition: profile_analyzer.py:266
ref_counted_ptr.h
grpc_core::MakePluginAuthMetadataContext
grpc_auth_metadata_context MakePluginAuthMetadataContext(const ClientMetadataHandle &initial_metadata, const grpc_call_credentials::GetRequestMetadataArgs *args)
Definition: call_creds_util.cc:83
gpr_strdup
GPRAPI char * gpr_strdup(const char *src)
Definition: string.cc:39
call_creds_util.h
grpc_core::ClientMetadataHandle
MetadataHandle< ClientMetadata > ClientMetadataHandle
Definition: transport.h:153
GRPC_SSL_URL_SCHEME
#define GRPC_SSL_URL_SCHEME
Definition: security_connector.h:49
absl::string_view::npos
static constexpr size_type npos
Definition: abseil-cpp/absl/strings/string_view.h:182
service
__attribute__((deprecated("Please use GRPCProtoMethod."))) @interface ProtoMethod NSString * service
Definition: ProtoMethod.h:25
grpc_auth_metadata_context
Definition: grpc_security.h:391
method_name
absl::string_view method_name
Definition: call_creds_util.cc:40
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:51