Merge pull request #18452 from grpc/grpc_namespace_server_credentials

Fold server credentials from grpc to grpc_impl namespace
pull/18510/head^2
Karthik Ravi Shankar 6 years ago committed by GitHub
commit af283b3183
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 1
      BUILD.gn
  3. 3
      CMakeLists.txt
  4. 3
      Makefile
  5. 1
      build.yaml
  6. 1
      gRPC-C++.podspec
  7. 7
      include/grpcpp/impl/codegen/server_interface.h
  8. 66
      include/grpcpp/security/server_credentials.h
  9. 85
      include/grpcpp/security/server_credentials_impl.h
  10. 15
      include/grpcpp/server_builder.h
  11. 6
      src/cpp/server/insecure_server_credentials.cc
  12. 16
      src/cpp/server/secure_server_credentials.cc
  13. 17
      src/cpp/server/secure_server_credentials.h
  14. 6
      src/cpp/server/server_credentials.cc
  15. 1
      test/cpp/util/test_credentials_provider.cc
  16. 1
      tools/doxygen/Doxyfile.c++
  17. 1
      tools/doxygen/Doxyfile.c++.internal
  18. 2
      tools/run_tests/generated/sources_and_headers.json

@ -253,6 +253,7 @@ GRPCXX_PUBLIC_HDRS = [
"include/grpcpp/security/auth_metadata_processor_impl.h",
"include/grpcpp/security/credentials.h",
"include/grpcpp/security/server_credentials.h",
"include/grpcpp/security/server_credentials_impl.h",
"include/grpcpp/server.h",
"include/grpcpp/server_builder.h",
"include/grpcpp/server_context.h",

@ -1084,6 +1084,7 @@ config("grpc_config") {
"include/grpcpp/security/auth_metadata_processor_impl.h",
"include/grpcpp/security/credentials.h",
"include/grpcpp/security/server_credentials.h",
"include/grpcpp/security/server_credentials_impl.h",
"include/grpcpp/server.h",
"include/grpcpp/server_builder.h",
"include/grpcpp/server_context.h",

@ -3032,6 +3032,7 @@ foreach(_hdr
include/grpcpp/security/auth_metadata_processor_impl.h
include/grpcpp/security/credentials.h
include/grpcpp/security/server_credentials.h
include/grpcpp/security/server_credentials_impl.h
include/grpcpp/server.h
include/grpcpp/server_builder.h
include/grpcpp/server_context.h
@ -3632,6 +3633,7 @@ foreach(_hdr
include/grpcpp/security/auth_metadata_processor_impl.h
include/grpcpp/security/credentials.h
include/grpcpp/security/server_credentials.h
include/grpcpp/security/server_credentials_impl.h
include/grpcpp/server.h
include/grpcpp/server_builder.h
include/grpcpp/server_context.h
@ -4606,6 +4608,7 @@ foreach(_hdr
include/grpcpp/security/auth_metadata_processor_impl.h
include/grpcpp/security/credentials.h
include/grpcpp/security/server_credentials.h
include/grpcpp/security/server_credentials_impl.h
include/grpcpp/server.h
include/grpcpp/server_builder.h
include/grpcpp/server_context.h

@ -5363,6 +5363,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/security/auth_metadata_processor_impl.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
include/grpcpp/server_context.h \
@ -5971,6 +5972,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/security/auth_metadata_processor_impl.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
include/grpcpp/server_context.h \
@ -6894,6 +6896,7 @@ PUBLIC_HEADERS_CXX += \
include/grpcpp/security/auth_metadata_processor_impl.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
include/grpcpp/server_context.h \

@ -1378,6 +1378,7 @@ filegroups:
- include/grpcpp/security/auth_metadata_processor_impl.h
- include/grpcpp/security/credentials.h
- include/grpcpp/security/server_credentials.h
- include/grpcpp/security/server_credentials_impl.h
- include/grpcpp/server.h
- include/grpcpp/server_builder.h
- include/grpcpp/server_context.h

@ -117,6 +117,7 @@ Pod::Spec.new do |s|
'include/grpcpp/security/auth_metadata_processor_impl.h',
'include/grpcpp/security/credentials.h',
'include/grpcpp/security/server_credentials.h',
'include/grpcpp/security/server_credentials_impl.h',
'include/grpcpp/server.h',
'include/grpcpp/server_builder.h',
'include/grpcpp/server_context.h',

@ -28,6 +28,10 @@
#include <grpcpp/impl/codegen/rpc_service_method.h>
#include <grpcpp/impl/codegen/server_context.h>
namespace grpc_impl {
class ServerCredentials;
}
namespace grpc {
class AsyncGenericService;
@ -35,7 +39,6 @@ class Channel;
class GenericServerContext;
class ServerCompletionQueue;
class ServerContext;
class ServerCredentials;
class Service;
extern CoreCodegenInterface* g_core_codegen_interface;
@ -150,7 +153,7 @@ class ServerInterface : public internal::CallHook {
///
/// \warning It's an error to call this method on an already started server.
virtual int AddListeningPort(const grpc::string& addr,
ServerCredentials* creds) = 0;
grpc_impl::ServerCredentials* creds) = 0;
/// Start the server.
///

@ -1,6 +1,6 @@
/*
*
* Copyright 2015 gRPC authors.
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -19,39 +19,11 @@
#ifndef GRPCPP_SECURITY_SERVER_CREDENTIALS_H
#define GRPCPP_SECURITY_SERVER_CREDENTIALS_H
#include <memory>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpcpp/security/auth_metadata_processor.h>
#include <grpcpp/support/config.h>
struct grpc_server;
#include <grpcpp/security/server_credentials_impl.h>
namespace grpc {
class Server;
/// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
class ServerCredentials {
public:
virtual ~ServerCredentials();
/// This method is not thread-safe and has to be called before the server is
/// started. The last call to this function wins.
virtual void SetAuthMetadataProcessor(
const std::shared_ptr<AuthMetadataProcessor>& processor) = 0;
private:
friend class ::grpc::Server;
/// Tries to bind \a server to the given \a addr (eg, localhost:1234,
/// 192.168.1.1:31416, [::1]:27182, etc.)
///
/// \return bound port number on sucess, 0 on failure.
// TODO(dgq): the "port" part seems to be a misnomer.
virtual int AddPortToServer(const grpc::string& addr,
grpc_server* server) = 0;
};
typedef ::grpc_impl::ServerCredentials ServerCredentials;
/// Options to create ServerCredentials with SSL
struct SslServerCredentialsOptions {
@ -79,27 +51,29 @@ struct SslServerCredentialsOptions {
grpc_ssl_client_certificate_request_type client_certificate_request;
};
/// Builds SSL ServerCredentials given SSL specific options
std::shared_ptr<ServerCredentials> SslServerCredentials(
const SslServerCredentialsOptions& options);
static inline std::shared_ptr<ServerCredentials> SslServerCredentials(
const SslServerCredentialsOptions& options) {
return ::grpc_impl::SslServerCredentials(options);
}
/// Builds insecure server credentials.
std::shared_ptr<ServerCredentials> InsecureServerCredentials();
static inline std::shared_ptr<ServerCredentials> InsecureServerCredentials() {
return ::grpc_impl::InsecureServerCredentials();
}
namespace experimental {
/// Options to create ServerCredentials with ALTS
struct AltsServerCredentialsOptions {
/// Add fields if needed.
};
typedef ::grpc_impl::experimental::AltsServerCredentialsOptions
AltsServerCredentialsOptions;
/// Builds ALTS ServerCredentials given ALTS specific options
std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
static inline std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options) {
return ::grpc_impl::experimental::AltsServerCredentials(options);
}
/// Builds Local ServerCredentials.
std::shared_ptr<ServerCredentials> LocalServerCredentials(
grpc_local_connect_type type);
static inline std::shared_ptr<ServerCredentials> LocalServerCredentials(
grpc_local_connect_type type) {
return ::grpc_impl::experimental::LocalServerCredentials(type);
}
} // namespace experimental
} // namespace grpc

@ -0,0 +1,85 @@
/*
*
* Copyright 2015 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 GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
#define GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H
#include <memory>
#include <vector>
#include <grpc/grpc_security_constants.h>
#include <grpcpp/security/auth_metadata_processor.h>
#include <grpcpp/support/config.h>
struct grpc_server;
namespace grpc {
class Server;
struct SslServerCredentialsOptions;
} // namespace grpc
namespace grpc_impl {
/// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
class ServerCredentials {
public:
virtual ~ServerCredentials();
/// This method is not thread-safe and has to be called before the server is
/// started. The last call to this function wins.
virtual void SetAuthMetadataProcessor(
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) = 0;
private:
friend class ::grpc::Server;
/// Tries to bind \a server to the given \a addr (eg, localhost:1234,
/// 192.168.1.1:31416, [::1]:27182, etc.)
///
/// \return bound port number on sucess, 0 on failure.
// TODO(dgq): the "port" part seems to be a misnomer.
virtual int AddPortToServer(const grpc::string& addr,
grpc_server* server) = 0;
};
/// Builds SSL ServerCredentials given SSL specific options
std::shared_ptr<ServerCredentials> SslServerCredentials(
const grpc::SslServerCredentialsOptions& options);
/// Builds insecure server credentials.
std::shared_ptr<ServerCredentials> InsecureServerCredentials();
namespace experimental {
/// Options to create ServerCredentials with ALTS
struct AltsServerCredentialsOptions {
/// Add fields if needed.
};
/// Builds ALTS ServerCredentials given ALTS specific options
std::shared_ptr<ServerCredentials> AltsServerCredentials(
const AltsServerCredentialsOptions& options);
/// Builds Local ServerCredentials.
std::shared_ptr<ServerCredentials> LocalServerCredentials(
grpc_local_connect_type type);
} // namespace experimental
} // namespace grpc_impl
#endif // GRPCPP_SECURITY_SERVER_CREDENTIALS_IMPL_H

@ -37,8 +37,9 @@ struct grpc_resource_quota;
namespace grpc_impl {
class ServerCredentials;
class ResourceQuota;
}
} // namespace grpc_impl
namespace grpc {
@ -46,7 +47,6 @@ class AsyncGenericService;
class CompletionQueue;
class Server;
class ServerCompletionQueue;
class ServerCredentials;
class Service;
namespace testing {
@ -97,9 +97,10 @@ class ServerBuilder {
/// number bound to the \a grpc::Server for the corresponding endpoint after
/// it is successfully bound by BuildAndStart(), 0 otherwise. AddListeningPort
/// does not modify this pointer.
ServerBuilder& AddListeningPort(const grpc::string& addr_uri,
std::shared_ptr<ServerCredentials> creds,
int* selected_port = nullptr);
ServerBuilder& AddListeningPort(
const grpc::string& addr_uri,
std::shared_ptr<grpc_impl::ServerCredentials> creds,
int* selected_port = nullptr);
/// Add a completion queue for handling asynchronous services.
///
@ -256,7 +257,7 @@ class ServerBuilder {
/// Experimental, to be deprecated
struct Port {
grpc::string addr;
std::shared_ptr<ServerCredentials> creds;
std::shared_ptr<grpc_impl::ServerCredentials> creds;
int* selected_port;
};
@ -324,7 +325,7 @@ class ServerBuilder {
/// List of completion queues added via \a AddCompletionQueue method.
std::vector<ServerCompletionQueue*> cqs_;
std::shared_ptr<ServerCredentials> creds_;
std::shared_ptr<grpc_impl::ServerCredentials> creds_;
std::vector<std::unique_ptr<ServerBuilderPlugin>> plugins_;
grpc_resource_quota* resource_quota_;
AsyncGenericService* generic_service_{nullptr};

@ -21,7 +21,7 @@
#include <grpc/grpc.h>
#include <grpc/support/log.h>
namespace grpc {
namespace grpc_impl {
namespace {
class InsecureServerCredentialsImpl final : public ServerCredentials {
public:
@ -29,7 +29,7 @@ class InsecureServerCredentialsImpl final : public ServerCredentials {
return grpc_server_add_insecure_http2_port(server, addr.c_str());
}
void SetAuthMetadataProcessor(
const std::shared_ptr<AuthMetadataProcessor>& processor) override {
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) override {
(void)processor;
GPR_ASSERT(0); // Should not be called on InsecureServerCredentials.
}
@ -41,4 +41,4 @@ std::shared_ptr<ServerCredentials> InsecureServerCredentials() {
new InsecureServerCredentialsImpl());
}
} // namespace grpc
} // namespace grpc_impl

@ -93,21 +93,25 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor(
status.error_message().c_str());
}
} // namespace grpc
namespace grpc_impl {
int SecureServerCredentials::AddPortToServer(const grpc::string& addr,
grpc_server* server) {
return grpc_server_add_secure_http2_port(server, addr.c_str(), creds_);
}
void SecureServerCredentials::SetAuthMetadataProcessor(
const std::shared_ptr<AuthMetadataProcessor>& processor) {
auto* wrapper = new AuthMetadataProcessorAyncWrapper(processor);
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) {
auto* wrapper = new grpc::AuthMetadataProcessorAyncWrapper(processor);
grpc_server_credentials_set_auth_metadata_processor(
creds_, {AuthMetadataProcessorAyncWrapper::Process,
AuthMetadataProcessorAyncWrapper::Destroy, wrapper});
creds_, {grpc::AuthMetadataProcessorAyncWrapper::Process,
grpc::AuthMetadataProcessorAyncWrapper::Destroy, wrapper});
}
std::shared_ptr<ServerCredentials> SslServerCredentials(
const SslServerCredentialsOptions& options) {
const grpc::SslServerCredentialsOptions& options) {
std::vector<grpc_ssl_pem_key_cert_pair> pem_key_cert_pairs;
for (auto key_cert_pair = options.pem_key_cert_pairs.begin();
key_cert_pair != options.pem_key_cert_pairs.end(); key_cert_pair++) {
@ -147,4 +151,4 @@ std::shared_ptr<ServerCredentials> LocalServerCredentials(
}
} // namespace experimental
} // namespace grpc
} // namespace grpc_impl

@ -27,8 +27,15 @@
#include "src/cpp/server/thread_pool_interface.h"
namespace grpc_impl {
class SecureServerCredentials;
} // namespace grpc_impl
namespace grpc {
typedef ::grpc_impl::SecureServerCredentials SecureServerCredentials;
class AuthMetadataProcessorAyncWrapper final {
public:
static void Destroy(void* wrapper);
@ -49,6 +56,10 @@ class AuthMetadataProcessorAyncWrapper final {
std::shared_ptr<AuthMetadataProcessor> processor_;
};
} // namespace grpc
namespace grpc_impl {
class SecureServerCredentials final : public ServerCredentials {
public:
explicit SecureServerCredentials(grpc_server_credentials* creds)
@ -60,13 +71,13 @@ class SecureServerCredentials final : public ServerCredentials {
int AddPortToServer(const grpc::string& addr, grpc_server* server) override;
void SetAuthMetadataProcessor(
const std::shared_ptr<AuthMetadataProcessor>& processor) override;
const std::shared_ptr<grpc::AuthMetadataProcessor>& processor) override;
private:
grpc_server_credentials* creds_;
std::unique_ptr<AuthMetadataProcessorAyncWrapper> processor_;
std::unique_ptr<grpc::AuthMetadataProcessorAyncWrapper> processor_;
};
} // namespace grpc
} // namespace grpc_impl
#endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H

@ -16,10 +16,10 @@
*
*/
#include <grpcpp/security/server_credentials.h>
#include <grpcpp/security/server_credentials_impl.h>
namespace grpc {
namespace grpc_impl {
ServerCredentials::~ServerCredentials() {}
} // namespace grpc
} // namespace grpc_impl

@ -24,6 +24,7 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpcpp/security/server_credentials.h>
#include "test/core/end2end/data/ssl_test_data.h"

@ -1007,6 +1007,7 @@ include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
include/grpcpp/server_context.h \

@ -1009,6 +1009,7 @@ include/grpcpp/security/auth_metadata_processor.h \
include/grpcpp/security/auth_metadata_processor_impl.h \
include/grpcpp/security/credentials.h \
include/grpcpp/security/server_credentials.h \
include/grpcpp/security/server_credentials_impl.h \
include/grpcpp/server.h \
include/grpcpp/server_builder.h \
include/grpcpp/server_context.h \

@ -10127,6 +10127,7 @@
"include/grpcpp/security/auth_metadata_processor_impl.h",
"include/grpcpp/security/credentials.h",
"include/grpcpp/security/server_credentials.h",
"include/grpcpp/security/server_credentials_impl.h",
"include/grpcpp/server.h",
"include/grpcpp/server_builder.h",
"include/grpcpp/server_context.h",
@ -10245,6 +10246,7 @@
"include/grpcpp/security/auth_metadata_processor_impl.h",
"include/grpcpp/security/credentials.h",
"include/grpcpp/security/server_credentials.h",
"include/grpcpp/security/server_credentials_impl.h",
"include/grpcpp/server.h",
"include/grpcpp/server_builder.h",
"include/grpcpp/server_context.h",

Loading…
Cancel
Save