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
109 changes: 95 additions & 14 deletions crates/catalog/rest/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ use crate::types::{
pub const REST_CATALOG_PROP_URI: &str = "uri";
/// REST catalog warehouse location
pub const REST_CATALOG_PROP_WAREHOUSE: &str = "warehouse";
/// Disable header redaction in error logs (defaults to false for security)
pub const REST_CATALOG_PROP_DISABLE_HEADER_REDACTION: &str = "disable-header-redaction";

const ICEBERG_REST_SPEC_VERSION: &str = "0.14.1";
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down Expand Up @@ -293,6 +295,17 @@ impl RestCatalogConfig {
params
}

/// Check if header redaction is disabled in error logs.
///
/// Returns true if the `disable-header-redaction` property is set to "true".
/// Defaults to false for security (headers are redacted by default).
pub(crate) fn disable_header_redaction(&self) -> bool {
self.props
.get(REST_CATALOG_PROP_DISABLE_HEADER_REDACTION)
.map(|v| v.eq_ignore_ascii_case("true"))
.unwrap_or(false)
}

/// Merge the `RestCatalogConfig` with the a [`CatalogConfig`] (fetched from the REST server).
pub(crate) fn merge_with_config(mut self, mut config: CatalogConfig) -> Self {
if let Some(uri) = config.overrides.remove("uri") {
Expand Down Expand Up @@ -378,7 +391,11 @@ impl RestCatalog {

match http_response.status() {
StatusCode::OK => deserialize_catalog_response(http_response).await,
_ => Err(deserialize_unexpected_catalog_error(http_response).await),
_ => Err(deserialize_unexpected_catalog_error(
http_response,
client.disable_header_redaction(),
)
.await),
}
}

Expand Down Expand Up @@ -479,7 +496,13 @@ impl Catalog for RestCatalog {
"The parent parameter of the namespace provided does not exist",
));
}
_ => return Err(deserialize_unexpected_catalog_error(http_response).await),
_ => {
return Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await);
}
}
}

Expand Down Expand Up @@ -514,7 +537,11 @@ impl Catalog for RestCatalog {
ErrorKind::Unexpected,
"Tried to create a namespace that already exists",
)),
_ => Err(deserialize_unexpected_catalog_error(http_response).await),
_ => Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await),
}
}

Expand All @@ -538,7 +565,11 @@ impl Catalog for RestCatalog {
ErrorKind::Unexpected,
"Tried to get a namespace that does not exist",
)),
_ => Err(deserialize_unexpected_catalog_error(http_response).await),
_ => Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await),
}
}

Expand All @@ -555,7 +586,11 @@ impl Catalog for RestCatalog {
match http_response.status() {
StatusCode::NO_CONTENT | StatusCode::OK => Ok(true),
StatusCode::NOT_FOUND => Ok(false),
_ => Err(deserialize_unexpected_catalog_error(http_response).await),
_ => Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await),
}
}

Expand Down Expand Up @@ -586,7 +621,11 @@ impl Catalog for RestCatalog {
ErrorKind::Unexpected,
"Tried to drop a namespace that does not exist",
)),
_ => Err(deserialize_unexpected_catalog_error(http_response).await),
_ => Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await),
}
}

Expand Down Expand Up @@ -623,7 +662,13 @@ impl Catalog for RestCatalog {
"Tried to list tables of a namespace that does not exist",
));
}
_ => return Err(deserialize_unexpected_catalog_error(http_response).await),
_ => {
return Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await);
}
}
}

Expand Down Expand Up @@ -677,7 +722,13 @@ impl Catalog for RestCatalog {
"The table already exists",
));
}
_ => return Err(deserialize_unexpected_catalog_error(http_response).await),
_ => {
return Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await);
}
};

let metadata_location = response.metadata_location.as_ref().ok_or(Error::new(
Expand Down Expand Up @@ -732,7 +783,13 @@ impl Catalog for RestCatalog {
"Tried to load a table that does not exist",
));
}
_ => return Err(deserialize_unexpected_catalog_error(http_response).await),
_ => {
return Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await);
}
};

let config = response
Expand Down Expand Up @@ -774,7 +831,11 @@ impl Catalog for RestCatalog {
ErrorKind::Unexpected,
"Tried to drop a table that does not exist",
)),
_ => Err(deserialize_unexpected_catalog_error(http_response).await),
_ => Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await),
}
}

Expand All @@ -792,7 +853,11 @@ impl Catalog for RestCatalog {
match http_response.status() {
StatusCode::NO_CONTENT | StatusCode::OK => Ok(true),
StatusCode::NOT_FOUND => Ok(false),
_ => Err(deserialize_unexpected_catalog_error(http_response).await),
_ => Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await),
}
}

Expand Down Expand Up @@ -821,7 +886,11 @@ impl Catalog for RestCatalog {
ErrorKind::Unexpected,
"Tried to rename a table to a name that already exists",
)),
_ => Err(deserialize_unexpected_catalog_error(http_response).await),
_ => Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await),
}
}

Expand Down Expand Up @@ -865,7 +934,13 @@ impl Catalog for RestCatalog {
"The given table already exists.",
));
}
_ => return Err(deserialize_unexpected_catalog_error(http_response).await),
_ => {
return Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await);
}
};

let metadata_location = response.metadata_location.as_ref().ok_or(Error::new(
Expand Down Expand Up @@ -934,7 +1009,13 @@ impl Catalog for RestCatalog {
"A server-side gateway timeout occurred; the commit state is unknown.",
));
}
_ => return Err(deserialize_unexpected_catalog_error(http_response).await),
_ => {
return Err(deserialize_unexpected_catalog_error(
http_response,
context.client.disable_header_redaction(),
)
.await);
}
};

let file_io = self
Expand Down
Loading
Loading