(&self, req: &Request<T>)
| 121 | } |
| 122 | |
| 123 | fn get_ctx<T>(&self, req: &Request<T>) -> Result<Arc<SessionContext>, Status> { |
| 124 | // get the token from the authorization header on Request |
| 125 | let auth = req |
| 126 | .metadata() |
| 127 | .get("authorization") |
| 128 | .ok_or_else(|| Status::internal("No authorization header!"))?; |
| 129 | let str = auth |
| 130 | .to_str() |
| 131 | .map_err(|e| Status::internal(format!("Error parsing header: {e}")))?; |
| 132 | let authorization = str.to_string(); |
| 133 | let bearer = "Bearer "; |
| 134 | if !authorization.starts_with(bearer) { |
| 135 | Err(Status::internal("Invalid auth header!"))?; |
| 136 | } |
| 137 | let auth = authorization[bearer.len()..].to_string(); |
| 138 | |
| 139 | if let Some(context) = self.contexts.get(&auth) { |
| 140 | Ok(context.clone()) |
| 141 | } else { |
| 142 | Err(Status::internal(format!( |
| 143 | "Context handle not found: {auth}" |
| 144 | )))? |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | fn get_plan(&self, handle: &str) -> Result<LogicalPlan, Status> { |
| 149 | if let Some(plan) = self.statements.get(handle) { |
no test coverage detected