amogh-jahagirdar commented on code in PR #1961:
URL: https://github.com/apache/iceberg-rust/pull/1961#discussion_r2659955917
##########
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:
We could, I'm not opposed to that but I also think if someone adds the usage
of these HTTP methods to the spec later, it creates another point in the client
that needs to be updated at that point, instead of "just working".
I figured since it's all the REST spec is just defined HTTP standard verbs,
just allow of them.
--
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]