Xuanwo commented on code in PR #2203:
URL: 
https://github.com/apache/incubator-opendal/pull/2203#discussion_r1184723786


##########
core/src/services/gdrive/core.rs:
##########
@@ -0,0 +1,202 @@
+// 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.
+
+use std::collections::HashMap;
+use std::fmt::Debug;
+use std::fmt::Formatter;
+use std::sync::Arc;
+
+use crate::raw::HttpClient;
+
+use http::{header, Request, Response};
+use serde::Deserialize;
+use tokio::sync::Mutex;
+
+use crate::{
+    raw::{build_rooted_abs_path, new_request_build_error, AsyncBody, 
IncomingAsyncBody},
+    types::Result,
+};
+
+pub struct GdriveCore {
+    pub root: String,
+    pub access_token: String,
+    pub client: HttpClient,
+    pub path_2_id: Arc<Mutex<HashMap<String, String>>>,
+}
+
+impl Debug for GdriveCore {
+    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+        let mut de = f.debug_struct("GdriveCore");
+        de.field("root", &self.root);
+        de.finish()
+    }
+}
+
+impl GdriveCore {
+    async fn get_abs_root_id(&self) -> String {
+        let root = "root";
+
+        {
+            let cache_guard = self.path_2_id.lock().await;
+            if cache_guard.contains_key(root) {
+                return cache_guard.get(root).unwrap().to_string();
+            }
+        }
+
+        let mut req = 
Request::get("https://www.googleapis.com/drive/v3/files/root";);
+        let auth_header_content = format!("Bearer {}", self.access_token);
+        req = req.header(header::AUTHORIZATION, auth_header_content);
+        let req = req
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+            .unwrap();
+
+        let resp = self.client.send(req).await.unwrap();
+
+        let body_value: GdriveFile =
+            
serde_json::from_slice(&resp.into_body().bytes().await.unwrap()).unwrap();

Review Comment:
   Please don't unwrap here. It's possible that meeting error during reading 
body, we should handle this by converting to `opendal::Error` instead. So does 
for serde_json from_slice.



-- 
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]

Reply via email to