sungwy commented on code in PR #4356:
URL: https://github.com/apache/polaris/pull/4356#discussion_r3195304784


##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/common/PolarisSecurableMapper.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.catalog.common;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.polaris.core.auth.ImmutablePolarisSecurable;
+import org.apache.polaris.core.auth.PathSegment;
+import org.apache.polaris.core.auth.PolarisSecurable;
+import org.apache.polaris.core.entity.PolarisEntityType;
+import org.apache.polaris.service.types.PolicyAttachmentTarget;
+import org.apache.polaris.service.types.PolicyIdentifier;
+
+/**
+ * Utility mapper for translating Polaris domain identifiers into canonical 
{@link
+ * org.apache.polaris.core.auth.PolarisSecurable} paths.
+ */
+public final class PolarisSecurableMapper {
+  private PolarisSecurableMapper() {}
+
+  public static PolarisSecurable catalog(String catalogName) {
+    return PolarisSecurable.of(new PathSegment(PolarisEntityType.CATALOG, 
catalogName));
+  }
+
+  public static PolarisSecurable catalogRole(String catalogName, String 
catalogRoleName) {
+    return ImmutablePolarisSecurable.builder()
+        .addPathSegment(new PathSegment(PolarisEntityType.CATALOG, 
catalogName))
+        .addPathSegment(new PathSegment(PolarisEntityType.CATALOG_ROLE, 
catalogRoleName))
+        .build();
+  }
+
+  public static PolarisSecurable namespace(String catalogName, Namespace 
namespace) {
+    ImmutablePolarisSecurable.Builder builder =
+        ImmutablePolarisSecurable.builder()
+            .addPathSegment(new PathSegment(PolarisEntityType.CATALOG, 
catalogName));
+    Arrays.stream(namespace.levels())
+        .map(level -> new PathSegment(PolarisEntityType.NAMESPACE, level))
+        .forEach(builder::addPathSegment);
+    return builder.build();

Review Comment:
   updated `PolarisSecurableMapper` methods to explicitly validate the inputs: 
`.namespace()` expects non-empty `Namespace`



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

Reply via email to