You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "Ji-Xinyou (via GitHub)" <gi...@apache.org> on 2023/04/25 12:10:50 UTC

[GitHub] [incubator-opendal] Ji-Xinyou opened a new pull request, #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Ji-Xinyou opened a new pull request, #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119

   This PR supports Supabase backend using its `storage api`, check [this](https://supabase.github.io/storage-api/).
   
   For anyone want to test this, you can refer the rust-doc. But you have to use `supabase` command line tool provided by supabase to setup corresponding docker containers, check [here](https://supabase.com/docs/guides/cli/local-development).
   
   ## Some misc
   
   The Supabase has two kinds of key, service_key(Secret Key) and anon_key(Client key), this PR set the key up in two ways.
   - In Builder
   - In environment variable
   
   In general, the builder takes precedence over env_var, and then the secret key takes precedence over anon_key since it has more privileges.
   
   This is already a big PR, although it is possible to implement operation like scan and list, I am planning to do so in future PRs.
   
   ### misc's misc
   During the process of implementation, I found that every service's implementation contains some duplicate codes, maybe there are some magics to reduce them?


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176493974


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   A service should not declare it will need env like `OPENDAL_XXX`. It doesn't work like this.
   
   ---
   
   Service should declare it need config `abc`, and
   
   - provide a public function called `abc()`.
   - load `abc` in `from_map` and call `abc()` to set it.
   - And finlly, `from_env` will load all `OPENDAL_SUPABASE_XXX` from env and call `from_map`.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176526604


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > What I want to say is that, if these backends do not use `reqsign`, then they lose the ability to load properties from the environment variable, right?
   
   Supabase doesn't have properties to load from env. It's a simple service which only requires a url and key.
   
   ---
   
   We should add this feature once supabase declares that it will load key from `SUPABASE_KEY`.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176507492


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   I prefer to keep consist with supabase's SDK, call it `key` and return error if users trying to visit unpublic resource.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176510126


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   We can mention the `service_key` and `anon_key` in the docs of `fn key()` to let users know the difference.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176541049


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > OpenDAL will load config from env if `service providers` declares their standards like `AWS_ACCESS_KEY_ID`. And OpenDAL will not expose it's internal env to users.
   
   Got it. Instead, we can give developers some notice when implementing backend. @Xuanwo



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#issuecomment-1525574465

   Bravo!


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176539851


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   For example:
   
   ![image](https://user-images.githubusercontent.com/5351546/234295831-721af13c-9bf2-4063-895a-4ba888fbc675.png)
   



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177488601


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > Leave to users to decide. They know what bucket they are visiting. It's not opendal's job.
   > 
   > We just need to make our behaviour clear.
   
   The problem is that the user cannot decide which url to choose. Supabase uses different url to access secret buckets and public buckets, and we only provide a unified interface of `op.read()`
   
   The url for authorized bucket is `/object/authorized/{bucket_name}/{wild_card}`, for the public bucket is `/object/public/{bucket_name}/{wild_card}`. We have to request to either one of them or both of them, how can user decide which one to call through `op.read()`?



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176551597


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > Instead, we can give developers some notice when implementing backend.
   
   Nice idea. Maybe we can add some notes in the super duck service docs.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176573665


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > Hi, supabase doesn't allow calling `write` without `authorization`. Please try `read` a public bucket.
   
   Oops, I got your point. You are right.
   
   Another case, suppose we are calling read() on a path, the underlying operation would send a get request to a url.
   The authorized url and the public url is different, to be more specific, `/authenticated/bucket/wildcard` and /`public/bucket/wildcard`.
   Which function should we call? Since we are not bookeeping the key is anon_key or service_key.
   
   IMO, we should call the `public` one first, if failed, then call the `authenticated` one.
   
   What do you think?



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#issuecomment-1521685760

   > During the process of implementation, I found that every service's implementation contains some duplicate codes, maybe there are some magics to reduce them?
   
   This is unnecessary. OpenDAL's abstraction is already sufficiently complex. Instead of adding more abstraction, I would rather duplicate some code.


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176566520


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Hi, supabase doesn't allow calling `write` without `authorization` (which makes sense right? You don't want anonymouse to write data in your bucket even it's public). Please try `read` a public bucket.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176536841


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > I mean documenting on the differences of anon_key and service_key.
   
   Oh, sorry. I thought we still talking about the env loading logic.
   
   And yes, we need to let users know about the difference of `anon_key` and `service_key`.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#issuecomment-1521687767

   > This is unnecessary. OpenDAL's abstraction is already sufficiently complex. Instead of adding more abstraction, I would rather duplicate some code.
   
   Agreed. And I have to admit these abstractions are very brilliant.


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177345048


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   We don't need to support that case. It's easier for users to build two operator with different keys.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177482998


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Leave  to users to decide. They know what bucket they are visiting. It's not opendal's job.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176484545


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > We don't need this
   
   If so, how and where to get those envs?
   



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key
+/// - `anon_key`: Set the client key for the backend, this cannot access non-public resources
+///
+/// ## Authorization key setup
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only access public resources while the latter one
+/// can access all resources.
+///
+/// There exists a priority of setting up the authorization keys.
+/// The key set up by builder takes precedence over environment variable, and the service_key
+/// takes precedence over anon_key.
+///
+/// There are two ways of setting up the authorization key, i.e., environment variable and builder.
+/// - The environment variable OPENDAL_SUPABASE_AUTH_ANON_KEY sets up the anon_key.
+/// - The environment variable OPENDAL_SUPABASE_AUTH_SERVICE_KEY sets up the service_role_key.
+///
+/// # Example
+///
+/// ## Basic Setup
+///
+/// ### Using Environment Variable
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     // suppose the environment variable is set
+///     let mut builder = services::Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+///
+/// ### Using Builder
+///
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = services::Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///     // this sets up the anon_key, which means this operator can only access public resource
+///     builder.anon_key("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+#[derive(Default)]
+pub struct SupabaseBuilder {
+    root: Option<String>,
+
+    bucket: String,
+    endpoint: Option<String>,
+
+    service_key: Option<String>,
+    anon_key: Option<String>,
+
+    // todo: optional public, currently true always
+    // todo: optional file_size_limit, currently 0
+    // todo: optional allowed_mime_types, currently only string
+    http_client: Option<HttpClient>,
+}
+
+impl Debug for SupabaseBuilder {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseBuilder")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseBuilder {
+    /// Set root of this backend.
+    ///
+    /// All operations will happen under this root.
+    pub fn root(&mut self, root: &str) -> &mut Self {
+        self.root = if root.is_empty() {
+            None
+        } else {
+            Some(root.to_string())
+        };
+
+        self
+    }
+
+    /// Set bucket name of this backend.
+    pub fn bucket(&mut self, bucket: &str) -> &mut Self {
+        self.bucket = bucket.to_string();
+        self
+    }
+
+    /// Set endpoint of this backend.
+    ///
+    /// Endpoint must be full uri
+    pub fn endpoint(&mut self, endpoint: &str) -> &mut Self {
+        self.endpoint = if endpoint.is_empty() {
+            None
+        } else {
+            Some(endpoint.trim_end_matches('/').to_string())
+        };
+
+        self
+    }
+
+    /// Set the service_role_key for this backend
+    pub fn service_key(&mut self, service_key: &str) -> &mut Self {
+        self.service_key = Some(service_key.to_string());
+        self
+    }
+
+    /// Set the anon_key for this backend
+    pub fn anon_key(&mut self, anon_key: &str) -> &mut Self {
+        self.anon_key = Some(anon_key.to_string());
+        self
+    }
+
+    /// Specify the http client that used by this service.
+    ///
+    /// # Notes
+    ///
+    /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed
+    /// during minor updates.
+    pub fn http_client(&mut self, client: HttpClient) -> &mut Self {
+        self.http_client = Some(client);
+        self
+    }
+}
+
+impl Builder for SupabaseBuilder {
+    const SCHEME: Scheme = Scheme::Supabase;
+    type Accessor = SupabaseBackend;
+
+    fn from_map(map: std::collections::HashMap<String, String>) -> Self {
+        let mut builder = SupabaseBuilder::default();
+
+        map.get("root").map(|v| builder.root(v));
+        map.get("bucket").map(|v| builder.bucket(v));
+        map.get("endpoint").map(|v| builder.endpoint(v));
+        map.get("anon_key").map(|v| builder.anon_key(v));
+        map.get("service_key").map(|v| builder.service_key(v));
+
+        builder
+    }
+
+    fn build(&mut self) -> Result<Self::Accessor> {
+        let root = normalize_root(&self.root.take().unwrap_or_default());
+        debug!("backend use root {}", &root);
+
+        let bucket = &self.bucket;
+
+        let endpoint = self.endpoint.take().unwrap_or_default();
+
+        let http_client = if let Some(client) = self.http_client.take() {
+            client
+        } else {
+            HttpClient::new().map_err(|err| {
+                err.with_operation("Builder::build")
+                    .with_context("service", Scheme::S3)

Review Comment:
   Is there a typo?



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177500260


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > If they want to call public bucket, don't pass a key; otherwise, pass a key.
   
   But this draws the previous problem that, without a key they cannot write to a public bucket.
   
   So you mean, if they want to do so, they should have to construct two operators, one with anon_key to write and another one with no key to read?
   
   I think it would be fine, we can polish that later on.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177626889


##########
core/src/services/supabase/writer.rs:
##########
@@ -0,0 +1,119 @@
+// 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::sync::Arc;
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use http::StatusCode;
+
+use super::core::*;
+use super::error::parse_error;
+use crate::ops::OpWrite;
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseWriter {
+    core: Arc<SupabaseCore>,
+
+    op: OpWrite,
+    path: String,
+
+    buffer: oio::VectorCursor,
+    buffer_size: usize,
+}
+
+impl SupabaseWriter {
+    pub fn new(core: Arc<SupabaseCore>, path: &str, op: OpWrite) -> Self {
+        SupabaseWriter {
+            core,
+            op,
+            path: path.to_string(),
+            buffer: oio::VectorCursor::new(),
+            buffer_size: 8 * 1024 * 1024,
+        }
+    }
+
+    pub async fn upload(&self, bytes: Bytes) -> Result<()> {
+        let mut req = self.core.supabase_upload_object_request(
+            &self.path,
+            Some(bytes.len()),
+            self.op.content_type(),
+            AsyncBody::Bytes(bytes),
+        )?;
+
+        self.core.sign(&mut req)?;
+
+        let resp = self.core.send(req).await?;
+
+        match resp.status() {
+            StatusCode::OK => {
+                resp.into_body().consume().await?;
+                Ok(())
+            }
+            _ => Err(parse_error(resp).await?),
+        }
+    }
+}
+
+#[async_trait]
+impl oio::Write for SupabaseWriter {
+    async fn write(&mut self, bs: Bytes) -> Result<()> {

Review Comment:
   Currently `supabase_upload_object_request()` does overwrite the same path with the same byte. But Supabase does not have something like `upload id`.
   
   I am not sure about the correct behaviors you are pointing out, could you elaborate more on this?



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176531763


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > I think we could write authorization key's behaviors in detail in the rust-doc.
   
   We don't need to write docs for not existing things...



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177641091


##########
core/src/services/supabase/writer.rs:
##########
@@ -0,0 +1,119 @@
+// 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::sync::Arc;
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use http::StatusCode;
+
+use super::core::*;
+use super::error::parse_error;
+use crate::ops::OpWrite;
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseWriter {
+    core: Arc<SupabaseCore>,
+
+    op: OpWrite,
+    path: String,
+
+    buffer: oio::VectorCursor,
+    buffer_size: usize,
+}
+
+impl SupabaseWriter {
+    pub fn new(core: Arc<SupabaseCore>, path: &str, op: OpWrite) -> Self {
+        SupabaseWriter {
+            core,
+            op,
+            path: path.to_string(),
+            buffer: oio::VectorCursor::new(),
+            buffer_size: 8 * 1024 * 1024,
+        }
+    }
+
+    pub async fn upload(&self, bytes: Bytes) -> Result<()> {
+        let mut req = self.core.supabase_upload_object_request(
+            &self.path,
+            Some(bytes.len()),
+            self.op.content_type(),
+            AsyncBody::Bytes(bytes),
+        )?;
+
+        self.core.sign(&mut req)?;
+
+        let resp = self.core.send(req).await?;
+
+        match resp.status() {
+            StatusCode::OK => {
+                resp.into_body().consume().await?;
+                Ok(())
+            }
+            _ => Err(parse_error(resp).await?),
+        }
+    }
+}
+
+#[async_trait]
+impl oio::Write for SupabaseWriter {
+    async fn write(&mut self, bs: Bytes) -> Result<()> {

Review Comment:
   We should check the content length.
   
   Only write content if content length match, otherwise, return Unsupported instead.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo merged pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177498014


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   If they want to call public bucket, don't pass a key; otherwise, pass a key.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1179021857


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,226 @@
+// 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::fmt::Debug;
+
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization
+    /// If loaded, the read operation will always access the nonpublic resources.
+    /// If you want to read the public resources, please do not set the key.
+    pub key: Option<String>,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(
+        root: &str,
+        bucket: &str,
+        endpoint: &str,
+        key: Option<String>,
+        client: HttpClient,
+    ) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            key,
+            http_client: client,
+        }
+    }
+
+    /// Add authorization header to the request if the key is set. Otherwise leave
+    /// the request as-is.
+    pub fn sign<T>(&self, req: &mut Request<T>) -> Result<()> {
+        if let Some(k) = &self.key {
+            let v = HeaderValue::from_str(&format!("Bearer {}", k)).unwrap();
+            req.headers_mut().insert(http::header::AUTHORIZATION, v);
+        }
+        Ok(())
+    }
+}
+
+// requests
+impl SupabaseCore {
+    pub fn supabase_upload_object_request(
+        &self,
+        path: &str,
+        size: Option<usize>,
+        content_type: Option<&str>,
+        body: AsyncBody,
+    ) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        let mut req = Request::post(&url);
+
+        if let Some(size) = size {
+            req = req.header(CONTENT_LENGTH, size)
+        }
+
+        if let Some(mime) = content_type {
+            req = req.header(CONTENT_TYPE, mime)
+        }
+
+        let req = req.body(body).map_err(new_request_build_error)?;
+
+        Ok(req)
+    }
+
+    pub fn supabase_get_object_public_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/public/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/authenticated/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_info_public_request(
+        &self,
+        path: &str,
+    ) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/info/public/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_info_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/info/authenticated/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+}
+
+// core utils
+impl SupabaseCore {
+    pub async fn send(&self, req: Request<AsyncBody>) -> Result<Response<IncomingAsyncBody>> {
+        self.http_client.send(req).await
+    }
+
+    pub async fn supabase_get_object(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        if self.key.is_some() {
+            self.supabase_get_object_auth(path).await
+        } else {
+            self.supabase_get_object_public(path).await
+        }
+    }
+
+    pub async fn supabase_get_object_info(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        if self.key.is_some() {
+            self.supabase_get_object_info_auth(path).await
+        } else {
+            self.supabase_get_object_info_public(path).await
+        }
+    }
+
+    async fn supabase_get_object_public(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_public_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_auth(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_auth_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_info_public(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_info_public_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_info_auth(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_info_auth_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await

Review Comment:
   I mean expand `supabase_get_object_public`, `supabase_get_object_auth`, `supabase_get_object` directly:
   
   ```rust
   pub fn supabase_get_object(&self, path: &str) -> Result<Response<AsyncBody>> {
       let p = build_abs_path(&self.root, path);
   
       let req = if self.core.key {
          xxx
       } else {
          yyy
       };
   
       self.send(req).await
   }
   ```



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176534424


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > > I think we could write authorization key's behaviors in detail in the rust-doc.
   > 
   > We don't need to write docs for not existing things...
   
   I mean documenting on the differences of anon_key and service_key.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176493974


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   A service should not declare it will need env like `OPENDAL_XXX`. It doesn't work like this.
   
   ---
   
   Service should declare it need config `abc`, and
   
   - provide a public function called `abc()`.
   - load `abc` in `from_map` and call `abc()` to set it.
   - And finlly, `from_env` will load all `OPENDAL_SUPABASE_XXX` from env and call `from_map`. (this is only used internally now, and we don't expose it to users as a recommanded way)



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176501975


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   One more thing to talk about. Should be expose API like
   ```Rust
   builder.anon_key();
   builder.service_key();
   ```
   and call `public/auth` API separately based on that.
   
   OR
   
   we only provide
   ```Rust
   builder.auth_key()
   ```
   and let the server return unauthorized when user uses a anon_key to access a unpublic resource.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177332870


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   What if the user loads an `anon_key`, i.e., filling the `key: Option<T>` field. But then it initiates a read, which should we call, the public one or the authenticated one, since we do not know the key is anon or service.
   
   In the SDK provided by supabase, its `read()` can have another argument like `public/authenticated`, but this is not the case for us in OpenDAL since our read operation is started by Operator without that kinds of arguments.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176487963


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > We don't need this
   
   If so, how and where to get those envs?



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176496329


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > ```rust
   > let key = std::env::var("SOME_USER_ASSIGNED_ENV");
   > builder.anon_key(key);
   > ```
   
   It's our application developers own decision and not related to opendal.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176566520


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Hi, supabase doesn't allow calling `write` without `authorization`. Please try read a public bucket.



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Hi, supabase doesn't allow calling `write` without `authorization`. Please try `read` a public bucket.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177475392


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > We don't need to support that case. It's easier for users to build two operator with different keys.
   
   Maybe we have some misunderstanding here.
   Take the following code segment as an example
   ```Rust
   
   let b = services::Supabase::default();
   b.key("some_anon_key");
   
   let op = Operator::new(b);
   
   let _ = op.read("some_key");
   ```
   
   Underlying this read would be the `Accessor::read()`.
   
   At the end of the day, we have to call some functions to actually read the data from Supabase. Currently we have
   `supabase_get_object_auth()` and `supabase_get_object_public()`.
   
   If we choose the auth one, i.e.: `supabase_get_object_auth()`
   - For those does not set the key / set with anon_key: the read will fail even if the bucket is public.
   
   If we choose the public one, i.e.: `supabase_get_object_public()`
   - For those set with service_key, they cannot access the nonpublic bucket even they have their authorized key.
   
   In general, the real problem is, the `Operator`'s read does not specify whether we should call the `supabase_get_object_auth()` or `supabase_get_object_public()`, and if we always choose one of them to be called in the backend. The problem described earlier will happen.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177482998


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Leave  to users to decide. They know what bucket they are visiting. It's not opendal's job.
   
   We just need to make our behaviour clear.
   
   - call auth api if we have key
   - call public if we don't 



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176513861


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > We can mention the `service_key` and `anon_key` in the docs of `fn key()` to let users know the difference.
   
   So, in our implementation. We should try twice on accessing the resource since the urls for `public` and `authorized` are different.
   
   It would look like
   ```shell
   if supabase_get_object_info_public().failed() {
       supabase_get_object_info_auth()
   }
   ```



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176517942


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Set `AUTHORIZATION` header if we have a `key`, otherwise leave it empty. Users should make the decision, we just return the server's response back,



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Set `AUTHORIZATION` header if we have a `key`, otherwise leave it empty. Users should make the decision, we just return the server's response back.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176490487


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > > We don't need this
   > 
   > If so, how and where to get those envs?
   
   Probably w/ the code like
   ```Rust
   let key = std::env::var("SOME_USER_ASSIGNED_ENV");
   builder.anon_key(key);
   ```



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176530413


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > What I want to say is that, if these backends do not use `reqsign`, then they lose the ability to load properties from the environment variable, right? Perhaps our past experience with using services like S3 may have caused some confusion.
   > 
   > So users need to handle this process themselves. We may need to write this behavior into our docs.
   
   I think we could write authorization key's behaviors in detail in the rust-doc.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177498014


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   If they want to call public bucket, don't pass a key; otherwise, pass a key.
   
   They should decide this during building instead of calling.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1179013344


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,226 @@
+// 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::fmt::Debug;
+
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization
+    /// If loaded, the read operation will always access the nonpublic resources.
+    /// If you want to read the public resources, please do not set the key.
+    pub key: Option<String>,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(
+        root: &str,
+        bucket: &str,
+        endpoint: &str,
+        key: Option<String>,
+        client: HttpClient,
+    ) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            key,
+            http_client: client,
+        }
+    }
+
+    /// Add authorization header to the request if the key is set. Otherwise leave
+    /// the request as-is.
+    pub fn sign<T>(&self, req: &mut Request<T>) -> Result<()> {
+        if let Some(k) = &self.key {
+            let v = HeaderValue::from_str(&format!("Bearer {}", k)).unwrap();
+            req.headers_mut().insert(http::header::AUTHORIZATION, v);
+        }
+        Ok(())
+    }
+}
+
+// requests
+impl SupabaseCore {
+    pub fn supabase_upload_object_request(
+        &self,
+        path: &str,
+        size: Option<usize>,
+        content_type: Option<&str>,
+        body: AsyncBody,
+    ) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        let mut req = Request::post(&url);
+
+        if let Some(size) = size {
+            req = req.header(CONTENT_LENGTH, size)
+        }
+
+        if let Some(mime) = content_type {
+            req = req.header(CONTENT_TYPE, mime)
+        }
+
+        let req = req.body(body).map_err(new_request_build_error)?;
+
+        Ok(req)
+    }
+
+    pub fn supabase_get_object_public_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/public/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/authenticated/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_info_public_request(
+        &self,
+        path: &str,
+    ) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/info/public/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_info_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/info/authenticated/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+}
+
+// core utils
+impl SupabaseCore {
+    pub async fn send(&self, req: Request<AsyncBody>) -> Result<Response<IncomingAsyncBody>> {
+        self.http_client.send(req).await
+    }
+
+    pub async fn supabase_get_object(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        if self.key.is_some() {
+            self.supabase_get_object_auth(path).await
+        } else {
+            self.supabase_get_object_public(path).await
+        }
+    }
+
+    pub async fn supabase_get_object_info(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        if self.key.is_some() {
+            self.supabase_get_object_info_auth(path).await
+        } else {
+            self.supabase_get_object_info_public(path).await
+        }
+    }
+
+    async fn supabase_get_object_public(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_public_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_auth(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_auth_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_info_public(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_info_public_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_info_auth(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_info_auth_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await

Review Comment:
   What do you mean by we don't need them, I do not quite understand. The `supabase_get_object` is used in `read` and `supabase_get_object_info` is used in `stat`



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176499244


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > > ```rust
   > > let key = std::env::var("SOME_USER_ASSIGNED_ENV");
   > > builder.anon_key(key);
   > > ```
   > 
   > It's our application developers own decision and not related to opendal.
   
   Yea, that's what I mean, it is the user's own choice on how to call on our key() interface



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176530833


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > So users need to handle this process themselves. We may need to write this behavior into our docs.
   
   We confused different things here. There are three roles involed:
   
   - service provider: supabase, s3, ....
   - we: opendal
   - users: users of opendal
   
   OpenDAL will load config from env if `service providers` declares their standards like `AWS_ACCESS_KEY_ID`. And OpenDAL will not expose it's internally env to users.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176538587


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > The case is we always need to have the `authorization` header for Supabase. The only different is whether we are using the anon_key or service_key.
   
   No. If authorization header is empty, we will visit supabase like a browser which is useful for public bucket.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176541049


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > OpenDAL will load config from env if `service providers` declares their standards like `AWS_ACCESS_KEY_ID`. And OpenDAL will not expose it's internal env to users.
   
   Got it. Instead, we can give developers some notice when implementing backend.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176541049


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > OpenDAL will load config from env if `service providers` declares their standards like `AWS_ACCESS_KEY_ID`. And OpenDAL will not expose it's internal env to users.
   
   Got it.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176545435


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > For example:
   > 
   > ![image](https://user-images.githubusercontent.com/5351546/234295831-721af13c-9bf2-4063-895a-4ba888fbc675.png)
   
   I think this may only apply in the case we are using browsers. I have tested that if we are accessing the public bucket
   
   If the authorization header is missing
   ```
   [2023-04-25T13:44:20Z ERROR opendal::services] service=supabase operation=Writer::close path=test written=13 -> data close failed: Unexpected (permanent) at Writer::close => SupabaseError { status_code: "400", error: "Error", message: "headers must have required property 'authorization'" }
   ```
   
   If the header's value is missing
   ```
   [2023-04-25T13:46:18Z ERROR opendal::services] service=supabase operation=Writer::close path=test written=13 -> data close failed: Unexpected (permanent) at Writer::close => SupabaseError { status_code: "400", error: "jwt must be provided", message: "jwt must be provided" }
   ```



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176566520


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Hi, supabase doesn't allow calling `write` without `authorization` (which makes sense right? You don't want anonymouse to write data in your bucket even it's public). Please try `read` a public bucket.
   
   ---
   
   If users call `write` without specify the key, we can just return the error back.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177482998


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Leave  to users to decide. They know what bucket they are visiting. It's not opendal's job.
   
   We just need to make our behaviour clear.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1179009746


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,226 @@
+// 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::fmt::Debug;
+
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization
+    /// If loaded, the read operation will always access the nonpublic resources.
+    /// If you want to read the public resources, please do not set the key.
+    pub key: Option<String>,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(
+        root: &str,
+        bucket: &str,
+        endpoint: &str,
+        key: Option<String>,
+        client: HttpClient,
+    ) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            key,
+            http_client: client,
+        }
+    }
+
+    /// Add authorization header to the request if the key is set. Otherwise leave
+    /// the request as-is.
+    pub fn sign<T>(&self, req: &mut Request<T>) -> Result<()> {
+        if let Some(k) = &self.key {
+            let v = HeaderValue::from_str(&format!("Bearer {}", k)).unwrap();
+            req.headers_mut().insert(http::header::AUTHORIZATION, v);
+        }
+        Ok(())
+    }
+}
+
+// requests
+impl SupabaseCore {
+    pub fn supabase_upload_object_request(
+        &self,
+        path: &str,
+        size: Option<usize>,
+        content_type: Option<&str>,
+        body: AsyncBody,
+    ) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        let mut req = Request::post(&url);
+
+        if let Some(size) = size {
+            req = req.header(CONTENT_LENGTH, size)
+        }
+
+        if let Some(mime) = content_type {
+            req = req.header(CONTENT_TYPE, mime)
+        }
+
+        let req = req.body(body).map_err(new_request_build_error)?;
+
+        Ok(req)
+    }
+
+    pub fn supabase_get_object_public_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/public/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/authenticated/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_info_public_request(
+        &self,
+        path: &str,
+    ) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/info/public/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+
+    pub fn supabase_get_object_info_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/info/authenticated/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        Request::get(&url)
+            .body(AsyncBody::Empty)
+            .map_err(new_request_build_error)
+    }
+}
+
+// core utils
+impl SupabaseCore {
+    pub async fn send(&self, req: Request<AsyncBody>) -> Result<Response<IncomingAsyncBody>> {
+        self.http_client.send(req).await
+    }
+
+    pub async fn supabase_get_object(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        if self.key.is_some() {
+            self.supabase_get_object_auth(path).await
+        } else {
+            self.supabase_get_object_public(path).await
+        }
+    }
+
+    pub async fn supabase_get_object_info(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        if self.key.is_some() {
+            self.supabase_get_object_info_auth(path).await
+        } else {
+            self.supabase_get_object_info_public(path).await
+        }
+    }
+
+    async fn supabase_get_object_public(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_public_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_auth(&self, path: &str) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_auth_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_info_public(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_info_public_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await
+    }
+
+    async fn supabase_get_object_info_auth(
+        &self,
+        path: &str,
+    ) -> Result<Response<IncomingAsyncBody>> {
+        let mut req = self.supabase_get_object_info_auth_request(path)?;
+        self.sign(&mut req)?;
+        self.send(req).await

Review Comment:
   Please remove them all, we don't need to them. 



##########
core/src/services/supabase/error.rs:
##########
@@ -0,0 +1,65 @@
+// 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 bytes::Buf;
+use http::Response;
+use http::StatusCode;
+use serde::Deserialize;
+use serde_json::from_reader;
+
+use crate::{raw::*, Error, ErrorKind, Result};
+
+#[derive(Default, Debug, Deserialize)]
+#[serde(default, rename_all = "camelCase")]
+/// The error returned by Supabase
+struct SupabaseError {
+    status_code: String,
+    error: String,
+    message: String,
+}
+
+/// Parse the supabase error type to the OpenDAL error type
+pub async fn parse_error(resp: Response<IncomingAsyncBody>) -> Result<Error> {
+    let (parts, body) = resp.into_parts();
+    let bs = body.bytes().await?;
+
+    // todo: the supabase error has status code 4XX, handle all that
+    let (kind, retryable) = match parts.status {
+        StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
+        StatusCode::FORBIDDEN => (ErrorKind::PermissionDenied, false),
+        StatusCode::PRECONDITION_FAILED | StatusCode::NOT_MODIFIED => {
+            (ErrorKind::ConditionNotMatch, false)
+        }
+        StatusCode::INTERNAL_SERVER_ERROR
+        | StatusCode::BAD_GATEWAY
+        | StatusCode::SERVICE_UNAVAILABLE
+        | StatusCode::GATEWAY_TIMEOUT => (ErrorKind::Unexpected, true),
+        _ => (ErrorKind::Unexpected, false),
+    };
+
+    let (message, _) = from_reader::<_, SupabaseError>(bs.clone().reader())

Review Comment:
   We can use `from_slice` directly.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1178693604


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,222 @@
+// 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::fmt::Debug;
+
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization
+    /// If loaded, the read operation will always access the nonpublic resources.
+    /// If you want to read the public resources, please do not set the key.
+    pub auth_key: Option<HeaderValue>,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(
+        root: &str,
+        bucket: &str,
+        endpoint: &str,
+        auth_key: Option<HeaderValue>,
+        client: HttpClient,
+    ) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key,
+            http_client: client,
+        }
+    }
+
+    /// Add authorization header to the request if the key is set. Otherwise leave
+    /// the request as-is.
+    pub fn sign<T>(&self, req: &mut Request<T>) -> Result<()> {
+        if let Some(k) = &self.auth_key {
+            let v = HeaderValue::from_str(&format!("Bearer {}", k.to_str().unwrap())).unwrap();
+            req.headers_mut().insert(http::header::AUTHORIZATION, v);
+        }
+        Ok(())
+    }
+}
+
+// requests
+impl SupabaseCore {
+    pub fn supabase_upload_object_request(
+        &self,
+        path: &str,
+        size: Option<usize>,
+        content_type: Option<&str>,
+        body: AsyncBody,
+    ) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        let mut req = Request::post(&url);
+
+        if let Some(size) = size {
+            req = req.header(CONTENT_LENGTH, size)
+        }
+
+        if let Some(mime) = content_type {
+            req = req.header(CONTENT_TYPE, mime)
+        }
+
+        let req = req.body(body).map_err(new_request_build_error)?;
+
+        Ok(req)
+    }
+
+    pub fn supabase_get_object_public_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        self.supabase_get_object_request(path, false)
+    }
+
+    pub fn supabase_get_object_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        self.supabase_get_object_request(path, true)
+    }
+
+    pub fn supabase_get_object_info_public_request(
+        &self,
+        path: &str,
+    ) -> Result<Request<AsyncBody>> {
+        self.supabase_get_object_info_request(path, false)
+    }
+
+    pub fn supabase_get_object_info_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        self.supabase_get_object_info_request(path, true)
+    }
+}

Review Comment:
   Fixed



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1177777511


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,286 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key
+/// - `anon_key`: Set the client key for the backend, this cannot access non-public resources
+///
+/// ## Authorization keys
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only write public resources while the latter one
+/// can access all resources. Note that if you want to read public resources, do not set the key.
+///
+/// # Example
+///
+/// ## Basic Setup
+///
+/// ```
+///
+/// ### Using Builder
+///
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = services::Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///     // this sets up the anon_key, which means this operator can only write public resource
+///     builder.key("some_anon_key");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+#[derive(Default)]
+pub struct SupabaseBuilder {
+    root: Option<String>,
+
+    bucket: String,
+    endpoint: Option<String>,
+
+    auth_key: Option<String>,

Review Comment:
   Prefer to keep fit with `key`.



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,286 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key
+/// - `anon_key`: Set the client key for the backend, this cannot access non-public resources
+///
+/// ## Authorization keys
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only write public resources while the latter one
+/// can access all resources. Note that if you want to read public resources, do not set the key.
+///
+/// # Example
+///
+/// ## Basic Setup
+///
+/// ```
+///
+/// ### Using Builder
+///
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = services::Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///     // this sets up the anon_key, which means this operator can only write public resource
+///     builder.key("some_anon_key");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+#[derive(Default)]
+pub struct SupabaseBuilder {
+    root: Option<String>,
+
+    bucket: String,
+    endpoint: Option<String>,
+
+    auth_key: Option<String>,
+
+    // todo: optional public, currently true always
+    // todo: optional file_size_limit, currently 0
+    // todo: optional allowed_mime_types, currently only string
+    http_client: Option<HttpClient>,
+}
+
+impl Debug for SupabaseBuilder {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseBuilder")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseBuilder {
+    /// Set root of this backend.
+    ///
+    /// All operations will happen under this root.
+    pub fn root(&mut self, root: &str) -> &mut Self {
+        self.root = if root.is_empty() {
+            None
+        } else {
+            Some(root.to_string())
+        };
+
+        self
+    }
+
+    /// Set bucket name of this backend.
+    pub fn bucket(&mut self, bucket: &str) -> &mut Self {
+        self.bucket = bucket.to_string();
+        self
+    }
+
+    /// Set endpoint of this backend.
+    ///
+    /// Endpoint must be full uri
+    pub fn endpoint(&mut self, endpoint: &str) -> &mut Self {
+        self.endpoint = if endpoint.is_empty() {
+            None
+        } else {
+            Some(endpoint.trim_end_matches('/').to_string())
+        };
+
+        self
+    }
+
+    /// Set the authorization key for this backend
+    /// Do not set this key if you want to read public bucket
+    pub fn key(&mut self, key: &str) -> &mut Self {
+        self.auth_key = Some(key.to_string());
+        self
+    }
+
+    /// Specify the http client that used by this service.
+    ///
+    /// # Notes
+    ///
+    /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed
+    /// during minor updates.
+    pub fn http_client(&mut self, client: HttpClient) -> &mut Self {
+        self.http_client = Some(client);
+        self
+    }
+}
+
+impl Builder for SupabaseBuilder {
+    const SCHEME: Scheme = Scheme::Supabase;
+    type Accessor = SupabaseBackend;
+
+    fn from_map(map: std::collections::HashMap<String, String>) -> Self {
+        let mut builder = SupabaseBuilder::default();
+
+        map.get("root").map(|v| builder.root(v));
+        map.get("bucket").map(|v| builder.bucket(v));
+        map.get("endpoint").map(|v| builder.endpoint(v));
+        map.get("key").map(|v| builder.key(v));
+
+        builder
+    }
+
+    fn build(&mut self) -> Result<Self::Accessor> {
+        let root = normalize_root(&self.root.take().unwrap_or_default());
+        debug!("backend use root {}", &root);
+
+        let bucket = &self.bucket;
+
+        let endpoint = self.endpoint.take().unwrap_or_default();
+
+        let http_client = if let Some(client) = self.http_client.take() {
+            client
+        } else {
+            HttpClient::new().map_err(|err| {
+                err.with_operation("Builder::build")
+                    .with_context("service", Scheme::Supabase)
+            })?
+        };
+
+        let auth_key = self
+            .auth_key
+            .as_ref()
+            .map(|k| HeaderValue::from_str(k).unwrap());

Review Comment:
   This is not the final header value. How about just store as `String` and convert to header value while needed?



##########
core/src/services/supabase/writer.rs:
##########
@@ -0,0 +1,131 @@
+// 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::sync::Arc;
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use http::StatusCode;
+
+use super::core::*;
+use super::error::parse_error;
+use crate::ops::OpWrite;
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseWriter {
+    core: Arc<SupabaseCore>,
+
+    op: OpWrite,
+    path: String,
+
+    buffer: oio::VectorCursor,
+    buffer_size: usize,
+}
+
+impl SupabaseWriter {
+    pub fn new(core: Arc<SupabaseCore>, path: &str, op: OpWrite) -> Self {
+        SupabaseWriter {
+            core,
+            op,
+            path: path.to_string(),
+            buffer: oio::VectorCursor::new(),
+            buffer_size: 8 * 1024 * 1024,
+        }
+    }
+
+    pub async fn upload(&self, bytes: Bytes) -> Result<()> {
+        let size = bytes.len();
+
+        // the content length should match
+        if let Some(l) = self.op.content_length() {
+            if l as usize != size {
+                return Err(Error::new(
+                    ErrorKind::Unexpected,
+                    "The content length does not match the bytes' length",
+                ));
+            }
+        }
+
+        let mut req = self.core.supabase_upload_object_request(
+            &self.path,
+            Some(size),
+            self.op.content_type(),
+            AsyncBody::Bytes(bytes),
+        )?;
+
+        self.core.sign(&mut req)?;
+
+        let resp = self.core.send(req).await?;
+
+        match resp.status() {
+            StatusCode::OK => {
+                resp.into_body().consume().await?;
+                Ok(())
+            }
+            _ => Err(parse_error(resp).await?),
+        }
+    }
+}
+
+#[async_trait]
+impl oio::Write for SupabaseWriter {
+    async fn write(&mut self, bs: Bytes) -> Result<()> {
+        if bs.is_empty() {
+            return Ok(());
+        }
+
+        self.buffer.push(bs);
+        if self.buffer.len() <= self.buffer_size {
+            return Ok(());
+        }
+
+        let bs = self.buffer.peak_at_least(self.buffer_size);
+        let size = bs.len();
+
+        match self.upload(bs).await {
+            Ok(_) => {
+                self.buffer.take(size);
+                Ok(())
+            }
+            Err(e) => {
+                self.buffer.pop();
+                Err(e)
+            }
+        }
+    }

Review Comment:
   We don't need to handle the buffer if `unsized write` is not supported.
   
   Please refer to:
   
   https://github.com/apache/incubator-opendal/blob/a814d9f65e48f02dffefe42e7a7a0adcbad1dde8/core/src/services/azblob/backend.rs#L530-L535
   
   and
   
   https://github.com/apache/incubator-opendal/blob/a814d9f65e48f02dffefe42e7a7a0adcbad1dde8/core/src/services/azblob/writer.rs#L45-L67



##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,222 @@
+// 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::fmt::Debug;
+
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization
+    /// If loaded, the read operation will always access the nonpublic resources.
+    /// If you want to read the public resources, please do not set the key.
+    pub auth_key: Option<HeaderValue>,

Review Comment:
   Store as a `String` is much easier.



##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,222 @@
+// 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::fmt::Debug;
+
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization
+    /// If loaded, the read operation will always access the nonpublic resources.
+    /// If you want to read the public resources, please do not set the key.
+    pub auth_key: Option<HeaderValue>,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(
+        root: &str,
+        bucket: &str,
+        endpoint: &str,
+        auth_key: Option<HeaderValue>,
+        client: HttpClient,
+    ) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key,
+            http_client: client,
+        }
+    }
+
+    /// Add authorization header to the request if the key is set. Otherwise leave
+    /// the request as-is.
+    pub fn sign<T>(&self, req: &mut Request<T>) -> Result<()> {
+        if let Some(k) = &self.auth_key {
+            let v = HeaderValue::from_str(&format!("Bearer {}", k.to_str().unwrap())).unwrap();
+            req.headers_mut().insert(http::header::AUTHORIZATION, v);
+        }
+        Ok(())
+    }
+}
+
+// requests
+impl SupabaseCore {
+    pub fn supabase_upload_object_request(
+        &self,
+        path: &str,
+        size: Option<usize>,
+        content_type: Option<&str>,
+        body: AsyncBody,
+    ) -> Result<Request<AsyncBody>> {
+        let p = build_abs_path(&self.root, path);
+        let url = format!(
+            "{}/storage/v1/object/{}/{}",
+            self.endpoint,
+            self.bucket,
+            percent_encode_path(&p)
+        );
+
+        let mut req = Request::post(&url);
+
+        if let Some(size) = size {
+            req = req.header(CONTENT_LENGTH, size)
+        }
+
+        if let Some(mime) = content_type {
+            req = req.header(CONTENT_TYPE, mime)
+        }
+
+        let req = req.body(body).map_err(new_request_build_error)?;
+
+        Ok(req)
+    }
+
+    pub fn supabase_get_object_public_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        self.supabase_get_object_request(path, false)
+    }
+
+    pub fn supabase_get_object_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        self.supabase_get_object_request(path, true)
+    }
+
+    pub fn supabase_get_object_info_public_request(
+        &self,
+        path: &str,
+    ) -> Result<Request<AsyncBody>> {
+        self.supabase_get_object_info_request(path, false)
+    }
+
+    pub fn supabase_get_object_info_auth_request(&self, path: &str) -> Result<Request<AsyncBody>> {
+        self.supabase_get_object_info_request(path, true)
+    }
+}

Review Comment:
   I feel like those logic is a bit overdesigned. `Core` doesn't need to expose those internal logic to `Backend`.



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,286 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   Should be `key`.



##########
core/src/services/supabase/writer.rs:
##########
@@ -0,0 +1,131 @@
+// 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::sync::Arc;
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use http::StatusCode;
+
+use super::core::*;
+use super::error::parse_error;
+use crate::ops::OpWrite;
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseWriter {
+    core: Arc<SupabaseCore>,
+
+    op: OpWrite,
+    path: String,
+
+    buffer: oio::VectorCursor,
+    buffer_size: usize,
+}
+
+impl SupabaseWriter {
+    pub fn new(core: Arc<SupabaseCore>, path: &str, op: OpWrite) -> Self {
+        SupabaseWriter {
+            core,
+            op,
+            path: path.to_string(),
+            buffer: oio::VectorCursor::new(),
+            buffer_size: 8 * 1024 * 1024,
+        }
+    }
+
+    pub async fn upload(&self, bytes: Bytes) -> Result<()> {
+        let size = bytes.len();
+
+        // the content length should match
+        if let Some(l) = self.op.content_length() {
+            if l as usize != size {
+                return Err(Error::new(
+                    ErrorKind::Unexpected,
+                    "The content length does not match the bytes' length",
+                ));
+            }
+        }
+
+        let mut req = self.core.supabase_upload_object_request(
+            &self.path,
+            Some(size),
+            self.op.content_type(),
+            AsyncBody::Bytes(bytes),
+        )?;
+
+        self.core.sign(&mut req)?;
+
+        let resp = self.core.send(req).await?;
+
+        match resp.status() {
+            StatusCode::OK => {
+                resp.into_body().consume().await?;
+                Ok(())
+            }
+            _ => Err(parse_error(resp).await?),
+        }
+    }
+}
+
+#[async_trait]
+impl oio::Write for SupabaseWriter {
+    async fn write(&mut self, bs: Bytes) -> Result<()> {
+        if bs.is_empty() {
+            return Ok(());
+        }
+
+        self.buffer.push(bs);
+        if self.buffer.len() <= self.buffer_size {
+            return Ok(());
+        }
+
+        let bs = self.buffer.peak_at_least(self.buffer_size);
+        let size = bs.len();
+
+        match self.upload(bs).await {
+            Ok(_) => {
+                self.buffer.take(size);
+                Ok(())
+            }
+            Err(e) => {
+                self.buffer.pop();
+                Err(e)
+            }
+        }
+    }
+
+    async fn abort(&mut self) -> Result<()> {
+        unimplemented!()

Review Comment:
   Please return `Unsupported` error instead of panic.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176425414


##########
core/src/services/s3/core.rs:
##########
@@ -439,7 +439,7 @@ impl S3Core {
         self.send(req).await
     }
 
-    /// Make this functions as `pub(suber)` because `DirStream` depends
+    /// Make this functions as `pub(super)` because `DirStream` depends

Review Comment:
   Oh, this is an outdated comment. Please remove it directly.



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   We don't need to introduce the two different key here. It's users own decision. How about just use `key`? Like supabase's example:
   
   ```js
   void main() async {
     final supabase = SupabaseClient('supabaseUrl', 'supabaseKey');
   
     // Create file `example.txt` and upload it in `public` bucket
     final file = File('example.txt');
     file.writeAsStringSync('File content');
     final storageResponse = await supabase
         .storage
         .from('public')
         .upload('example.txt', file);
   }
   ```



##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";

Review Comment:
   authorization is part of HTTP standard. Please use `http::header::AUTHORIZATION` here  directly.



##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   We don't need this



##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {
+        // if set by user, return directly
+        if self.auth_key.is_some() {
+            return;
+        }
+
+        // load secret key first
+        if let Ok(v) = std::env::var(constants::SUPABASE_AUTH_SERVICE_KEY) {
+            self.auth_key = Some(HeaderValue::from_str(&v).unwrap());
+            self.auth = true;
+            return;
+        }
+
+        // if not loaded, load anon key then
+        if let Ok(v) = std::env::var(constants::SUPABASE_AUTH_ANON_KEY) {
+            self.auth_key = Some(HeaderValue::from_str(&v).unwrap());
+            self.auth = false;
+            return;
+        }
+
+        // the key should always be loaded
+        unreachable!(
+            "The authorization key is not set, you may set it in your builder or through environment variable {} or {}",
+            constants::SUPABASE_AUTH_ANON_KEY,
+            constants::SUPABASE_AUTH_SERVICE_KEY,
+        )
+    }
+
+    pub fn sign<T>(&self, req: &mut Request<T>) -> Result<()> {
+        if let Some(k) = &self.auth_key {
+            let v = HeaderValue::from_str(&format!("Bearer {}", k.to_str().unwrap())).unwrap();
+            req.headers_mut().insert(constants::AUTH_HTTP_HEADER_KEY, v);
+            Ok(())
+        } else {
+            Err(new_request_sign_error(anyhow!(
+                "The anon key is not loaded"
+            )))
+        }
+    }
+}
+
+// requests
+impl SupabaseCore {
+    // ?: this defaults the bucket id to be the bucket name
+    pub fn supabase_create_bucket_request(&self, public: bool) -> Result<Request<AsyncBody>> {

Review Comment:
   No, we don't need to support create_bucket. Bukcet must be created before starting use opendal.



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key
+/// - `anon_key`: Set the client key for the backend, this cannot access non-public resources
+///
+/// ## Authorization key setup
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only access public resources while the latter one
+/// can access all resources.
+///
+/// There exists a priority of setting up the authorization keys.
+/// The key set up by builder takes precedence over environment variable, and the service_key
+/// takes precedence over anon_key.
+///
+/// There are two ways of setting up the authorization key, i.e., environment variable and builder.
+/// - The environment variable OPENDAL_SUPABASE_AUTH_ANON_KEY sets up the anon_key.

Review Comment:
   We should only mention env here is service has its own env, for example: AWS_ACCESS_KEY_ID. And `OPENDAL_` env are reserved as internal usage which could be changed at anytime.
   
   So we should not mention the env way here.



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key
+/// - `anon_key`: Set the client key for the backend, this cannot access non-public resources
+///
+/// ## Authorization key setup
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only access public resources while the latter one
+/// can access all resources.
+///
+/// There exists a priority of setting up the authorization keys.
+/// The key set up by builder takes precedence over environment variable, and the service_key
+/// takes precedence over anon_key.
+///
+/// There are two ways of setting up the authorization key, i.e., environment variable and builder.
+/// - The environment variable OPENDAL_SUPABASE_AUTH_ANON_KEY sets up the anon_key.
+/// - The environment variable OPENDAL_SUPABASE_AUTH_SERVICE_KEY sets up the service_role_key.
+///
+/// # Example
+///
+/// ## Basic Setup
+///
+/// ### Using Environment Variable

Review Comment:
   Please remove this section.



##########
core/src/services/supabase/writer.rs:
##########
@@ -0,0 +1,119 @@
+// 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::sync::Arc;
+
+use async_trait::async_trait;
+use bytes::Bytes;
+use http::StatusCode;
+
+use super::core::*;
+use super::error::parse_error;
+use crate::ops::OpWrite;
+use crate::raw::*;
+use crate::*;
+
+pub struct SupabaseWriter {
+    core: Arc<SupabaseCore>,
+
+    op: OpWrite,
+    path: String,
+
+    buffer: oio::VectorCursor,
+    buffer_size: usize,
+}
+
+impl SupabaseWriter {
+    pub fn new(core: Arc<SupabaseCore>, path: &str, op: OpWrite) -> Self {
+        SupabaseWriter {
+            core,
+            op,
+            path: path.to_string(),
+            buffer: oio::VectorCursor::new(),
+            buffer_size: 8 * 1024 * 1024,
+        }
+    }
+
+    pub async fn upload(&self, bytes: Bytes) -> Result<()> {
+        let mut req = self.core.supabase_upload_object_request(
+            &self.path,
+            Some(bytes.len()),
+            self.op.content_type(),
+            AsyncBody::Bytes(bytes),
+        )?;
+
+        self.core.sign(&mut req)?;
+
+        let resp = self.core.send(req).await?;
+
+        match resp.status() {
+            StatusCode::OK => {
+                resp.into_body().consume().await?;
+                Ok(())
+            }
+            _ => Err(parse_error(resp).await?),
+        }
+    }
+}
+
+#[async_trait]
+impl oio::Write for SupabaseWriter {
+    async fn write(&mut self, bs: Bytes) -> Result<()> {

Review Comment:
   `supabase_upload_object_request` seems always overwrite the same path and can't be used as resumeable upload. Please re-check the logic here. Take `s3` as a reference.



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key
+/// - `anon_key`: Set the client key for the backend, this cannot access non-public resources
+///
+/// ## Authorization key setup
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only access public resources while the latter one
+/// can access all resources.
+///
+/// There exists a priority of setting up the authorization keys.
+/// The key set up by builder takes precedence over environment variable, and the service_key
+/// takes precedence over anon_key.
+///
+/// There are two ways of setting up the authorization key, i.e., environment variable and builder.
+/// - The environment variable OPENDAL_SUPABASE_AUTH_ANON_KEY sets up the anon_key.
+/// - The environment variable OPENDAL_SUPABASE_AUTH_SERVICE_KEY sets up the service_role_key.
+///
+/// # Example
+///
+/// ## Basic Setup
+///
+/// ### Using Environment Variable
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     // suppose the environment variable is set
+///     let mut builder = services::Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+///
+/// ### Using Builder
+///
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = services::Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///     // this sets up the anon_key, which means this operator can only access public resource
+///     builder.anon_key("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+#[derive(Default)]
+pub struct SupabaseBuilder {
+    root: Option<String>,
+
+    bucket: String,
+    endpoint: Option<String>,
+
+    service_key: Option<String>,
+    anon_key: Option<String>,
+
+    // todo: optional public, currently true always
+    // todo: optional file_size_limit, currently 0
+    // todo: optional allowed_mime_types, currently only string
+    http_client: Option<HttpClient>,
+}
+
+impl Debug for SupabaseBuilder {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseBuilder")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseBuilder {
+    /// Set root of this backend.
+    ///
+    /// All operations will happen under this root.
+    pub fn root(&mut self, root: &str) -> &mut Self {
+        self.root = if root.is_empty() {
+            None
+        } else {
+            Some(root.to_string())
+        };
+
+        self
+    }
+
+    /// Set bucket name of this backend.
+    pub fn bucket(&mut self, bucket: &str) -> &mut Self {
+        self.bucket = bucket.to_string();
+        self
+    }
+
+    /// Set endpoint of this backend.
+    ///
+    /// Endpoint must be full uri
+    pub fn endpoint(&mut self, endpoint: &str) -> &mut Self {
+        self.endpoint = if endpoint.is_empty() {
+            None
+        } else {
+            Some(endpoint.trim_end_matches('/').to_string())
+        };
+
+        self
+    }
+
+    /// Set the service_role_key for this backend
+    pub fn service_key(&mut self, service_key: &str) -> &mut Self {
+        self.service_key = Some(service_key.to_string());
+        self
+    }
+
+    /// Set the anon_key for this backend
+    pub fn anon_key(&mut self, anon_key: &str) -> &mut Self {
+        self.anon_key = Some(anon_key.to_string());
+        self
+    }
+
+    /// Specify the http client that used by this service.
+    ///
+    /// # Notes
+    ///
+    /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed
+    /// during minor updates.
+    pub fn http_client(&mut self, client: HttpClient) -> &mut Self {
+        self.http_client = Some(client);
+        self
+    }
+}
+
+impl Builder for SupabaseBuilder {
+    const SCHEME: Scheme = Scheme::Supabase;
+    type Accessor = SupabaseBackend;
+
+    fn from_map(map: std::collections::HashMap<String, String>) -> Self {
+        let mut builder = SupabaseBuilder::default();
+
+        map.get("root").map(|v| builder.root(v));
+        map.get("bucket").map(|v| builder.bucket(v));
+        map.get("endpoint").map(|v| builder.endpoint(v));
+        map.get("anon_key").map(|v| builder.anon_key(v));
+        map.get("service_key").map(|v| builder.service_key(v));
+
+        builder
+    }
+
+    fn build(&mut self) -> Result<Self::Accessor> {
+        let root = normalize_root(&self.root.take().unwrap_or_default());
+        debug!("backend use root {}", &root);
+
+        let bucket = &self.bucket;
+
+        let endpoint = self.endpoint.take().unwrap_or_default();
+
+        let http_client = if let Some(client) = self.http_client.take() {
+            client
+        } else {
+            HttpClient::new().map_err(|err| {
+                err.with_operation("Builder::build")
+                    .with_context("service", Scheme::S3)
+            })?
+        };
+
+        // priority:
+        //  if the service key is loaded, it is used.
+        //  Else if the anon key is loaded, it is used.
+        //  Else the key should be loaded from the environment variable
+        let (auth_key, auth) = if let Some(k) = &self.service_key {
+            (Some(k), true)
+        } else if let Some(k) = &self.anon_key {
+            (Some(k), false)
+        } else {
+            (None, false)
+        };
+
+        let auth_key = auth_key.map(|k| HeaderValue::from_str(k).unwrap());
+
+        let mut core = SupabaseCore {
+            root,
+            bucket: bucket.to_owned(),
+            endpoint,
+            auth_key,
+            auth,
+            http_client,
+        };
+
+        core.load_auth_key();
+
+        let core = Arc::new(core);
+
+        Ok(SupabaseBackend { core })
+    }
+}
+
+#[derive(Debug)]
+pub struct SupabaseBackend {
+    core: Arc<SupabaseCore>,
+}
+
+#[async_trait]
+impl Accessor for SupabaseBackend {
+    type Reader = IncomingAsyncBody;
+    type BlockingReader = ();
+    type Writer = SupabaseWriter;
+    type BlockingWriter = ();
+    // todo: implement Pager to support list and scan
+    type Pager = ();
+    type BlockingPager = ();
+
+    fn info(&self) -> AccessorInfo {
+        let mut am = AccessorInfo::default();
+        am.set_scheme(Scheme::Supabase)
+            .set_root(&self.core.root)
+            .set_name(&self.core.bucket)
+            .set_capability(Capability {
+                stat: true,
+                read: true,
+                write: true,
+
+                ..Default::default()
+            });
+
+        am
+    }
+
+    // todo: implement create_dir
+    async fn create_dir(&self, _path: &str, _: OpCreate) -> Result<RpCreate> {

Review Comment:
   Remove this API to mark it's unsupported for now instead of `unimplemented!()`.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176519678


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   What I want to say is that, if these backends do not use `reqsign`, then they lose the ability to load properties from the environment variable, right? Perhaps our past experience with using services like S3 may have caused some confusion.
   
   So users need to handle this process themselves. We may need to write this behavior into our docs.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176522390


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > Set `AUTHORIZATION` header if we have a `key`, otherwise leave it empty. Users should make the decision, we just return the server's response back.
   
   The case is we always need to have the `authorization` header for Supabase. The only different is whether we are using the anon_key or service_key.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176691283


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > The authorized url and the public url is different, to be more specific, `/authenticated/bucket/wildcard` and /`public/bucket/wildcard`.
   
   I guess we should call `authenticated` if `key` has been set, otherwise, call `public`. 
   
   Seems we have confused the `public` bucket and supabase's `public` API key. From storage's API spec, `public` API doesn't need any auth header.
   
   ---
   
   > IMO, we should call the `public` one first, if failed, then call the `authenticated` one.
   
   No, we never do this in OpenDAL.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#issuecomment-1523312879

   Seems there is a clippy warning in the java binding that makes the CI fails.


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176530833


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > So users need to handle this process themselves. We may need to write this behavior into our docs.
   
   We confused different things here. There are three roles involed:
   
   - service provider: supabase, s3, ....
   - we: opendal
   - users: users of opendal
   
   OpenDAL will load config from env if `service providers` declares their standards like `AWS_ACCESS_KEY_ID`. And OpenDAL will not expose it's internal env to users.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176526604


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > What I want to say is that, if these backends do not use `reqsign`, then they lose the ability to load properties from the environment variable, right?
   
   Supabase doesn't have properties to load from env. It's a simple service which only requires a url and key.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#issuecomment-1521683768

   Related: #1994 


-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176489882


##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,290 @@
+// 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::fmt::Debug;
+
+use anyhow::anyhow;
+use bytes::Bytes;
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+use serde_json::json;
+
+use crate::raw::*;
+use crate::*;
+
+mod constants {
+    pub const AUTH_HTTP_HEADER_KEY: &str = "authorization";
+    pub const SUPABASE_AUTH_ANON_KEY: &str = "OPENDAL_SUPABASE_AUTH_ANON_KEY";
+    pub const SUPABASE_AUTH_SERVICE_KEY: &str = "OPENDAL_SUPABASE_AUTH_SERVICE_KEY";
+}
+
+pub struct SupabaseCore {
+    pub root: String,
+    pub bucket: String,
+    pub endpoint: String,
+
+    /// The key used for authorization, initialized by environment variable you designated.
+    /// Normally it is rather an anon_key(Client key) or an service_role_key(Secret Key)
+    pub auth_key: Option<HeaderValue>,
+    /// This is true if the service_role_key is loaded, false if the anon_key is loaded
+    pub auth: bool,
+
+    pub http_client: HttpClient,
+}
+
+impl Debug for SupabaseCore {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseCore")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseCore {
+    pub fn new(root: &str, bucket: &str, endpoint: &str, client: HttpClient) -> Self {
+        Self {
+            root: root.to_string(),
+            bucket: bucket.to_string(),
+            endpoint: endpoint.to_string(),
+            auth_key: None,
+            auth: false,
+            http_client: client,
+        }
+    }
+
+    /// load auth key tries to load the authorization key from the environment variable
+    /// - if the key is set by user using Builder, this return directly
+    /// - if the key is not set by user, this will try to load the service key first, then the anon key
+    pub fn load_auth_key(&mut self) {

Review Comment:
   > If so, how and where to get those envs?
   
   We don't need to got those envs. Users should not configure opendal via `OPENDAL_XXXX`. We only load services' it own env like `AWS_ACCESS_KEY_ID`.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/Supabase): minimal read/write/stat support on Supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1176545435


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,342 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::HeaderValue;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `service_key`: Set the secret key for the backend, this is prioritized over the client key

Review Comment:
   > For example:
   
   
   I think this may only apply in the case we are using browsers. I have tested that if we are accessing the public bucket
   
   If the authorization header is missing
   ```
   [2023-04-25T13:44:20Z ERROR opendal::services] service=supabase operation=Writer::close path=test
   written=13 -> data close failed: Unexpected (permanent) at Writer::close => SupabaseError
   { status_code: "400", error: "Error", message: "headers must have required property 'authorization'" }
   ```
   
   If the header's value is missing
   ```
   [2023-04-25T13:46:18Z ERROR opendal::services] service=supabase operation=Writer::close path=test
   written=13 -> data close failed: Unexpected (permanent) at Writer::close => SupabaseError
   { status_code: "400", error: "jwt must be provided", message: "jwt must be provided" }
   ```



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Ji-Xinyou commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Ji-Xinyou (via GitHub)" <gi...@apache.org>.
Ji-Xinyou commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1178995892


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,282 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `key`: Set the authorization key for the backend, do not set if you want to read public bucket
+///
+/// ## Authorization keys
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only write public resources while the latter one
+/// can access all resources. Note that if you want to read public resources, do not set the key.
+///
+/// # Example
+///
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///     // this sets up the anon_key, which means this operator can only write public resource
+///     builder.key("some_anon_key");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+#[derive(Default)]
+pub struct SupabaseBuilder {
+    root: Option<String>,
+
+    bucket: String,
+    endpoint: Option<String>,
+
+    key: Option<String>,
+
+    // todo: optional public, currently true always
+    // todo: optional file_size_limit, currently 0
+    // todo: optional allowed_mime_types, currently only string
+    http_client: Option<HttpClient>,
+}
+
+impl Debug for SupabaseBuilder {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseBuilder")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseBuilder {
+    /// Set root of this backend.
+    ///
+    /// All operations will happen under this root.
+    pub fn root(&mut self, root: &str) -> &mut Self {
+        self.root = if root.is_empty() {
+            None
+        } else {
+            Some(root.to_string())
+        };
+
+        self
+    }
+
+    /// Set bucket name of this backend.
+    pub fn bucket(&mut self, bucket: &str) -> &mut Self {
+        self.bucket = bucket.to_string();
+        self
+    }
+
+    /// Set endpoint of this backend.
+    ///
+    /// Endpoint must be full uri
+    pub fn endpoint(&mut self, endpoint: &str) -> &mut Self {
+        self.endpoint = if endpoint.is_empty() {
+            None
+        } else {
+            Some(endpoint.trim_end_matches('/').to_string())
+        };
+
+        self
+    }
+
+    /// Set the authorization key for this backend
+    /// Do not set this key if you want to read public bucket
+    pub fn key(&mut self, key: &str) -> &mut Self {
+        self.key = Some(key.to_string());
+        self
+    }
+
+    /// Specify the http client that used by this service.
+    ///
+    /// # Notes
+    ///
+    /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed
+    /// during minor updates.
+    pub fn http_client(&mut self, client: HttpClient) -> &mut Self {
+        self.http_client = Some(client);
+        self
+    }
+}
+
+impl Builder for SupabaseBuilder {
+    const SCHEME: Scheme = Scheme::Supabase;
+    type Accessor = SupabaseBackend;
+
+    fn from_map(map: std::collections::HashMap<String, String>) -> Self {
+        let mut builder = SupabaseBuilder::default();
+
+        map.get("root").map(|v| builder.root(v));
+        map.get("bucket").map(|v| builder.bucket(v));
+        map.get("endpoint").map(|v| builder.endpoint(v));
+        map.get("key").map(|v| builder.key(v));
+
+        builder
+    }
+
+    fn build(&mut self) -> Result<Self::Accessor> {
+        let root = normalize_root(&self.root.take().unwrap_or_default());
+        debug!("backend use root {}", &root);
+
+        let bucket = &self.bucket;
+
+        let endpoint = self.endpoint.take().unwrap_or_default();
+
+        let http_client = if let Some(client) = self.http_client.take() {
+            client
+        } else {
+            HttpClient::new().map_err(|err| {
+                err.with_operation("Builder::build")
+                    .with_context("service", Scheme::Supabase)
+            })?
+        };
+
+        let key = self.key.as_ref().map(|k| k.to_owned());
+
+        let core = SupabaseCore::new(&root, bucket, &endpoint, key, http_client);
+
+        let core = Arc::new(core);
+
+        Ok(SupabaseBackend { core })
+    }
+}
+
+#[derive(Debug)]
+pub struct SupabaseBackend {
+    core: Arc<SupabaseCore>,
+}
+
+#[async_trait]
+impl Accessor for SupabaseBackend {
+    type Reader = IncomingAsyncBody;
+    type BlockingReader = ();
+    type Writer = SupabaseWriter;
+    type BlockingWriter = ();
+    // todo: implement Pager to support list and scan
+    type Pager = ();
+    type BlockingPager = ();
+
+    fn info(&self) -> AccessorInfo {
+        let mut am = AccessorInfo::default();
+        am.set_scheme(Scheme::Supabase)
+            .set_root(&self.core.root)
+            .set_name(&self.core.bucket)
+            .set_capability(Capability {
+                stat: true,
+                read: true,
+                write: true,
+
+                ..Default::default()
+            });
+
+        am
+    }
+
+    async fn read(&self, path: &str, _args: OpRead) -> Result<(RpRead, Self::Reader)> {
+        let resp = if self.core.key.is_some() {
+            self.core.supabase_get_object_auth(path).await?

Review Comment:
   Got it



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #2119: feat(services/supabase): Add read/write/stat support for supabase

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #2119:
URL: https://github.com/apache/incubator-opendal/pull/2119#discussion_r1178991814


##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,282 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `key`: Set the authorization key for the backend, do not set if you want to read public bucket
+///
+/// ## Authorization keys
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only write public resources while the latter one
+/// can access all resources. Note that if you want to read public resources, do not set the key.
+///
+/// # Example
+///
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///     // this sets up the anon_key, which means this operator can only write public resource
+///     builder.key("some_anon_key");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+#[derive(Default)]
+pub struct SupabaseBuilder {
+    root: Option<String>,
+
+    bucket: String,
+    endpoint: Option<String>,
+
+    key: Option<String>,
+
+    // todo: optional public, currently true always
+    // todo: optional file_size_limit, currently 0
+    // todo: optional allowed_mime_types, currently only string
+    http_client: Option<HttpClient>,
+}
+
+impl Debug for SupabaseBuilder {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseBuilder")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseBuilder {
+    /// Set root of this backend.
+    ///
+    /// All operations will happen under this root.
+    pub fn root(&mut self, root: &str) -> &mut Self {
+        self.root = if root.is_empty() {
+            None
+        } else {
+            Some(root.to_string())
+        };
+
+        self
+    }
+
+    /// Set bucket name of this backend.
+    pub fn bucket(&mut self, bucket: &str) -> &mut Self {
+        self.bucket = bucket.to_string();
+        self
+    }
+
+    /// Set endpoint of this backend.
+    ///
+    /// Endpoint must be full uri
+    pub fn endpoint(&mut self, endpoint: &str) -> &mut Self {
+        self.endpoint = if endpoint.is_empty() {
+            None
+        } else {
+            Some(endpoint.trim_end_matches('/').to_string())
+        };
+
+        self
+    }
+
+    /// Set the authorization key for this backend
+    /// Do not set this key if you want to read public bucket
+    pub fn key(&mut self, key: &str) -> &mut Self {
+        self.key = Some(key.to_string());
+        self
+    }
+
+    /// Specify the http client that used by this service.
+    ///
+    /// # Notes
+    ///
+    /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed
+    /// during minor updates.
+    pub fn http_client(&mut self, client: HttpClient) -> &mut Self {
+        self.http_client = Some(client);
+        self
+    }
+}
+
+impl Builder for SupabaseBuilder {
+    const SCHEME: Scheme = Scheme::Supabase;
+    type Accessor = SupabaseBackend;
+
+    fn from_map(map: std::collections::HashMap<String, String>) -> Self {
+        let mut builder = SupabaseBuilder::default();
+
+        map.get("root").map(|v| builder.root(v));
+        map.get("bucket").map(|v| builder.bucket(v));
+        map.get("endpoint").map(|v| builder.endpoint(v));
+        map.get("key").map(|v| builder.key(v));
+
+        builder
+    }
+
+    fn build(&mut self) -> Result<Self::Accessor> {
+        let root = normalize_root(&self.root.take().unwrap_or_default());
+        debug!("backend use root {}", &root);
+
+        let bucket = &self.bucket;
+
+        let endpoint = self.endpoint.take().unwrap_or_default();
+
+        let http_client = if let Some(client) = self.http_client.take() {
+            client
+        } else {
+            HttpClient::new().map_err(|err| {
+                err.with_operation("Builder::build")
+                    .with_context("service", Scheme::Supabase)
+            })?
+        };
+
+        let key = self.key.as_ref().map(|k| k.to_owned());
+
+        let core = SupabaseCore::new(&root, bucket, &endpoint, key, http_client);
+
+        let core = Arc::new(core);
+
+        Ok(SupabaseBackend { core })
+    }
+}
+
+#[derive(Debug)]
+pub struct SupabaseBackend {
+    core: Arc<SupabaseCore>,
+}
+
+#[async_trait]
+impl Accessor for SupabaseBackend {
+    type Reader = IncomingAsyncBody;
+    type BlockingReader = ();
+    type Writer = SupabaseWriter;
+    type BlockingWriter = ();
+    // todo: implement Pager to support list and scan
+    type Pager = ();
+    type BlockingPager = ();
+
+    fn info(&self) -> AccessorInfo {
+        let mut am = AccessorInfo::default();
+        am.set_scheme(Scheme::Supabase)
+            .set_root(&self.core.root)
+            .set_name(&self.core.bucket)
+            .set_capability(Capability {
+                stat: true,
+                read: true,
+                write: true,
+
+                ..Default::default()
+            });
+
+        am
+    }
+
+    async fn read(&self, path: &str, _args: OpRead) -> Result<(RpRead, Self::Reader)> {
+        let resp = if self.core.key.is_some() {
+            self.core.supabase_get_object_auth(path).await?

Review Comment:
   We only need to have `supabase_get_object`



##########
core/src/services/supabase/backend.rs:
##########
@@ -0,0 +1,282 @@
+// 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::fmt::Debug;
+use std::sync::Arc;
+
+use async_trait::async_trait;
+use http::StatusCode;
+use log::debug;
+
+use super::core::*;
+use super::error::parse_error;
+use super::writer::*;
+use crate::ops::*;
+use crate::raw::*;
+use crate::*;
+
+/// Supabase service
+///
+/// # Capabilities
+///
+/// - [x] read
+/// - [x] write
+/// - [ ] copy
+/// - [ ] list
+/// - [ ] scan
+/// - [ ] presign
+/// - [ ] blocking
+///
+/// # Configuration
+///
+/// - `root`: Set the work dir for backend.
+/// - `bucket`: Set the container name for backend.
+/// - `endpoint`: Set the endpoint for backend.
+/// - `key`: Set the authorization key for the backend, do not set if you want to read public bucket
+///
+/// ## Authorization keys
+///
+/// There are two types of key in the Supabase, one is anon_key(Client key), another one is
+/// service_role_key(Secret key). The former one can only write public resources while the latter one
+/// can access all resources. Note that if you want to read public resources, do not set the key.
+///
+/// # Example
+///
+/// ```no_run
+/// use anyhow::Result;
+/// use opendal::services::Supabase;
+/// use opendal::Operator;
+///
+/// #[tokio::main]
+/// async fn main() -> Result<()> {
+///     let mut builder = Supabase::default();
+///     builder.root("/");
+///     builder.bucket("test_bucket");
+///     builder.endpoint("http://127.0.0.1:54321");
+///     // this sets up the anon_key, which means this operator can only write public resource
+///     builder.key("some_anon_key");
+///
+///     let op: Operator = Operator::new(builder)?.finish();
+///    
+///     Ok(())
+/// }
+/// ```
+#[derive(Default)]
+pub struct SupabaseBuilder {
+    root: Option<String>,
+
+    bucket: String,
+    endpoint: Option<String>,
+
+    key: Option<String>,
+
+    // todo: optional public, currently true always
+    // todo: optional file_size_limit, currently 0
+    // todo: optional allowed_mime_types, currently only string
+    http_client: Option<HttpClient>,
+}
+
+impl Debug for SupabaseBuilder {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("SupabaseBuilder")
+            .field("root", &self.root)
+            .field("bucket", &self.bucket)
+            .field("endpoint", &self.endpoint)
+            .finish_non_exhaustive()
+    }
+}
+
+impl SupabaseBuilder {
+    /// Set root of this backend.
+    ///
+    /// All operations will happen under this root.
+    pub fn root(&mut self, root: &str) -> &mut Self {
+        self.root = if root.is_empty() {
+            None
+        } else {
+            Some(root.to_string())
+        };
+
+        self
+    }
+
+    /// Set bucket name of this backend.
+    pub fn bucket(&mut self, bucket: &str) -> &mut Self {
+        self.bucket = bucket.to_string();
+        self
+    }
+
+    /// Set endpoint of this backend.
+    ///
+    /// Endpoint must be full uri
+    pub fn endpoint(&mut self, endpoint: &str) -> &mut Self {
+        self.endpoint = if endpoint.is_empty() {
+            None
+        } else {
+            Some(endpoint.trim_end_matches('/').to_string())
+        };
+
+        self
+    }
+
+    /// Set the authorization key for this backend
+    /// Do not set this key if you want to read public bucket
+    pub fn key(&mut self, key: &str) -> &mut Self {
+        self.key = Some(key.to_string());
+        self
+    }
+
+    /// Specify the http client that used by this service.
+    ///
+    /// # Notes
+    ///
+    /// This API is part of OpenDAL's Raw API. `HttpClient` could be changed
+    /// during minor updates.
+    pub fn http_client(&mut self, client: HttpClient) -> &mut Self {
+        self.http_client = Some(client);
+        self
+    }
+}
+
+impl Builder for SupabaseBuilder {
+    const SCHEME: Scheme = Scheme::Supabase;
+    type Accessor = SupabaseBackend;
+
+    fn from_map(map: std::collections::HashMap<String, String>) -> Self {
+        let mut builder = SupabaseBuilder::default();
+
+        map.get("root").map(|v| builder.root(v));
+        map.get("bucket").map(|v| builder.bucket(v));
+        map.get("endpoint").map(|v| builder.endpoint(v));
+        map.get("key").map(|v| builder.key(v));
+
+        builder
+    }
+
+    fn build(&mut self) -> Result<Self::Accessor> {
+        let root = normalize_root(&self.root.take().unwrap_or_default());
+        debug!("backend use root {}", &root);
+
+        let bucket = &self.bucket;
+
+        let endpoint = self.endpoint.take().unwrap_or_default();
+
+        let http_client = if let Some(client) = self.http_client.take() {
+            client
+        } else {
+            HttpClient::new().map_err(|err| {
+                err.with_operation("Builder::build")
+                    .with_context("service", Scheme::Supabase)
+            })?
+        };
+
+        let key = self.key.as_ref().map(|k| k.to_owned());
+
+        let core = SupabaseCore::new(&root, bucket, &endpoint, key, http_client);
+
+        let core = Arc::new(core);
+
+        Ok(SupabaseBackend { core })
+    }
+}
+
+#[derive(Debug)]
+pub struct SupabaseBackend {
+    core: Arc<SupabaseCore>,
+}
+
+#[async_trait]
+impl Accessor for SupabaseBackend {
+    type Reader = IncomingAsyncBody;
+    type BlockingReader = ();
+    type Writer = SupabaseWriter;
+    type BlockingWriter = ();
+    // todo: implement Pager to support list and scan
+    type Pager = ();
+    type BlockingPager = ();
+
+    fn info(&self) -> AccessorInfo {
+        let mut am = AccessorInfo::default();
+        am.set_scheme(Scheme::Supabase)
+            .set_root(&self.core.root)
+            .set_name(&self.core.bucket)
+            .set_capability(Capability {
+                stat: true,
+                read: true,
+                write: true,
+
+                ..Default::default()
+            });
+
+        am
+    }
+
+    async fn read(&self, path: &str, _args: OpRead) -> Result<(RpRead, Self::Reader)> {
+        let resp = if self.core.key.is_some() {
+            self.core.supabase_get_object_auth(path).await?
+        } else {
+            self.core.supabase_get_object_public(path).await?
+        };
+
+        let status = resp.status();
+
+        match status {
+            StatusCode::OK | StatusCode::PARTIAL_CONTENT => {
+                let meta = parse_into_metadata(path, resp.headers())?;
+                Ok((RpRead::with_metadata(meta), resp.into_body()))
+            }
+            _ => Err(parse_error(resp).await?),
+        }
+    }
+
+    async fn write(&self, path: &str, args: OpWrite) -> Result<(RpWrite, Self::Writer)> {
+        if args.content_length().is_none() {
+            return Err(Error::new(
+                ErrorKind::Unsupported,
+                "write without content length is not supported",
+            ));
+        }
+
+        Ok((
+            RpWrite::default(),
+            SupabaseWriter::new(self.core.clone(), path, args),
+        ))
+    }
+
+    async fn stat(&self, path: &str, _args: OpStat) -> Result<RpStat> {
+        // Stat root always returns a DIR.
+        if path == "/" {
+            return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
+        }
+
+        let resp = if self.core.key.is_some() {
+            self.core.supabase_get_object_info_auth(path).await?

Review Comment:
   We only need `supabase_get_object_info`



##########
core/src/services/supabase/core.rs:
##########
@@ -0,0 +1,226 @@
+// 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::fmt::Debug;
+
+use http::header::CONTENT_LENGTH;
+use http::header::CONTENT_TYPE;
+use http::HeaderValue;
+use http::Request;
+use http::Response;
+
+use crate::raw::*;
+use crate::*;
+
+mod supabase_urls {
+    pub const SUPABASE_UPLOAD_PREFIX: &str = "storage/v1/object";

Review Comment:
   I prefer writing them directly. They are not shared very often.



-- 
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: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org