avantgardnerio commented on code in PR #2211:
URL: https://github.com/apache/arrow-rs/pull/2211#discussion_r933016516
##########
arrow-flight/examples/flight_sql_server.rs:
##########
@@ -41,6 +43,52 @@ pub struct FlightSqlServiceImpl {}
#[tonic::async_trait]
impl FlightSqlService for FlightSqlServiceImpl {
type FlightService = FlightSqlServiceImpl;
+
+ async fn do_handshake(
+ &self,
+ request: Request<Streaming<HandshakeRequest>>,
+ ) -> Result<
+ Response<Pin<Box<dyn Stream<Item = Result<HandshakeResponse, Status>>
+ Send>>>,
+ Status,
+ > {
+ let basic = "Basic ";
+ let authorization = request
+ .metadata()
+ .get("authorization")
+ .ok_or(Status::invalid_argument("authorization field not
present"))?
+ .to_str()
+ .map_err(|_| Status::invalid_argument("authorization not
parsable"))?;
+ if !authorization.starts_with(basic) {
+ Err(Status::invalid_argument(format!(
+ "Auth type not implemented: {}",
+ authorization
+ )))?;
+ }
+ let base64 = &authorization[basic.len()..];
+ let bytes = base64::decode(base64)
+ .map_err(|_| Status::invalid_argument("authorization not
parsable"))?;
+ let str = String::from_utf8(bytes)
+ .map_err(|_| Status::invalid_argument("authorization not
parsable"))?;
+ let parts: Vec<_> = str.split(":").collect();
+ if parts.len() != 2 {
+ Err(Status::invalid_argument(format!(
+ "Invalid authorization header"
+ )))?;
+ }
+ let user = parts[0];
+ let pass = parts[1];
+ if user != "admin" || pass != "password" {
+ Err(Status::unauthenticated("Invalid credentials!"))?
+ }
+ let result = HandshakeResponse {
+ protocol_version: 0,
+ payload: "random_uuid_token".as_bytes().to_vec(),
+ };
+ let result = Ok(result);
+ let output = futures::stream::iter(vec![result]);
+ return Ok(Response::new(Box::pin(output)));
+ }
+
Review Comment:
When we have TPC-H up and running, I'll come back around to this and look at
the main issues: cloning the server state & testing. Thanks for your feedback
and helping get it merged!
--
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]