Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ pub mod test_config_helpers {

/// URL of the local GCP emulator.
pub const LOCAL_GCP_EMULATOR_ENDPOINT: &str = "http://127.0.0.1:4443";

/// Creates a storage connecting to a local emulated google cloud storage.
pub fn new_emulated_google_cloud_storage(
uri: &Uri,
Expand All @@ -67,7 +66,9 @@ pub mod test_config_helpers {
let cfg = opendal::services::Gcs::default()
.bucket(&bucket)
.root(&root.to_string_lossy())
.endpoint(LOCAL_GCP_EMULATOR_ENDPOINT);
.endpoint(LOCAL_GCP_EMULATOR_ENDPOINT)
.allow_anonymous() // Disable authentication for fake GCS server
.disable_vm_metadata(); // Disable GCE metadata server requests
let store = OpendalStorage::new_google_cloud_storage(uri.clone(), cfg)?;
Ok(store)
}
Expand Down
33 changes: 6 additions & 27 deletions quickwit/quickwit-storage/tests/google_cloud_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,11 @@ mod gcp_storage_test_suite {
LOCAL_GCP_EMULATOR_ENDPOINT, new_emulated_google_cloud_storage,
};

pub async fn sign_gcs_request(req: &mut reqwest::Request) -> anyhow::Result<()> {
let signer = reqsign::google::default_signer("storage");

// Create http::Request and extract parts for signing
let http_req = http::Request::builder()
.method(req.method())
.uri(req.url().as_str())
.version(http::Version::HTTP_11)
.body(())?;

let (mut parts, _body) = http_req.into_parts();

// Copy headers from reqwest request
parts.headers = req.headers().clone();

// Sign the request parts
signer.sign(&mut parts, None).await?;

// Update the original request with signed headers
let headers = req.headers_mut();
headers.clear();
for (key, value) in &parts.headers {
headers.insert(key.clone(), value.clone());
}

Ok(())
pub fn sign_gcs_request(req: &mut reqwest::Request) {
req.headers_mut().insert(
reqwest::header::AUTHORIZATION,
reqwest::header::HeaderValue::from_str("Bearer dummy").unwrap(),
);
}

async fn create_gcs_bucket(bucket_name: &str) -> anyhow::Result<()> {
Expand All @@ -67,7 +46,7 @@ mod gcp_storage_test_suite {
.header(reqwest::header::CONTENT_TYPE, "application/json")
.build()?;

sign_gcs_request(&mut request).await?;
sign_gcs_request(&mut request);

let response = client.execute(request).await?;

Expand Down