MCPcopy Create free account
hub / github.com/apache/arrow-rs / do_handshake

Method do_handshake

arrow-flight/examples/flight_sql_server.rs:150–200  ·  view source on GitHub ↗
(
        &self,
        request: Request<Streaming<HandshakeRequest>>,
    )

Source from the content-addressed store, hash-verified

148 type FlightService = FlightSqlServiceImpl;
149
150 async fn do_handshake(
151 &self,
152 request: Request<Streaming<HandshakeRequest>>,
153 ) -> Result<
154 Response<Pin<Box<dyn Stream<Item = Result<HandshakeResponse, Status>> + Send>>>,
155 Status,
156 > {
157 let basic = "Basic ";
158 let authorization = request
159 .metadata()
160 .get("authorization")
161 .ok_or_else(|| Status::invalid_argument("authorization field not present"))?
162 .to_str()
163 .map_err(|e| status!("authorization not parsable", e))?;
164 if !authorization.starts_with(basic) {
165 Err(Status::invalid_argument(format!(
166 "Auth type not implemented: {authorization}"
167 )))?;
168 }
169 let base64 = &authorization[basic.len()..];
170 let bytes = BASE64_STANDARD
171 .decode(base64)
172 .map_err(|e| status!("authorization not decodable", e))?;
173 let str = str::from_utf8(&bytes).map_err(|e| status!("authorization not parsable", e))?;
174 let parts: Vec<_> = str.split(':').collect();
175 let (user, pass) = match parts.as_slice() {
176 [user, pass] => (user, pass),
177 _ => Err(Status::invalid_argument(
178 "Invalid authorization header".to_string(),
179 ))?,
180 };
181 if user != &"admin" || pass != &"password" {
182 Err(Status::unauthenticated("Invalid credentials!"))?
183 }
184
185 let result = HandshakeResponse {
186 protocol_version: 0,
187 payload: FAKE_TOKEN.into(),
188 };
189 let result = Ok(result);
190 let output = futures::stream::iter(vec![result]);
191
192 let token = format!("Bearer {FAKE_TOKEN}");
193 let mut response: Response<Pin<Box<dyn Stream<Item = _> + Send>>> =
194 Response::new(Box::pin(output));
195 response.metadata_mut().append(
196 "authorization",
197 MetadataValue::from_str(token.as_str()).unwrap(),
198 );
199 return Ok(response);
200 }
201
202 async fn do_get_fallback(
203 &self,

Callers

nothing calls this directly

Calls 10

collectMethod · 0.80
getMethod · 0.45
metadataMethod · 0.45
lenMethod · 0.45
decodeMethod · 0.45
splitMethod · 0.45
as_sliceMethod · 0.45
appendMethod · 0.45
metadata_mutMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected