Avoid making I/O methods const

This commit is contained in:
Antoine Pitrou committed 2019-04-11 15:31:53 +02:00
1 parent 48d42485fe
commit 067ff3217f
11 files changed
+61 -64

No files matched your search

+3 -3
View File
@@ -84,7 +84,7 @@ class GrpcClientAuthSender : public ClientAuthSender {
stream)
: stream_(stream) {}
Status Write(const std::string& token) const override {
Status Write(const std::string& token) override {
pb::HandshakeRequest response;
response.set_payload(token);
if (stream_->Write(response)) {
@@ -106,7 +106,7 @@ class GrpcClientAuthReader : public ClientAuthReader {
stream)
: stream_(stream) {}
Status Read(std::string* token) const override {
Status Read(std::string* token) override {
pb::HandshakeResponse request;
if (stream_->Read(&request)) {
*token = std::move(*request.release_payload());
@@ -244,7 +244,7 @@ class FlightClient::FlightClientImpl {
stream = stub_->Handshake(&context);
GrpcClientAuthSender outgoing{stream};
GrpcClientAuthReader incoming{stream};
RETURN_NOT_OK(auth_handler_->Authenticate(outgoing, incoming));
RETURN_NOT_OK(auth_handler_->Authenticate(&outgoing, &incoming));
RETURN_NOT_OK(internal::FromGrpcStatus(stream->Finish()));
return Status::OK();
}
+3 -4
View File
@@ -31,7 +31,7 @@ namespace flight {
class ARROW_EXPORT ClientAuthReader {
public:
virtual ~ClientAuthReader() = default;
virtual Status Read(std::string* response) const = 0;
virtual Status Read(std::string* response) = 0;
};
/// \brief A writer for messages to the server during an
@@ -39,7 +39,7 @@ class ARROW_EXPORT ClientAuthReader {
class ARROW_EXPORT ClientAuthSender {
public:
virtual ~ClientAuthSender() = default;
virtual Status Write(const std::string& token) const = 0;
virtual Status Write(const std::string& token) = 0;
};
/// \brief An authentication implementation for a Flight service.
@@ -52,8 +52,7 @@ class ARROW_EXPORT ClientAuthHandler {
/// \brief Authenticate the client on initial connection. The client
/// can send messages to/read responses from the server at any time.
/// \return Status OK if authenticated successfully
virtual Status Authenticate(const ClientAuthSender& outgoing,
const ClientAuthReader& incoming) = 0;
virtual Status Authenticate(ClientAuthSender* outgoing, ClientAuthReader* incoming) = 0;
/// \brief Get a per-call token.
/// \param[out] token The token to send to the server.
virtual Status GetToken(std::string* token) = 0;
+3 -3
View File
@@ -112,7 +112,7 @@ class GrpcServerAuthReader : public ServerAuthReader {
grpc::ServerReaderWriter<pb::HandshakeResponse, pb::HandshakeRequest>* stream)
: stream_(stream) {}
Status Read(std::string* token) const override {
Status Read(std::string* token) override {
pb::HandshakeRequest request;
if (stream_->Read(&request)) {
*token = std::move(*request.release_payload());
@@ -131,7 +131,7 @@ class GrpcServerAuthSender : public ServerAuthSender {
grpc::ServerReaderWriter<pb::HandshakeResponse, pb::HandshakeRequest>* stream)
: stream_(stream) {}
Status Write(const std::string& token) const override {
Status Write(const std::string& token) override {
pb::HandshakeResponse response;
response.set_payload(token);
if (stream_->Write(response)) {
@@ -232,7 +232,7 @@ class FlightServiceImpl : public FlightService::Service {
}
GrpcServerAuthSender outgoing{stream};
GrpcServerAuthReader incoming{stream};
GRPC_RETURN_NOT_OK(auth_handler_->Authenticate(outgoing, incoming));
GRPC_RETURN_NOT_OK(auth_handler_->Authenticate(&outgoing, &incoming));
return grpc::Status::OK;
}
+2 -2
View File
@@ -23,8 +23,8 @@ namespace flight {
ServerAuthHandler::~ServerAuthHandler() {}
NoOpAuthHandler::~NoOpAuthHandler() {}
Status NoOpAuthHandler::Authenticate(const ServerAuthSender& outgoing,
const ServerAuthReader& incoming) {
Status NoOpAuthHandler::Authenticate(ServerAuthSender* outgoing,
ServerAuthReader* incoming) {
return Status::OK();
}
+4 -6
View File
@@ -33,7 +33,7 @@ namespace flight {
class ARROW_EXPORT ServerAuthReader {
public:
virtual ~ServerAuthReader() = default;
virtual Status Read(std::string* token) const = 0;
virtual Status Read(std::string* token) = 0;
};
/// \brief A writer for messages to the client during an
@@ -41,7 +41,7 @@ class ARROW_EXPORT ServerAuthReader {
class ARROW_EXPORT ServerAuthSender {
public:
virtual ~ServerAuthSender() = default;
virtual Status Write(const std::string& message) const = 0;
virtual Status Write(const std::string& message) = 0;
};
/// \brief An authentication implementation for a Flight service.
@@ -55,8 +55,7 @@ class ARROW_EXPORT ServerAuthHandler {
virtual ~ServerAuthHandler();
/// \brief Authenticate the client on initial connection. The server
/// can send and read responses from the client at any time.
virtual Status Authenticate(const ServerAuthSender& outgoing,
const ServerAuthReader& incoming) = 0;
virtual Status Authenticate(ServerAuthSender* outgoing, ServerAuthReader* incoming) = 0;
/// \brief Validate a per-call client token.
/// \param[in] token The client token. May be the empty string if
/// the client does not provide a token.
@@ -71,8 +70,7 @@ class ARROW_EXPORT ServerAuthHandler {
class ARROW_EXPORT NoOpAuthHandler : public ServerAuthHandler {
public:
~NoOpAuthHandler();
Status Authenticate(const ServerAuthSender& outgoing,
const ServerAuthReader& incoming) override;
Status Authenticate(ServerAuthSender* outgoing, ServerAuthReader* incoming) override;
Status IsValid(const std::string& token, std::string* peer_identity) override;
};
+12 -8
View File
@@ -216,15 +216,17 @@ std::vector<ActionType> ExampleActionTypes() {
TestServerAuthHandler::TestServerAuthHandler(const std::string& username,
const std::string& password)
: username_(username), password_(password) {}
TestServerAuthHandler::~TestServerAuthHandler() {}
Status TestServerAuthHandler::Authenticate(const ServerAuthSender& outgoing,
const ServerAuthReader& incoming) {
Status TestServerAuthHandler::Authenticate(ServerAuthSender* outgoing,
ServerAuthReader* incoming) {
std::string token;
RETURN_NOT_OK(incoming.Read(&token));
RETURN_NOT_OK(incoming->Read(&token));
if (token != password_) {
return Status::Invalid("Invalid password");
}
RETURN_NOT_OK(outgoing.Write(username_));
RETURN_NOT_OK(outgoing->Write(username_));
return Status::OK();
}
@@ -240,12 +242,14 @@ Status TestServerAuthHandler::IsValid(const std::string& token,
TestClientAuthHandler::TestClientAuthHandler(const std::string& username,
const std::string& password)
: username_(username), password_(password) {}
TestClientAuthHandler::~TestClientAuthHandler() {}
Status TestClientAuthHandler::Authenticate(const ClientAuthSender& outgoing,
const ClientAuthReader& incoming) {
RETURN_NOT_OK(outgoing.Write(password_));
Status TestClientAuthHandler::Authenticate(ClientAuthSender* outgoing,
ClientAuthReader* incoming) {
RETURN_NOT_OK(outgoing->Write(password_));
std::string username;
RETURN_NOT_OK(incoming.Read(&username));
RETURN_NOT_OK(incoming->Read(&username));
if (username != username_) {
return Status::Invalid("Invalid username");
}
+2 -4
View File
@@ -139,8 +139,7 @@ class ARROW_EXPORT TestServerAuthHandler : public ServerAuthHandler {
explicit TestServerAuthHandler(const std::string& username,
const std::string& password);
~TestServerAuthHandler();
Status Authenticate(const ServerAuthSender& outgoing,
const ServerAuthReader& incoming) override;
Status Authenticate(ServerAuthSender* outgoing, ServerAuthReader* incoming) override;
Status IsValid(const std::string& token, std::string* peer_identity) override;
private:
@@ -153,8 +152,7 @@ class ARROW_EXPORT TestClientAuthHandler : public ClientAuthHandler {
explicit TestClientAuthHandler(const std::string& username,
const std::string& password);
~TestClientAuthHandler();
Status Authenticate(const ClientAuthSender& outgoing,
const ClientAuthReader& incoming) override;
Status Authenticate(ClientAuthSender* outgoing, ClientAuthReader* incoming) override;
Status GetToken(std::string* token) override;
private:
+4 -6
View File
@@ -33,9 +33,8 @@ PyServerAuthHandler::PyServerAuthHandler(PyObject* handler,
handler_.reset(handler);
}
Status PyServerAuthHandler::Authenticate(
const arrow::flight::ServerAuthSender& outgoing,
const arrow::flight::ServerAuthReader& incoming) {
Status PyServerAuthHandler::Authenticate(arrow::flight::ServerAuthSender* outgoing,
arrow::flight::ServerAuthReader* incoming) {
PyAcquireGIL lock;
vtable_.authenticate(handler_.obj(), outgoing, incoming);
return CheckPyError();
@@ -55,9 +54,8 @@ PyClientAuthHandler::PyClientAuthHandler(PyObject* handler,
handler_.reset(handler);
}
Status PyClientAuthHandler::Authenticate(
const arrow::flight::ClientAuthSender& outgoing,
const arrow::flight::ClientAuthReader& incoming) {
Status PyClientAuthHandler::Authenticate(arrow::flight::ClientAuthSender* outgoing,
arrow::flight::ClientAuthReader* incoming) {
PyAcquireGIL lock;
vtable_.authenticate(handler_.obj(), outgoing, incoming);
return CheckPyError();
+8 -8
View File
@@ -62,16 +62,16 @@ class ARROW_PYTHON_EXPORT PyFlightServerVtable {
class ARROW_PYTHON_EXPORT PyServerAuthHandlerVtable {
public:
std::function<void(PyObject*, const arrow::flight::ServerAuthSender&,
const arrow::flight::ServerAuthReader&)>
std::function<void(PyObject*, arrow::flight::ServerAuthSender*,
arrow::flight::ServerAuthReader*)>
authenticate;
std::function<void(PyObject*, const std::string&, std::string*)> is_valid;
};
class ARROW_PYTHON_EXPORT PyClientAuthHandlerVtable {
public:
std::function<void(PyObject*, const arrow::flight::ClientAuthSender&,
const arrow::flight::ClientAuthReader&)>
std::function<void(PyObject*, arrow::flight::ClientAuthSender*,
arrow::flight::ClientAuthReader*)>
authenticate;
std::function<void(PyObject*, std::string*)> get_token;
};
@@ -80,8 +80,8 @@ class ARROW_PYTHON_EXPORT PyClientAuthHandlerVtable {
class ARROW_PYTHON_EXPORT PyServerAuthHandler : public arrow::flight::ServerAuthHandler {
public:
explicit PyServerAuthHandler(PyObject* handler, PyServerAuthHandlerVtable vtable);
Status Authenticate(const arrow::flight::ServerAuthSender& outgoing,
const arrow::flight::ServerAuthReader& incoming) override;
Status Authenticate(arrow::flight::ServerAuthSender* outgoing,
arrow::flight::ServerAuthReader* incoming) override;
Status IsValid(const std::string& token, std::string* peer_identity) override;
private:
@@ -93,8 +93,8 @@ class ARROW_PYTHON_EXPORT PyServerAuthHandler : public arrow::flight::ServerAuth
class ARROW_PYTHON_EXPORT PyClientAuthHandler : public arrow::flight::ClientAuthHandler {
public:
explicit PyClientAuthHandler(PyObject* handler, PyClientAuthHandlerVtable vtable);
Status Authenticate(const arrow::flight::ClientAuthSender& outgoing,
const arrow::flight::ClientAuthReader& incoming) override;
Status Authenticate(arrow::flight::ClientAuthSender* outgoing,
arrow::flight::ClientAuthReader* incoming) override;
Status GetToken(std::string* token) override;
private:
+16 -16
View File
@@ -508,7 +508,7 @@ cdef class ServerCallContext:
cdef class ServerAuthReader:
"""A reader for messages from the client during an auth handshake."""
cdef:
const CServerAuthReader* reader
CServerAuthReader* reader
def read(self):
cdef c_string token
@@ -529,17 +529,17 @@ cdef class ServerAuthReader:
self.reader = NULL
@staticmethod
cdef ServerAuthReader wrap(const CServerAuthReader& reader):
cdef ServerAuthReader wrap(CServerAuthReader* reader):
cdef ServerAuthReader result = \
ServerAuthReader.__new__(ServerAuthReader)
result.reader = &reader
result.reader = reader
return result
cdef class ServerAuthSender:
"""A writer for messages to the client during an auth handshake."""
cdef:
const CServerAuthSender* sender
CServerAuthSender* sender
def write(self, message):
cdef c_string c_message = tobytes(message)
@@ -559,17 +559,17 @@ cdef class ServerAuthSender:
self.sender = NULL
@staticmethod
cdef ServerAuthSender wrap(const CServerAuthSender& sender):
cdef ServerAuthSender wrap(CServerAuthSender* sender):
cdef ServerAuthSender result = \
ServerAuthSender.__new__(ServerAuthSender)
result.sender = &sender
result.sender = sender
return result
cdef class ClientAuthReader:
"""A reader for messages from the server during an auth handshake."""
cdef:
const CClientAuthReader* reader
CClientAuthReader* reader
def read(self):
cdef c_string token
@@ -590,17 +590,17 @@ cdef class ClientAuthReader:
self.reader = NULL
@staticmethod
cdef ClientAuthReader wrap(const CClientAuthReader& reader):
cdef ClientAuthReader wrap(CClientAuthReader* reader):
cdef ClientAuthReader result = \
ClientAuthReader.__new__(ClientAuthReader)
result.reader = &reader
result.reader = reader
return result
cdef class ClientAuthSender:
"""A writer for messages to the server during an auth handshake."""
cdef:
const CClientAuthSender* sender
CClientAuthSender* sender
def write(self, message):
cdef c_string c_message = tobytes(message)
@@ -620,10 +620,10 @@ cdef class ClientAuthSender:
self.sender = NULL
@staticmethod
cdef ClientAuthSender wrap(const CClientAuthSender& sender):
cdef ClientAuthSender wrap(CClientAuthSender* sender):
cdef ClientAuthSender result = \
ClientAuthSender.__new__(ClientAuthSender)
result.sender = &sender
result.sender = sender
return result
@@ -792,8 +792,8 @@ cdef void _list_actions(void* self, const CServerCallContext& context,
actions.push_back(action_type)
cdef void _server_authenticate(void* self, const CServerAuthSender& outgoing,
const CServerAuthReader& incoming) except *:
cdef void _server_authenticate(void* self, CServerAuthSender* outgoing,
CServerAuthReader* incoming) except *:
"""Callback for implementing authentication in Python."""
sender = ServerAuthSender.wrap(outgoing)
reader = ServerAuthReader.wrap(incoming)
@@ -812,8 +812,8 @@ cdef void _is_valid(void* self, const c_string& token,
peer_identity[0] = c_result
cdef void _client_authenticate(void* self, const CClientAuthSender& outgoing,
const CClientAuthReader& incoming) except *:
cdef void _client_authenticate(void* self, CClientAuthSender* outgoing,
CClientAuthReader* incoming) except *:
"""Callback for implementing authentication in Python."""
sender = ClientAuthSender.wrap(outgoing)
reader = ClientAuthReader.wrap(incoming)
+4 -4
View File
@@ -181,11 +181,11 @@ ctypedef void cb_list_actions(object, const CServerCallContext&,
vector[CActionType]*)
ctypedef void cb_result_next(object, unique_ptr[CResult]*)
ctypedef void cb_data_stream_next(object, CFlightPayload*)
ctypedef void cb_server_authenticate(object, const CServerAuthSender&,
const CServerAuthReader&)
ctypedef void cb_server_authenticate(object, CServerAuthSender*,
CServerAuthReader*)
ctypedef void cb_is_valid(object, const c_string&, c_string*)
ctypedef void cb_client_authenticate(object, const CClientAuthSender&,
const CClientAuthReader&)
ctypedef void cb_client_authenticate(object, CClientAuthSender*,
CClientAuthReader*)
ctypedef void cb_get_token(object, c_string*)
cdef extern from "arrow/python/flight.h" namespace "arrow::py::flight" nogil: