github-actions[bot] commented on code in PR #24772: URL: https://github.com/apache/doris/pull/24772#discussion_r1334368224
########## be/src/service/arrow_flight/auth_server_middleware.cpp: ########## @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 "service/arrow_flight/auth_server_middleware.h" + +#include "service/arrow_flight/call_header_utils.h" + +namespace doris { +namespace flight { + +void NoOpHeaderAuthServerMiddleware::SendingHeaders( + arrow::flight::AddCallHeaders* outgoing_headers) { + outgoing_headers->AddHeader(kAuthHeader, std::string(kBearerPrefix) + kBearerDefaultToken); +} + +arrow::Status NoOpHeaderAuthServerMiddlewareFactory::StartCall( + const arrow::flight::CallInfo& info, const arrow::flight::ServerCallContext& context, + std::shared_ptr<arrow::flight::ServerMiddleware>* middleware) { + std::string username, password; Review Comment: warning: variable 'username' is not initialized [cppcoreguidelines-init-variables] ```suggestion std::string username = 0, password; ``` ########## be/src/service/arrow_flight/auth_server_middleware.cpp: ########## @@ -0,0 +1,55 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 "service/arrow_flight/auth_server_middleware.h" + +#include "service/arrow_flight/call_header_utils.h" + +namespace doris { +namespace flight { + +void NoOpHeaderAuthServerMiddleware::SendingHeaders( + arrow::flight::AddCallHeaders* outgoing_headers) { + outgoing_headers->AddHeader(kAuthHeader, std::string(kBearerPrefix) + kBearerDefaultToken); +} + +arrow::Status NoOpHeaderAuthServerMiddlewareFactory::StartCall( + const arrow::flight::CallInfo& info, const arrow::flight::ServerCallContext& context, + std::shared_ptr<arrow::flight::ServerMiddleware>* middleware) { + std::string username, password; + ParseBasicHeader(context.incoming_headers(), username, password); + *middleware = std::make_shared<NoOpHeaderAuthServerMiddleware>(); + return arrow::Status::OK(); +} + +void NoOpBearerAuthServerMiddleware::SendingHeaders( + arrow::flight::AddCallHeaders* outgoing_headers) { + std::string bearer_token = Review Comment: warning: variable 'bearer_token' is not initialized [cppcoreguidelines-init-variables] ```suggestion std::string bearer_token = 0 = ``` ########## be/src/service/arrow_flight/call_header_utils.h: ########## @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#pragma once + +#include "arrow/flight/types.h" Review Comment: warning: 'arrow/flight/types.h' file not found [clang-diagnostic-error] ```cpp #include "arrow/flight/types.h" ^ ``` ########## be/src/service/arrow_flight/auth_server_middleware.h: ########## @@ -0,0 +1,88 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#pragma once + +#include <arrow/status.h> Review Comment: warning: 'arrow/status.h' file not found [clang-diagnostic-error] ```cpp #include <arrow/status.h> ^ ``` ########## be/src/service/arrow_flight/call_header_utils.h: ########## @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#pragma once + +#include "arrow/flight/types.h" +#include "arrow/util/base64.h" + +namespace doris { +namespace flight { + +const char kBearerDefaultToken[] = "bearertoken"; +const char kBasicPrefix[] = "Basic "; +const char kBearerPrefix[] = "Bearer "; +const char kAuthHeader[] = "authorization"; + +// Function to look in CallHeaders for a key that has a value starting with prefix and +// return the rest of the value after the prefix. +std::string FindKeyValPrefixInCallHeaders(const arrow::flight::CallHeaders& incoming_headers, + const std::string& key, const std::string& prefix) { + // Lambda function to compare characters without case sensitivity. + auto char_compare = [](const char& char1, const char& char2) { + return (::toupper(char1) == ::toupper(char2)); + }; + + auto iter = incoming_headers.find(key); + if (iter == incoming_headers.end()) { + return ""; + } + const std::string val(iter->second); + if (val.size() > prefix.length()) { + if (std::equal(val.begin(), val.begin() + prefix.length(), prefix.begin(), char_compare)) { + return val.substr(prefix.length()); + } + } + return ""; +} + +void ParseBasicHeader(const arrow::flight::CallHeaders& incoming_headers, std::string& username, + std::string& password) { + std::string encoded_credentials = Review Comment: warning: variable 'encoded_credentials' is not initialized [cppcoreguidelines-init-variables] ```suggestion std::string encoded_credentials = 0 = ``` ########## be/src/service/arrow_flight/call_header_utils.h: ########## @@ -0,0 +1,63 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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. + +#pragma once + +#include "arrow/flight/types.h" +#include "arrow/util/base64.h" + +namespace doris { +namespace flight { + +const char kBearerDefaultToken[] = "bearertoken"; +const char kBasicPrefix[] = "Basic "; +const char kBearerPrefix[] = "Bearer "; +const char kAuthHeader[] = "authorization"; + +// Function to look in CallHeaders for a key that has a value starting with prefix and +// return the rest of the value after the prefix. +std::string FindKeyValPrefixInCallHeaders(const arrow::flight::CallHeaders& incoming_headers, + const std::string& key, const std::string& prefix) { + // Lambda function to compare characters without case sensitivity. + auto char_compare = [](const char& char1, const char& char2) { + return (::toupper(char1) == ::toupper(char2)); + }; + + auto iter = incoming_headers.find(key); + if (iter == incoming_headers.end()) { + return ""; + } + const std::string val(iter->second); Review Comment: warning: variable 'val' is not initialized [cppcoreguidelines-init-variables] ```suggestion const std::string val = 0(iter->second); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
