From 9e1e3c8e6a5e88221f2b0f04087eecb14dd5f14b Mon Sep 17 00:00:00 2001 From: suyanhanx Date: Sun, 16 Jul 2023 21:16:12 +0800 Subject: [PATCH 1/4] try to enable Signed-off-by: suyanhanx --- .../service_test_vercel_artifacts.yml | 63 +++++++++++++++++++ core/src/services/vercel_artifacts/backend.rs | 56 +++++++++++++++-- 2 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/service_test_vercel_artifacts.yml diff --git a/.github/workflows/service_test_vercel_artifacts.yml b/.github/workflows/service_test_vercel_artifacts.yml new file mode 100644 index 000000000000..ba73573087ac --- /dev/null +++ b/.github/workflows/service_test_vercel_artifacts.yml @@ -0,0 +1,63 @@ +# 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. + +name: Service Test Vercel Artifacts + +on: + push: + branches: + - main + pull_request: + branches: + - main + paths: + - "core/src/**" + - "core/tests/**" + - "!core/src/docs/**" + - "!core/src/services/**" + - "core/src/services/vercel_artifacts/**" + - ".github/workflows/service_test_vercel_artifacts.yml" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} + cancel-in-progress: true + +jobs: + vercel_artifacts: + runs-on: ubuntu-latest + if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork + steps: + - uses: actions/checkout@v3 + - name: Setup Rust toolchain + uses: ./.github/actions/setup + with: + need-nextest: true + + - name: Load secret + id: op-load-secret + uses: 1password/load-secrets-action@v1 + with: + export-env: true + env: + OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} + OPENDAL_VERCEL_ARTIFACTS_TEST: op://services/vercel_artifacts/test + OPENDAL_VERCEL_ARTIFACTS_ACCESS_TOKEN: op://services/vercel_artifacts/access_token + + - name: Test + shell: bash + working-directory: core + run: cargo nextest run vercel_artifacts --features=services-vercel-artifacts diff --git a/core/src/services/vercel_artifacts/backend.rs b/core/src/services/vercel_artifacts/backend.rs index aa79b69ee946..105a34926ca4 100644 --- a/core/src/services/vercel_artifacts/backend.rs +++ b/core/src/services/vercel_artifacts/backend.rs @@ -56,11 +56,17 @@ impl Accessor for VercelArtifactsBackend { let mut ma = AccessorInfo::default(); ma.set_scheme(Scheme::VercelArtifacts) .set_capability(Capability { + stat: true, + read: true, read_can_next: true, write: true, + create_dir: true, + + delete: true, + ..Default::default() }); @@ -95,15 +101,42 @@ impl Accessor for VercelArtifactsBackend { VercelArtifactsWriter::new(self.clone(), args, path.to_string()), )) } + + async fn stat(&self, path: &str, _args: OpStat) -> Result { + if (path == "/") || (path.ends_with('/')) { + return Ok(RpStat::new(Metadata::new(EntryMode::DIR))); + } + + let res = self.vercel_artifacts_stat(path).await?; + + let status = res.status(); + + match status { + StatusCode::OK => { + let meta = parse_into_metadata(path, res.headers())?; + Ok(RpStat::new(meta)) + } + + _ => Err(parse_error(res).await?), + } + } + + async fn create_dir(&self, _path: &str, _args: OpCreateDir) -> Result { + Ok(RpCreateDir::default()) + } + + async fn delete(&self, _path: &str, _args: OpDelete) -> Result { + Ok(RpDelete::default()) + } } impl VercelArtifactsBackend { async fn vercel_artifacts_get( &self, - path: &str, + hash: &str, args: OpRead, ) -> Result> { - let url: String = format!("https://api.vercel.com/v8/artifacts/{}", path); + let url: String = format!("https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash)); let mut req = Request::get(&url); @@ -127,12 +160,11 @@ impl VercelArtifactsBackend { size: u64, body: AsyncBody, ) -> Result> { - let url = format!("https://api.vercel.com/v8/artifacts/{}", hash); + let url = format!("https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash)); let mut req = Request::put(&url); let auth_header_content = format!("Bearer {}", self.access_token); - // Borrowed from [vercel/remote-cache](https://github.com/vercel/remote-cache/blob/46cbc71346c84ec6c3022ec660ade52a25a20013/packages/remote/src/artifact-request.ts#LL41C34-L41C58) req = req.header(header::CONTENT_TYPE, "application/octet-stream"); req = req.header(header::AUTHORIZATION, auth_header_content); req = req.header(header::CONTENT_LENGTH, size); @@ -141,4 +173,20 @@ impl VercelArtifactsBackend { self.client.send(req).await } + + pub async fn vercel_artifacts_stat(&self, hash: &str) -> Result> { + let url = format!("https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash)); + + let mut req = Request::head(&url); + + let auth_header_content = format!("Bearer {}", self.access_token); + req = req.header(header::AUTHORIZATION, auth_header_content); + req = req.header(header::CONTENT_LENGTH, 0); + + let req = req + .body(AsyncBody::Empty) + .map_err(new_request_build_error)?; + + self.client.send(req).await + } } From 092dd9ee5f2c34caf15ebabc3de91e2c73a79fa9 Mon Sep 17 00:00:00 2001 From: suyanhanx Date: Sun, 16 Jul 2023 21:20:14 +0800 Subject: [PATCH 2/4] fmt Signed-off-by: suyanhanx --- .../service_test_vercel_artifacts.yml | 63 ------------------- core/src/services/vercel_artifacts/backend.rs | 15 ++++- 2 files changed, 12 insertions(+), 66 deletions(-) delete mode 100644 .github/workflows/service_test_vercel_artifacts.yml diff --git a/.github/workflows/service_test_vercel_artifacts.yml b/.github/workflows/service_test_vercel_artifacts.yml deleted file mode 100644 index ba73573087ac..000000000000 --- a/.github/workflows/service_test_vercel_artifacts.yml +++ /dev/null @@ -1,63 +0,0 @@ -# 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. - -name: Service Test Vercel Artifacts - -on: - push: - branches: - - main - pull_request: - branches: - - main - paths: - - "core/src/**" - - "core/tests/**" - - "!core/src/docs/**" - - "!core/src/services/**" - - "core/src/services/vercel_artifacts/**" - - ".github/workflows/service_test_vercel_artifacts.yml" - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} - cancel-in-progress: true - -jobs: - vercel_artifacts: - runs-on: ubuntu-latest - if: github.event_name == 'push' || !github.event.pull_request.head.repo.fork - steps: - - uses: actions/checkout@v3 - - name: Setup Rust toolchain - uses: ./.github/actions/setup - with: - need-nextest: true - - - name: Load secret - id: op-load-secret - uses: 1password/load-secrets-action@v1 - with: - export-env: true - env: - OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} - OPENDAL_VERCEL_ARTIFACTS_TEST: op://services/vercel_artifacts/test - OPENDAL_VERCEL_ARTIFACTS_ACCESS_TOKEN: op://services/vercel_artifacts/access_token - - - name: Test - shell: bash - working-directory: core - run: cargo nextest run vercel_artifacts --features=services-vercel-artifacts diff --git a/core/src/services/vercel_artifacts/backend.rs b/core/src/services/vercel_artifacts/backend.rs index 105a34926ca4..11f025aab045 100644 --- a/core/src/services/vercel_artifacts/backend.rs +++ b/core/src/services/vercel_artifacts/backend.rs @@ -136,7 +136,10 @@ impl VercelArtifactsBackend { hash: &str, args: OpRead, ) -> Result> { - let url: String = format!("https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash)); + let url: String = format!( + "https://api.vercel.com/v8/artifacts/{}", + percent_encode_path(hash) + ); let mut req = Request::get(&url); @@ -160,7 +163,10 @@ impl VercelArtifactsBackend { size: u64, body: AsyncBody, ) -> Result> { - let url = format!("https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash)); + let url = format!( + "https://api.vercel.com/v8/artifacts/{}", + percent_encode_path(hash) + ); let mut req = Request::put(&url); @@ -175,7 +181,10 @@ impl VercelArtifactsBackend { } pub async fn vercel_artifacts_stat(&self, hash: &str) -> Result> { - let url = format!("https://api.vercel.com/v8/artifacts/{}", percent_encode_path(hash)); + let url = format!( + "https://api.vercel.com/v8/artifacts/{}", + percent_encode_path(hash) + ); let mut req = Request::head(&url); From 5ff822ca5b8cfb206394eaeb60a2eabb6e81921b Mon Sep 17 00:00:00 2001 From: suyanhanx Date: Mon, 17 Jul 2023 13:27:37 +0800 Subject: [PATCH 3/4] remove Signed-off-by: suyanhanx --- core/src/services/vercel_artifacts/backend.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/core/src/services/vercel_artifacts/backend.rs b/core/src/services/vercel_artifacts/backend.rs index 11f025aab045..b1f59676b6a6 100644 --- a/core/src/services/vercel_artifacts/backend.rs +++ b/core/src/services/vercel_artifacts/backend.rs @@ -120,14 +120,6 @@ impl Accessor for VercelArtifactsBackend { _ => Err(parse_error(res).await?), } } - - async fn create_dir(&self, _path: &str, _args: OpCreateDir) -> Result { - Ok(RpCreateDir::default()) - } - - async fn delete(&self, _path: &str, _args: OpDelete) -> Result { - Ok(RpDelete::default()) - } } impl VercelArtifactsBackend { From 42788b596925af88d5c7d94ebd76f47d85e522a8 Mon Sep 17 00:00:00 2001 From: suyanhanx Date: Mon, 17 Jul 2023 13:33:59 +0800 Subject: [PATCH 4/4] remove Signed-off-by: suyanhanx --- core/src/services/vercel_artifacts/backend.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/core/src/services/vercel_artifacts/backend.rs b/core/src/services/vercel_artifacts/backend.rs index b1f59676b6a6..b8a9d649162e 100644 --- a/core/src/services/vercel_artifacts/backend.rs +++ b/core/src/services/vercel_artifacts/backend.rs @@ -63,10 +63,6 @@ impl Accessor for VercelArtifactsBackend { write: true, - create_dir: true, - - delete: true, - ..Default::default() });