Skip to content

Commit 39ce403

Browse files
authored
fix: ghac doesn't support delete anymore (#5628)
* fix: ghac doesn't support delete anymore Signed-off-by: Xuanwo <[email protected]> * Fix tests Signed-off-by: Xuanwo <[email protected]> * Fix tests Signed-off-by: Xuanwo <[email protected]> * Fix tests Signed-off-by: Xuanwo <[email protected]> --------- Signed-off-by: Xuanwo <[email protected]>
1 parent 079b98a commit 39ce403

File tree

12 files changed

+42
-202
lines changed

12 files changed

+42
-202
lines changed

.github/workflows/service_test_ghac.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
- name: Test
6060
shell: bash
6161
working-directory: core
62-
run: cargo nextest run behavior --features tests,services-ghac
62+
run: cargo test behavior --features tests,services-ghac
6363
env:
6464
OPENDAL_TEST: ghac
6565
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

core/src/services/ghac/backend.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ use http::header::AUTHORIZATION;
2626
use http::header::CONTENT_LENGTH;
2727
use http::header::CONTENT_RANGE;
2828
use http::header::CONTENT_TYPE;
29-
use http::header::USER_AGENT;
3029
use http::Request;
3130
use http::Response;
3231
use http::StatusCode;
3332
use log::debug;
3433
use serde::Deserialize;
3534
use serde::Serialize;
3635

37-
use super::delete::GhacDeleter;
3836
use super::error::parse_error;
3937
use super::writer::GhacWriter;
4038
use crate::raw::*;
@@ -54,14 +52,6 @@ const ACTIONS_CACHE_URL: &str = "ACTIONS_CACHE_URL";
5452
/// This token will be valid for 6h and github action will running for 6
5553
/// hours at most. So we don't need to refetch it again.
5654
const ACTIONS_RUNTIME_TOKEN: &str = "ACTIONS_RUNTIME_TOKEN";
57-
/// The token provided by workflow;
58-
const GITHUB_TOKEN: &str = "GITHUB_TOKEN";
59-
/// The github api url for ghac.
60-
const GITHUB_API_URL: &str = "GITHUB_API_URL";
61-
/// The repository that runs this action.
62-
const GITHUB_REPOSITORY: &str = "GITHUB_REPOSITORY";
63-
/// The github API version that used by OpenDAL.
64-
const GITHUB_API_VERSION: &str = "2022-11-28";
6555

6656
fn value_or_env(
6757
explicit_value: Option<String>,
@@ -198,11 +188,6 @@ impl Builder for GhacBuilder {
198188
.clone()
199189
.unwrap_or_else(|| "opendal".to_string()),
200190

201-
api_url: env::var(GITHUB_API_URL)
202-
.unwrap_or_else(|_| "https://api.github.com".to_string()),
203-
api_token: env::var(GITHUB_TOKEN).unwrap_or_default(),
204-
repo: env::var(GITHUB_REPOSITORY).unwrap_or_default(),
205-
206191
client,
207192
};
208193

@@ -220,18 +205,14 @@ pub struct GhacBackend {
220205
catch_token: String,
221206
version: String,
222207

223-
api_url: String,
224-
pub api_token: String,
225-
repo: String,
226-
227208
pub client: HttpClient,
228209
}
229210

230211
impl Access for GhacBackend {
231212
type Reader = HttpBody;
232213
type Writer = GhacWriter;
233214
type Lister = ();
234-
type Deleter = oio::OneShotDeleter<GhacDeleter>;
215+
type Deleter = ();
235216
type BlockingReader = ();
236217
type BlockingWriter = ();
237218
type BlockingLister = ();
@@ -258,7 +239,6 @@ impl Access for GhacBackend {
258239

259240
write: true,
260241
write_can_multi: true,
261-
delete: true,
262242

263243
shared: true,
264244

@@ -356,13 +336,6 @@ impl Access for GhacBackend {
356336

357337
Ok((RpWrite::default(), GhacWriter::new(self.clone(), cache_id)))
358338
}
359-
360-
async fn delete(&self) -> Result<(RpDelete, Self::Deleter)> {
361-
Ok((
362-
RpDelete::default(),
363-
oio::OneShotDeleter::new(GhacDeleter::new(self.clone())),
364-
))
365-
}
366339
}
367340

368341
impl GhacBackend {
@@ -463,26 +436,6 @@ impl GhacBackend {
463436

464437
Ok(req)
465438
}
466-
467-
pub async fn ghac_delete(&self, path: &str) -> Result<Response<Buffer>> {
468-
let p = build_abs_path(&self.root, path);
469-
470-
let url = format!(
471-
"{}/repos/{}/actions/caches?key={}",
472-
self.api_url,
473-
self.repo,
474-
percent_encode_path(&p)
475-
);
476-
477-
let mut req = Request::delete(&url);
478-
req = req.header(AUTHORIZATION, format!("Bearer {}", self.api_token));
479-
req = req.header(USER_AGENT, format!("opendal/{VERSION} (service ghac)"));
480-
req = req.header("X-GitHub-Api-Version", GITHUB_API_VERSION);
481-
482-
let req = req.body(Buffer::new()).map_err(new_request_build_error)?;
483-
484-
self.client.send(req).await
485-
}
486439
}
487440

488441
#[derive(Deserialize)]

core/src/services/ghac/delete.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

core/src/services/ghac/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#[cfg(feature = "services-ghac")]
19-
mod delete;
2018
#[cfg(feature = "services-ghac")]
2119
mod error;
2220
#[cfg(feature = "services-ghac")]

core/tests/behavior/blocking_copy.rs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,11 @@ pub fn tests(op: &Operator, tests: &mut Vec<Trial>) {
4040

4141
/// Copy a file and test with stat.
4242
pub fn test_blocking_copy_file(op: BlockingOperator) -> Result<()> {
43-
let source_path = uuid::Uuid::new_v4().to_string();
44-
let (source_content, _) = gen_bytes(op.info().full_capability());
43+
let (source_path, source_content, _) = TEST_FIXTURE.new_file(op.clone());
4544

4645
op.write(&source_path, source_content.clone())?;
4746

48-
let target_path = uuid::Uuid::new_v4().to_string();
47+
let target_path = TEST_FIXTURE.new_file_path();
4948

5049
op.copy(&source_path, &target_path)?;
5150

@@ -55,8 +54,6 @@ pub fn test_blocking_copy_file(op: BlockingOperator) -> Result<()> {
5554
format!("{:x}", Sha256::digest(&source_content)),
5655
);
5756

58-
op.delete(&source_path).expect("delete must succeed");
59-
op.delete(&target_path).expect("delete must succeed");
6057
Ok(())
6158
}
6259

@@ -96,46 +93,37 @@ pub fn test_blocking_copy_target_dir(op: BlockingOperator) -> Result<()> {
9693
return Ok(());
9794
}
9895

99-
let source_path = uuid::Uuid::new_v4().to_string();
100-
let (source_content, _) = gen_bytes(op.info().full_capability());
96+
let (source_path, source_content, _) = TEST_FIXTURE.new_file(op.clone());
10197

10298
op.write(&source_path, source_content)?;
10399

104-
let target_path = format!("{}/", uuid::Uuid::new_v4());
100+
let target_path = TEST_FIXTURE.new_dir_path();
105101

106102
op.create_dir(&target_path)?;
107103

108104
let err = op
109105
.copy(&source_path, &target_path)
110106
.expect_err("copy must fail");
111107
assert_eq!(err.kind(), ErrorKind::IsADirectory);
112-
113-
op.delete(&source_path).expect("delete must succeed");
114-
op.delete(&target_path).expect("delete must succeed");
115108
Ok(())
116109
}
117110

118111
/// Copy a file to self should return an error.
119112
pub fn test_blocking_copy_self(op: BlockingOperator) -> Result<()> {
120-
let source_path = uuid::Uuid::new_v4().to_string();
121-
let (source_content, _size) = gen_bytes(op.info().full_capability());
113+
let (source_path, source_content, _) = TEST_FIXTURE.new_file(op.clone());
122114

123115
op.write(&source_path, source_content)?;
124116

125117
let err = op
126118
.copy(&source_path, &source_path)
127119
.expect_err("copy must fail");
128120
assert_eq!(err.kind(), ErrorKind::IsSameFile);
129-
130-
op.delete(&source_path).expect("delete must succeed");
131121
Ok(())
132122
}
133123

134124
/// Copy to a nested path, parent path should be created successfully.
135125
pub fn test_blocking_copy_nested(op: BlockingOperator) -> Result<()> {
136-
let source_path = uuid::Uuid::new_v4().to_string();
137-
let (source_content, _) = gen_bytes(op.info().full_capability());
138-
126+
let (source_path, source_content, _) = TEST_FIXTURE.new_file(op.clone());
139127
op.write(&source_path, source_content.clone())?;
140128

141129
let target_path = format!(
@@ -144,6 +132,7 @@ pub fn test_blocking_copy_nested(op: BlockingOperator) -> Result<()> {
144132
uuid::Uuid::new_v4(),
145133
uuid::Uuid::new_v4()
146134
);
135+
TEST_FIXTURE.add_path(target_path.clone());
147136

148137
op.copy(&source_path, &target_path)?;
149138

@@ -152,23 +141,15 @@ pub fn test_blocking_copy_nested(op: BlockingOperator) -> Result<()> {
152141
format!("{:x}", Sha256::digest(target_content)),
153142
format!("{:x}", Sha256::digest(&source_content)),
154143
);
155-
156-
op.delete(&source_path).expect("delete must succeed");
157-
op.delete(&target_path).expect("delete must succeed");
158144
Ok(())
159145
}
160146

161147
/// Copy to a exist path should overwrite successfully.
162148
pub fn test_blocking_copy_overwrite(op: BlockingOperator) -> Result<()> {
163-
let source_path = uuid::Uuid::new_v4().to_string();
164-
let (source_content, _) = gen_bytes(op.info().full_capability());
165-
149+
let (source_path, source_content, _) = TEST_FIXTURE.new_file(op.clone());
166150
op.write(&source_path, source_content.clone())?;
167151

168-
let target_path = uuid::Uuid::new_v4().to_string();
169-
let (target_content, _) = gen_bytes(op.info().full_capability());
170-
assert_ne!(source_content, target_content);
171-
152+
let (target_path, target_content, _) = TEST_FIXTURE.new_file(op.clone());
172153
op.write(&target_path, target_content)?;
173154

174155
op.copy(&source_path, &target_path)?;
@@ -178,8 +159,5 @@ pub fn test_blocking_copy_overwrite(op: BlockingOperator) -> Result<()> {
178159
format!("{:x}", Sha256::digest(target_content)),
179160
format!("{:x}", Sha256::digest(&source_content)),
180161
);
181-
182-
op.delete(&source_path).expect("delete must succeed");
183-
op.delete(&target_path).expect("delete must succeed");
184162
Ok(())
185163
}

core/tests/behavior/blocking_create_dir.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@ pub fn test_blocking_create_dir(op: BlockingOperator) -> Result<()> {
3737
return Ok(());
3838
}
3939

40-
let path = format!("{}/", uuid::Uuid::new_v4());
40+
let path = TEST_FIXTURE.new_dir_path();
4141

4242
op.create_dir(&path)?;
4343

4444
let meta = op.stat(&path)?;
4545
assert_eq!(meta.mode(), EntryMode::DIR);
46-
47-
op.delete(&path).expect("delete must succeed");
4846
Ok(())
4947
}
5048

@@ -54,15 +52,12 @@ pub fn test_blocking_create_dir_existing(op: BlockingOperator) -> Result<()> {
5452
return Ok(());
5553
}
5654

57-
let path = format!("{}/", uuid::Uuid::new_v4());
58-
55+
let path = TEST_FIXTURE.new_dir_path();
5956
op.create_dir(&path)?;
6057

6158
op.create_dir(&path)?;
6259

6360
let meta = op.stat(&path)?;
6461
assert_eq!(meta.mode(), EntryMode::DIR);
65-
66-
op.delete(&path).expect("delete must succeed");
6762
Ok(())
6863
}

core/tests/behavior/blocking_list.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn test_blocking_list_dir(op: BlockingOperator) -> Result<()> {
4343
let parent = uuid::Uuid::new_v4().to_string();
4444
let path = format!("{parent}/{}", uuid::Uuid::new_v4());
4545
debug!("Generate a random file: {}", &path);
46-
let (content, size) = gen_bytes(op.info().full_capability());
46+
let (_, content, size) = TEST_FIXTURE.new_file_with_path(op.clone(), &path);
4747

4848
op.write(&path, content).expect("write must succeed");
4949

@@ -61,14 +61,12 @@ pub fn test_blocking_list_dir(op: BlockingOperator) -> Result<()> {
6161
}
6262
}
6363
assert!(found, "file should be found in list");
64-
65-
op.delete(&path).expect("delete must succeed");
6664
Ok(())
6765
}
6866

6967
/// List non exist dir should return nothing.
7068
pub fn test_blocking_list_non_exist_dir(op: BlockingOperator) -> Result<()> {
71-
let dir = format!("{}/", uuid::Uuid::new_v4());
69+
let dir = TEST_FIXTURE.new_dir_path();
7270

7371
let obs = op.lister(&dir)?;
7472
let mut objects = HashMap::new();
@@ -84,6 +82,10 @@ pub fn test_blocking_list_non_exist_dir(op: BlockingOperator) -> Result<()> {
8482

8583
// Remove all should remove all in this path.
8684
pub fn test_blocking_remove_all(op: BlockingOperator) -> Result<()> {
85+
if !op.info().full_capability().delete {
86+
return Ok(());
87+
}
88+
8789
let parent = uuid::Uuid::new_v4().to_string();
8890

8991
let expected = [

0 commit comments

Comments
 (0)