Skip to content

Commit 21d9568

Browse files
authored
feat: Expose disable_config_load opendal GCS option (#847)
1 parent d51e818 commit 21d9568

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

crates/iceberg/src/io/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ use storage_fs::*;
8888
mod storage_gcs;
8989
#[cfg(feature = "storage-gcs")]
9090
pub use storage_gcs::*;
91+
92+
fn is_truthy(value: &str) -> bool {
93+
["true", "t", "1", "on"].contains(&value.to_lowercase().as_str())
94+
}

crates/iceberg/src/io/storage_gcs.rs

+24
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use opendal::services::GcsConfig;
2222
use opendal::Operator;
2323
use url::Url;
2424

25+
use crate::io::is_truthy;
2526
use crate::{Error, ErrorKind, Result};
2627

2728
// Reference: https://github.com/apache/iceberg/blob/main/gcp/src/main/java/org/apache/iceberg/gcp/GCPProperties.java
@@ -41,6 +42,13 @@ pub const GCS_CREDENTIALS_JSON: &str = "gcs.credentials-json";
4142
/// Google Cloud Storage token
4243
pub const GCS_TOKEN: &str = "gcs.oauth2.token";
4344

45+
/// Option to skip signing requests (e.g. for public buckets/folders).
46+
pub const GCS_ALLOW_ANONYMOUS: &str = "gcs.allow-anonymous";
47+
/// Option to skip loading the credential from GCE metadata server (typically used in conjunction with `GCS_ALLOW_ANONYMOUS`).
48+
pub const GCS_DISABLE_VM_METADATA: &str = "gcs.disable-vm-metadata";
49+
/// Option to skip loading configuration from config file and the env.
50+
pub const GCS_DISABLE_CONFIG_LOAD: &str = "gcs.disable-config-load";
51+
4452
/// Parse iceberg properties to [`GcsConfig`].
4553
pub(crate) fn gcs_config_parse(mut m: HashMap<String, String>) -> Result<GcsConfig> {
4654
let mut cfg = GcsConfig::default();
@@ -63,6 +71,22 @@ pub(crate) fn gcs_config_parse(mut m: HashMap<String, String>) -> Result<GcsConf
6371
cfg.disable_config_load = true;
6472
}
6573

74+
if let Some(allow_anonymous) = m.remove(GCS_ALLOW_ANONYMOUS) {
75+
if is_truthy(allow_anonymous.to_lowercase().as_str()) {
76+
cfg.allow_anonymous = true;
77+
}
78+
}
79+
if let Some(disable_ec2_metadata) = m.remove(GCS_DISABLE_VM_METADATA) {
80+
if is_truthy(disable_ec2_metadata.to_lowercase().as_str()) {
81+
cfg.disable_vm_metadata = true;
82+
}
83+
};
84+
if let Some(disable_config_load) = m.remove(GCS_DISABLE_CONFIG_LOAD) {
85+
if is_truthy(disable_config_load.to_lowercase().as_str()) {
86+
cfg.disable_config_load = true;
87+
}
88+
};
89+
6690
Ok(cfg)
6791
}
6892

crates/iceberg/src/io/storage_s3.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use opendal::services::S3Config;
2222
use opendal::{Configurator, Operator};
2323
use url::Url;
2424

25+
use crate::io::is_truthy;
2526
use crate::{Error, ErrorKind, Result};
2627

2728
/// Following are arguments for [s3 file io](https://py.iceberg.apache.org/configuration/#s3).
@@ -66,10 +67,6 @@ pub const S3_DISABLE_EC2_METADATA: &str = "s3.disable-ec2-metadata";
6667
/// Option to skip loading configuration from config file and the env.
6768
pub const S3_DISABLE_CONFIG_LOAD: &str = "s3.disable-config-load";
6869

69-
fn is_truthy(value: &str) -> bool {
70-
["true", "t", "1", "on"].contains(&value)
71-
}
72-
7370
/// Parse iceberg props to s3 config.
7471
pub(crate) fn s3_config_parse(mut m: HashMap<String, String>) -> Result<S3Config> {
7572
let mut cfg = S3Config::default();

0 commit comments

Comments
 (0)