github-actions[bot] commented on code in PR #70725:
URL: https://github.com/apache/doris/pull/70725#discussion_r4624934435


##########
fe/fe-connector/fe-connector-lance/src/main/java/org/apache/doris/connector/lance/LanceCatalogProperties.java:
##########
@@ -160,36 +211,158 @@ private static void validateWarehouse(String warehouse) {
             return;
         }
         String scheme = uri.getScheme().toLowerCase(Locale.ROOT);
-        if (!"file".equals(scheme) && !"s3".equals(scheme)) {
+        if (!"file".equals(scheme) && !"s3".equals(scheme) && 
!"oss".equals(scheme)) {
             throw new IllegalArgumentException("Unsupported Lance filesystem 
warehouse scheme '" + scheme
-                    + "'; supported schemes are local/file and s3");
+                    + "'; supported schemes are local/file, s3, and oss");
         }
         // An object-store root names its bucket in the authority. Lance reads 
that authority as the
         // bucket and fails deep inside the store when it is absent, so reject 
the no-authority form
         // here where the message can still name the property.
-        if ("s3".equals(scheme) && StringUtils.isBlank(uri.getAuthority())) {
+        if (("s3".equals(scheme) || "oss".equals(scheme)) && 
StringUtils.isBlank(uri.getAuthority())) {
             throw new IllegalArgumentException(
                     "Lance " + scheme + " warehouse must name a bucket, as in 
" + scheme
                             + "://bucket/path, but was: " + warehouse);
         }
     }
 
+    private void validateRestProperties() {
+        if (raw.containsKey(WAREHOUSE)) {
+            throw new IllegalArgumentException("Property 'warehouse' is not 
valid for Lance REST catalog");
+        }
+        if (StringUtils.isBlank(restUri)) {
+            throw new IllegalArgumentException(
+                    "Missing required property '" + REST_URI + "' for Lance 
REST catalog");
+        }
+        validateRestUri(restUri);
+
+        // ALTER merges property maps and cannot remove keys; an empty 
inactive credential clears it.
+        boolean bearerTokenConfigured = StringUtils.isNotEmpty(bearerToken);
+        boolean apiKeyConfigured = StringUtils.isNotEmpty(apiKey);
+        switch (securityType) {
+            case SECURITY_NONE:
+                if (bearerTokenConfigured || apiKeyConfigured) {
+                    throw new IllegalArgumentException("Lance REST security 
type 'none' cannot configure '"
+                            + REST_BEARER_TOKEN + "' or '" + REST_API_KEY + 
"'");
+                }
+                break;
+            case SECURITY_BEARER:
+                if (StringUtils.isBlank(bearerToken) || apiKeyConfigured) {
+                    throw new IllegalArgumentException("Lance REST security 
type 'bearer' requires only '"
+                            + REST_BEARER_TOKEN + "'");
+                }
+                validateCredentialHeaderValue(REST_BEARER_TOKEN, bearerToken);
+                break;
+            case SECURITY_API_KEY:
+                if (StringUtils.isBlank(apiKey) || bearerTokenConfigured) {
+                    throw new IllegalArgumentException("Lance REST security 
type 'api_key' requires only '"
+                            + REST_API_KEY + "'");
+                }
+                validateCredentialHeaderValue(REST_API_KEY, apiKey);
+                break;
+            default:
+                throw new IllegalArgumentException("Property '" + 
REST_SECURITY_TYPE
+                        + "' must be 'none', 'bearer', or 'api_key'");
+        }
+
+        for (Map.Entry<String, String> entry : raw.entrySet()) {
+            String key = entry.getKey();
+            if (!key.startsWith(REST_PREFIX) || REST_KEYS.contains(key)) {
+                continue;
+            }
+            if (!key.startsWith(REST_HEADER_PREFIX)) {
+                throw new IllegalArgumentException("Unsupported Lance REST 
property '" + key + "'");
+            }
+            validateRestHeader(key.substring(REST_HEADER_PREFIX.length()), 
entry.getValue());
+        }
+    }
+
+    private static void validateRestUri(String value) {
+        final URI uri;
+        try {
+            uri = URI.create(value.trim());
+        } catch (IllegalArgumentException e) {
+            throw new IllegalArgumentException("Invalid Lance REST URI in 
property '" + REST_URI + "'", e);
+        }
+        String scheme = uri.getScheme();
+        if (scheme == null || (!"http".equalsIgnoreCase(scheme) && 
!"https".equalsIgnoreCase(scheme))) {
+            throw new IllegalArgumentException("Property '" + REST_URI + "' 
must use http or https");
+        }
+        if (StringUtils.isBlank(uri.getRawAuthority()) || uri.getRawUserInfo() 
!= null
+                || uri.getRawQuery() != null || uri.getRawFragment() != null) {
+            throw new IllegalArgumentException("Property '" + REST_URI
+                    + "' must contain an authority and cannot contain 
user-info, query, or fragment");
+        }
+    }
+
+    private static void validateRestHeader(String headerName, String 
headerValue) {
+        if (StringUtils.isBlank(headerName) || 
!HTTP_HEADER_NAME.matcher(headerName).matches()) {
+            throw new IllegalArgumentException("Invalid HTTP header name in 
property '"
+                    + REST_HEADER_PREFIX + headerName + "'");
+        }
+        if ("authorization".equalsIgnoreCase(headerName) || 
"x-api-key".equalsIgnoreCase(headerName)) {
+            throw new IllegalArgumentException("Authentication header '" + 
headerName
+                    + "' must be configured through '" + REST_SECURITY_TYPE + 
"'");
+        }
+        if (headerValue == null || headerValue.indexOf('\r') >= 0 || 
headerValue.indexOf('\n') >= 0) {
+            throw new IllegalArgumentException("Invalid HTTP header value in 
property '"
+                    + REST_HEADER_PREFIX + headerName + "'");
+        }
+    }
+
+    private static void validateCredentialHeaderValue(String propertyName, 
String value) {
+        if (value.indexOf('\r') >= 0 || value.indexOf('\n') >= 0) {
+            throw new IllegalArgumentException("Invalid HTTP credential value 
in property '" + propertyName + "'");
+        }
+    }
+
     /**
-     * Fails for a flavor this build cannot serve. Called where a catalog 
would first reach its namespace,
-     * so a {@code rest} catalog carried over from an earlier version stays 
loadable, droppable and alterable,
-     * and only reading through it fails, saying why.
+     * What {@code LanceNamespace.connect("rest", ...)} is given: the server, 
the namespace delimiter, and every
+     * header to send, the credential header included. It contains the 
credentials: keep it internal.
      */
-    public void requireFilesystem() {
-        if (!FILESYSTEM.equals(catalogType)) {
-            throw new DorisConnectorException("Lance " + catalogType + " 
catalogs are not supported yet;"
-                    + " only '" + CATALOG_TYPE + "'='" + FILESYSTEM + "' 
catalogs can be read");
+    Map<String, String> restNamespaceProperties() {
+        Map<String, String> properties = new HashMap<>();
+        properties.put("uri", StringUtils.stripEnd(restUri.trim(), "/"));
+        properties.put("delimiter", namespaceDelimiter);
+        raw.forEach((key, value) -> {
+            if (key.startsWith(REST_HEADER_PREFIX)) {
+                properties.put("header." + 
key.substring(REST_HEADER_PREFIX.length()), value);

Review Comment:
   [P2] Reject conflicting case variants of REST headers
   
   A catalog created with `lance.rest.header.X-Tenant=old` accepts an ALTER 
setting `lance.rest.header.x-tenant=new`. Catalog property keys remain 
case-sensitive, so the merged map retains both and this loop forwards both to 
Lance. The pinned SDK keeps these names in a Rust `HashMap`, then inserts them 
into the same case-insensitive HTTP `HeaderMap` in unspecified iteration order 
(`rest.rs`, `from_properties` / `apply_headers`). Consequently the accepted 
tenant update can continue sending `old`, and reopening the client can change 
which value wins. Detect case-equivalent header names with conflicting values 
while validating the merged properties and emit one normalized header; cover 
this CREATE/ALTER case as well as the authentication-mode transitions.



-- 
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]

Reply via email to