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 13:07:31 UTC

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

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