Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "chore: Make bucket name required in storage config" #2337

Merged
merged 1 commit into from
Jan 2, 2024
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ benchmarks/artifacts/
/deps

.vscode/
.helix/

# Spark jar for iceberg data generation
*.jar
Expand Down
2 changes: 1 addition & 1 deletion crates/glaredb/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl RunCommand for MetastoreArgs {
(Some(bucket), Some(service_account_path), None) => {
let service_account_key = std::fs::read_to_string(service_account_path)?;
StorageConfig::Gcs {
bucket,
bucket: Some(bucket),
service_account_key,
}
}
Expand Down
29 changes: 19 additions & 10 deletions crates/object_store_util/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ pub enum StorageConfig {
secret_access_key: String,
region: Option<String>,
endpoint: Option<String>,
bucket: String,
bucket: Option<String>,
},
Gcs {
service_account_key: String,
bucket: String,
bucket: Option<String>,
},
Azure {
account_name: String,
access_key: String,
container_name: String,
container_name: Option<String>,
},
Local {
path: PathBuf,
Expand All @@ -49,7 +49,6 @@ impl StorageConfig {
let mut builder = AmazonS3Builder::new()
.with_access_key_id(access_key_id)
.with_secret_access_key(secret_access_key)
.with_bucket_name(bucket)
.with_region(region.clone().unwrap_or_default());

if let Some(endpoint) = endpoint {
Expand All @@ -67,15 +66,22 @@ impl StorageConfig {
}
}

if let Some(bucket) = bucket {
builder = builder.with_bucket_name(bucket);
}

Arc::new(builder.build()?)
}
StorageConfig::Gcs {
service_account_key,
bucket,
} => {
let builder = GoogleCloudStorageBuilder::new()
.with_service_account_key(service_account_key)
.with_bucket_name(bucket);
let mut builder =
GoogleCloudStorageBuilder::new().with_service_account_key(service_account_key);

if let Some(bucket) = bucket {
builder = builder.with_bucket_name(bucket);
}

Arc::new(builder.build()?)
}
Expand All @@ -84,10 +90,13 @@ impl StorageConfig {
access_key,
container_name,
} => {
let builder = MicrosoftAzureBuilder::new()
let mut builder = MicrosoftAzureBuilder::new()
.with_account(account_name)
.with_access_key(access_key)
.with_container_name(container_name);
.with_access_key(access_key);

if let Some(container_name) = container_name {
builder = builder.with_container_name(container_name);
}

Arc::new(builder.build()?)
}
Expand Down
22 changes: 12 additions & 10 deletions crates/sqlexec/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ impl EngineStorageConfig {
let bucket = opts
.get("bucket")
.cloned()
.or(url.host_str().map(|h| h.to_string()))
.ok_or(ExecError::MissingBucketName)?;
.or(url.host_str().map(|h| h.to_string()));

EngineStorageConfig {
location: url.clone(),
Expand Down Expand Up @@ -157,8 +156,6 @@ impl EngineStorageConfig {
}
}

let bucket = bucket.ok_or(ExecError::MissingBucketName)?;

EngineStorageConfig {
location: url.clone(),
conf: StorageConfig::S3 {
Expand Down Expand Up @@ -189,8 +186,7 @@ impl EngineStorageConfig {
let container_name = opts
.get("container_name")
.cloned()
.or(url.host_str().map(|h| h.to_string()))
.ok_or(ExecError::MissingBucketName)?;
.or(url.host_str().map(|h| h.to_string()));

EngineStorageConfig {
location: url.clone(),
Expand Down Expand Up @@ -231,15 +227,21 @@ impl EngineStorageConfig {
.map_err(DatasourceCommonError::from)?,
conf: StorageConfig::Gcs {
service_account_key,
bucket,
bucket: Some(bucket),
},
}
}
// Expected gcs config opts for the session.
(StorageConfig::Gcs { bucket: None, .. }, None) => {
return Err(ExecError::InvalidStorageConfig(
"Missing bucket on session configuration",
))
}
(_, Some(_)) => EngineStorageConfig {
location: Url::parse("memory://").map_err(DatasourceCommonError::from)?,
conf: StorageConfig::Memory,
},
(_, None) => self.clone(),
_ => self.clone(),
})
}

Expand Down Expand Up @@ -565,14 +567,14 @@ mod tests {
secret_access_key,
region: None,
endpoint: None,
bucket: "some-bucket".to_string(),
bucket: Some("some-bucket".to_string()),
}
);

let merged_conf = conf.with_session_config(&SessionStorageConfig {
gcs_bucket: Some("my-other-bucket".to_string()),
})?;
assert_eq!(merged_conf.conf, StorageConfig::Memory);
assert_eq!(merged_conf.conf, StorageConfig::Memory,);
Ok(())
}
}
3 changes: 0 additions & 3 deletions crates/sqlexec/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ pub enum ExecError {
#[error("Invalid URL for remote execution: {0}")]
InvalidRemoteExecUrl(String),

#[error("Missing bucket name: required for storage configuration")]
MissingBucketName,

#[error(transparent)]
DatasourceDebug(#[from] datasources::debug::errors::DebugError),

Expand Down
Loading