geruh commented on code in PR #1961:
URL: https://github.com/apache/iceberg-rust/pull/1961#discussion_r2659930527
##########
crates/catalog/rest/src/catalog.rs:
##########
@@ -55,6 +57,33 @@ const ICEBERG_REST_SPEC_VERSION: &str = "0.14.1";
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const PATH_V1: &str = "v1";
+static DEFAULT_ENDPOINTS: OnceLock<HashSet<Endpoint>> = OnceLock::new();
+
+fn default_endpoints() -> &'static HashSet<Endpoint> {
+ DEFAULT_ENDPOINTS.get_or_init(|| {
+ [
+ Endpoint::v1_config(),
Review Comment:
nit: we can remove config from this list
##########
crates/catalog/rest/src/catalog.rs:
##########
@@ -781,6 +837,7 @@ impl Catalog for RestCatalog {
/// Check if a table exists in the catalog.
async fn table_exists(&self, table: &TableIdent) -> Result<bool> {
let context = self.context().await?;
+ Endpoint::check_supported(&context.config.endpoints,
Endpoint::v1_table_exists())?;
Review Comment:
This may break compatibility with older implementations where table
existence checks happened through LoadTable.
##########
crates/catalog/rest/src/types.rs:
##########
@@ -15,20 +15,244 @@
// specific language governing permissions and limitations
// under the License.
-//! Request and response types for the Iceberg REST API.
-
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
+use std::sync::OnceLock;
+use http::Method;
use iceberg::spec::{Schema, SortOrder, TableMetadata, UnboundPartitionSpec};
use iceberg::{
Error, ErrorKind, Namespace, NamespaceIdent, TableIdent, TableRequirement,
TableUpdate,
};
-use serde_derive::{Deserialize, Serialize};
+use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub(super) struct CatalogConfig {
pub(super) overrides: HashMap<String, String>,
pub(super) defaults: HashMap<String, String>,
+ #[serde(default, skip_serializing_if = "HashSet::is_empty")]
+ pub(super) endpoints: HashSet<Endpoint>,
+}
+
+#[derive(Clone, Debug, PartialEq, Eq, Hash)]
+/// Struct containing the method and path of an REST Catalog Endpoint
+pub struct Endpoint {
+ method: Method,
+ path: String,
+}
+
+impl Endpoint {
+ /// HTTP Method for endpoint
+ pub fn method(&self) -> &Method {
+ &self.method
+ }
+
+ /// Endpoint path
+ pub fn path(&self) -> &str {
+ &self.path
+ }
+
+ /// Check if the set of supported endpoints supports the provided endpoint
+ pub fn check_supported(
+ supported_endpoints: &HashSet<Endpoint>,
+ endpoint: &Endpoint,
+ ) -> Result<(), Error> {
+ if supported_endpoints.contains(endpoint) {
+ Ok(())
+ } else {
+ Err(Error::new(
+ ErrorKind::FeatureUnsupported,
+ format!(
+ "Endpoint '{}' is not supported by the server",
+ endpoint.as_str()
+ ),
+ ))
+ }
+ }
+
+ /// Parse endpoint in the form <HTTP Method> <URL> into an endpoint
structure
+ pub fn parse(endpoint: &str) -> Result<Self, Error> {
+ let parts: Vec<&str> = endpoint.splitn(2, ' ').collect();
+ if parts.len() != 2 {
+ return Err(Error::new(
+ ErrorKind::DataInvalid,
+ "Invalid endpoint format: '{}'. Expected <Method> <Path>",
+ ));
+ }
+
+ let method: Method =
Method::from_bytes(parts[0].as_bytes()).map_err(|_| {
+ Error::new(
+ ErrorKind::DataInvalid,
+ format!("Invalid HTTP method: '{}'", parts[0]),
+ )
+ })?;
+
+ // Validate that the method is one of the standard HTTP methods since
from_bytes allows for http extensions
+ match method {
+ Method::GET
+ | Method::POST
+ | Method::PUT
+ | Method::DELETE
+ | Method::HEAD
+ | Method::OPTIONS
+ | Method::PATCH => {}
Review Comment:
Should we scope this down to the methods we actually handle?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]