sungwy commented on code in PR #4356: URL: https://github.com/apache/polaris/pull/4356#discussion_r3456723172
########## runtime/service/src/main/java/org/apache/polaris/service/catalog/common/PolarisSecurableMapper.java: ########## @@ -0,0 +1,116 @@ +/* + * 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) { + if (namespace.isEmpty()) { + throw new IllegalArgumentException("Namespace target must not be empty"); + } + 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(); + } + + public static PolarisSecurable tableLike(String catalogName, TableIdentifier identifier) { Review Comment: Thanks @flyrain - this is a good callout. When I first ran into this, I decided that it would be safe to make this change because we don't support [empty namespaces in the IcebergCatalogHandler](https://github.com/apache/polaris/blob/6e883ed05388afbb608e5d515a9c99c89e0cccf2/runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractLocalIcebergCatalogTest.java#L434) today in Polaris. But I agree that it's good to document any behavioral changes in the `CHANGELOG` -- 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]
