mirror of https://github.com/grpc/grpc.git
Third attempt: Convert client_auth_filter to promises (#28968)
* wip
* Automated change: Fix sanity tests
* fixes
* progress
* progress
* grpc compiles
* Automated change: Fix sanity tests
* fixing tests
* x
* progress
* better code
* Automated change: Fix sanity tests
* progress
* progress
* windows fix
* Make Duration metadata trivial
* better message
* fix
* Automated change: Fix sanity tests
* fix
* fix
* fix
* fix
* Automated change: Fix sanity tests
* Automated change: Fix sanity tests
* fix
* progress
* fixes
* fix
* fix
* spam
* un-disable errantly disabled tests
* gain insight
* Automated change: Fix sanity tests
* fixes
* fixes
* fix
* debug
* tweak
* fix
* fix timeout
* fix comment
* fixes
* x
* better test
* tests
* Automated change: Fix sanity tests
* missed file
* fix
* x
* fix
* fix
* fix
* fix
* Automated change: Fix sanity tests
* fix
* merge
* Automated change: Fix sanity tests
* Revert "Revert "Revert "Revert "Convert client_auth_filter to promises (#28767)" (#28951)" (#28952)" (#28967)"
This reverts commit 0f73576b17
.
* fix potential memory leak
* Fix behavior if >1 pending request
* fix
* fix nullptr access
Co-authored-by: ctiller <ctiller@users.noreply.github.com>
pull/28980/head^2
parent
5fc3ff8203
commit
87acbadba1
72 changed files with 1762 additions and 2047 deletions
@ -0,0 +1,50 @@ |
||||
// Copyright 2022 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/channel/promise_based_filter.h" |
||||
|
||||
#include "src/core/lib/channel/channel_stack.h" |
||||
|
||||
namespace grpc_core { |
||||
namespace promise_filter_detail { |
||||
|
||||
// We don't form ActivityPtr's to this type, and consequently don't need
|
||||
// Orphan().
|
||||
void BaseCallData::Orphan() { abort(); } |
||||
|
||||
// For now we don't care about owning/non-owning wakers, instead just share
|
||||
// implementation.
|
||||
Waker BaseCallData::MakeNonOwningWaker() { return MakeOwningWaker(); } |
||||
|
||||
Waker BaseCallData::MakeOwningWaker() { |
||||
GRPC_CALL_STACK_REF(call_stack_, "waker"); |
||||
return Waker(this); |
||||
} |
||||
|
||||
void BaseCallData::Wakeup() { |
||||
auto wakeup = [](void* p, grpc_error_handle) { |
||||
auto* self = static_cast<BaseCallData*>(p); |
||||
self->OnWakeup(); |
||||
self->Drop(); |
||||
}; |
||||
auto* closure = GRPC_CLOSURE_CREATE(wakeup, this, nullptr); |
||||
GRPC_CALL_COMBINER_START(call_combiner_, closure, GRPC_ERROR_NONE, "wakeup"); |
||||
} |
||||
|
||||
void BaseCallData::Drop() { GRPC_CALL_STACK_UNREF(call_stack_, "waker"); } |
||||
|
||||
} // namespace promise_filter_detail
|
||||
} // namespace grpc_core
|
@ -0,0 +1,87 @@ |
||||
//
|
||||
// Copyright 2022 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include "src/core/lib/security/credentials/call_creds_util.h" |
||||
|
||||
#include "absl/strings/str_cat.h" |
||||
#include "absl/strings/string_view.h" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
namespace { |
||||
|
||||
struct ServiceUrlAndMethod { |
||||
std::string service_url; |
||||
absl::string_view method_name; |
||||
}; |
||||
|
||||
ServiceUrlAndMethod MakeServiceUrlAndMethod( |
||||
const ClientInitialMetadata& initial_metadata, |
||||
const grpc_call_credentials::GetRequestMetadataArgs* args) { |
||||
auto service = |
||||
initial_metadata->get_pointer(HttpPathMetadata())->as_string_view(); |
||||
auto last_slash = service.find_last_of('/'); |
||||
absl::string_view method_name; |
||||
if (last_slash == absl::string_view::npos) { |
||||
gpr_log(GPR_ERROR, "No '/' found in fully qualified method name"); |
||||
service = ""; |
||||
method_name = ""; |
||||
} else if (last_slash == 0) { |
||||
method_name = ""; |
||||
} else { |
||||
method_name = service.substr(last_slash + 1); |
||||
service = service.substr(0, last_slash); |
||||
} |
||||
auto host_and_port = |
||||
initial_metadata->get_pointer(HttpAuthorityMetadata())->as_string_view(); |
||||
absl::string_view url_scheme = args->security_connector->url_scheme(); |
||||
if (url_scheme == GRPC_SSL_URL_SCHEME) { |
||||
// Remove the port if it is 443.
|
||||
auto port_delimiter = host_and_port.find_last_of(':'); |
||||
if (port_delimiter != absl::string_view::npos && |
||||
host_and_port.substr(port_delimiter + 1) == "443") { |
||||
host_and_port = host_and_port.substr(0, port_delimiter); |
||||
} |
||||
} |
||||
return ServiceUrlAndMethod{ |
||||
absl::StrCat(url_scheme, "://", host_and_port, service), method_name}; |
||||
} |
||||
|
||||
} // namespace
|
||||
|
||||
std::string MakeJwtServiceUrl( |
||||
const ClientInitialMetadata& initial_metadata, |
||||
const grpc_call_credentials::GetRequestMetadataArgs* args) { |
||||
return MakeServiceUrlAndMethod(initial_metadata, args).service_url; |
||||
} |
||||
|
||||
grpc_auth_metadata_context MakePluginAuthMetadataContext( |
||||
const ClientInitialMetadata& initial_metadata, |
||||
const grpc_call_credentials::GetRequestMetadataArgs* args) { |
||||
auto fields = MakeServiceUrlAndMethod(initial_metadata, args); |
||||
grpc_auth_metadata_context ctx; |
||||
memset(&ctx, 0, sizeof(ctx)); |
||||
ctx.channel_auth_context = args->auth_context != nullptr |
||||
? args->auth_context->Ref().release() |
||||
: nullptr; |
||||
ctx.service_url = gpr_strdup(fields.service_url.c_str()); |
||||
ctx.method_name = gpr_strdup(std::string(fields.method_name).c_str()); |
||||
return ctx; |
||||
} |
||||
|
||||
} // namespace grpc_core
|
@ -0,0 +1,42 @@ |
||||
//
|
||||
// Copyright 2022 gRPC authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef GRPC_CORE_LIB_SECURITY_CREDENTIALS_CALL_CREDS_UTIL_H |
||||
#define GRPC_CORE_LIB_SECURITY_CREDENTIALS_CALL_CREDS_UTIL_H |
||||
|
||||
#include <grpc/support/port_platform.h> |
||||
|
||||
#include <string> |
||||
|
||||
#include <grpc/grpc_security.h> |
||||
|
||||
#include "src/core/lib/security/credentials/credentials.h" |
||||
|
||||
namespace grpc_core { |
||||
|
||||
// Helper function to construct service URL for jwt call creds.
|
||||
std::string MakeJwtServiceUrl( |
||||
const ClientInitialMetadata& initial_metadata, |
||||
const grpc_call_credentials::GetRequestMetadataArgs* args); |
||||
|
||||
// Helper function to construct context for plugin call creds.
|
||||
grpc_auth_metadata_context MakePluginAuthMetadataContext( |
||||
const ClientInitialMetadata& initial_metadata, |
||||
const grpc_call_credentials::GetRequestMetadataArgs* args); |
||||
|
||||
} // namespace grpc_core
|
||||
|
||||
#endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_CALL_CREDS_UTIL_H */ |
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue