You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by su...@apache.org on 2023/08/23 14:35:11 UTC
[incubator-opendal] 01/02: stash
This is an automated email from the ASF dual-hosted git repository.
suyanhanx pushed a commit to branch gdrive-auth
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 6fe1e966afe06da3a2ec4a777ca33b00e7f8330e
Author: suyanhanx <su...@gmail.com>
AuthorDate: Wed Aug 23 20:27:53 2023 +0800
stash
Signed-off-by: suyanhanx <su...@gmail.com>
---
core/src/services/dropbox/builder.rs | 2 +-
core/src/services/gdrive/builder.rs | 23 ++++++++++++++++-------
core/src/services/gdrive/core.rs | 12 ++++++++++++
3 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/core/src/services/dropbox/builder.rs b/core/src/services/dropbox/builder.rs
index d31b26a75..0d4ecd1a8 100644
--- a/core/src/services/dropbox/builder.rs
+++ b/core/src/services/dropbox/builder.rs
@@ -112,7 +112,7 @@ pub struct DropboxBuilder {
impl Debug for DropboxBuilder {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("Builder").finish()
+ f.debug_struct("Builder").field("root", &self.root).finish()
}
}
diff --git a/core/src/services/gdrive/builder.rs b/core/src/services/gdrive/builder.rs
index 9a7a3b387..aa1a4b8d6 100644
--- a/core/src/services/gdrive/builder.rs
+++ b/core/src/services/gdrive/builder.rs
@@ -79,8 +79,14 @@ use crate::*;
/// ```
#[derive(Default)]
pub struct GdriveBuilder {
- access_token: Option<String>,
root: Option<String>,
+
+ access_token: Option<String>,
+
+ refresh_token: Option<String>,
+ client_id: Option<String>,
+ client_secret: Option<String>,
+
http_client: Option<HttpClient>,
}
@@ -91,18 +97,21 @@ impl Debug for GdriveBuilder {
}
impl GdriveBuilder {
- /// default: no access token, which leads to failure
- pub fn access_token(&mut self, access_token: &str) -> &mut Self {
- self.access_token = Some(access_token.to_string());
- self
- }
-
/// Set root path of GoogleDrive folder.
pub fn root(&mut self, root: &str) -> &mut Self {
self.root = Some(root.to_string());
self
}
+ /// Access token is used for temporary access to the GoogleDrive API.
+ ///
+ /// You can get the access token from [GoogleDrive App Console](https://console.cloud.google.com/apis/credentials)
+ pub fn access_token(&mut self, access_token: &str) -> &mut Self {
+ self.access_token = Some(access_token.to_string());
+ self
+ }
+
+
/// Specify the http client that used by this service.
///
/// # Notes
diff --git a/core/src/services/gdrive/core.rs b/core/src/services/gdrive/core.rs
index acf8b0747..a4dcb9fc3 100644
--- a/core/src/services/gdrive/core.rs
+++ b/core/src/services/gdrive/core.rs
@@ -21,6 +21,8 @@ use std::fmt::Formatter;
use std::sync::Arc;
use bytes;
+use chrono::DateTime;
+use chrono::Utc;
use http::header;
use http::Request;
use http::Response;
@@ -409,6 +411,16 @@ impl GdriveCore {
}
}
+#[derive(Clone)]
+pub struct GdriveSigner {
+ pub client_id: String,
+ pub client_secret: String,
+ pub refresh_token: String,
+
+ pub access_token: String,
+ pub expires_in: DateTime<Utc>,
+}
+
// This is the file struct returned by the Google Drive API.
// This is a complex struct, but we only add the fields we need.
// refer to https://developers.google.com/drive/api/reference/rest/v3/files#File