Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,6 @@ private <T> Pair<List<T>, String> paginate(
return Pair.of(subList, nextPageToken);
}

public ListNamespacesResponse listNamespaces(SupportsNamespaces catalog, Namespace parent) {
List<Namespace> results;
if (parent.isEmpty()) {
results = catalog.listNamespaces();
} else {
results = catalog.listNamespaces(parent);
}

return ListNamespacesResponse.builder().addAll(results).build();
}

public ListNamespacesResponse listNamespaces(
SupportsNamespaces catalog, Namespace parent, String pageToken, Integer pageSize) {
List<Namespace> results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,6 @@
this.viewCatalog = (baseCatalog instanceof ViewCatalog) ? (ViewCatalog) baseCatalog : null;
}

public ListNamespacesResponse listNamespaces(Namespace parent) {
PolarisAuthorizableOperation op = PolarisAuthorizableOperation.LIST_NAMESPACES;
authorizeBasicNamespaceOperationOrThrow(op, parent);

return catalogHandlerUtils().listNamespaces(namespaceCatalog, parent);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments for catalogHandlerUtils().listNamespaces(), should we remove it as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it as well in the latest commit.

}

public ListNamespacesResponse listNamespaces(
Namespace parent, String pageToken, Integer pageSize) {
PolarisAuthorizableOperation op = PolarisAuthorizableOperation.LIST_NAMESPACES;
Expand Down Expand Up @@ -396,7 +389,7 @@
* @param request the table creation request
* @return ETagged {@link LoadTableResponse} to uniquely identify the table metadata
*/
public LoadTableResponse createTableDirect(Namespace namespace, CreateTableRequest request) {

Check warning on line 392 in runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java

View workflow job for this annotation

GitHub Actions / CI/PR / Gradle Build Checks

@return tag cannot be used in method with void return type.
return createTableDirect(
namespace, request, EnumSet.noneOf(AccessDelegationMode.class), Optional.empty());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private IcebergCatalogHandler newHandler(
@TestFactory
Stream<DynamicNode> testListNamespacesPrivileges() {
return authzTestsBuilder("listNamespaces")
.action(() -> newHandler().listNamespaces(Namespace.of()))
.action(() -> newHandler().listNamespaces(Namespace.of(), null, null))
.shouldPassWith(PolarisPrivilege.NAMESPACE_LIST)
.shouldPassWith(PolarisPrivilege.NAMESPACE_READ_PROPERTIES)
.shouldPassWith(PolarisPrivilege.NAMESPACE_WRITE_PROPERTIES)
Expand Down Expand Up @@ -204,7 +204,7 @@ Stream<DynamicNode> testInsufficientPermissionsPriorToSecretRotation() {
Stream<DynamicNode> beforeRotationTests =
Stream.of(
authzTestsBuilder("listNamespaces (before rotation)")
.action(() -> handler.get().listNamespaces(Namespace.of()))
.action(() -> handler.get().listNamespaces(Namespace.of(), null, null))
.principalName(principalName)
.shouldFailWithAnyPrivilege()
.createTests(),
Expand Down Expand Up @@ -258,7 +258,7 @@ Stream<DynamicNode> testInsufficientPermissionsPriorToSecretRotation() {
Stream<DynamicNode> afterRotationTests =
Stream.of(
authzTestsBuilder("listNamespaces (after rotation)")
.action(() -> refreshedWrapper.get().listNamespaces(Namespace.of()))
.action(() -> refreshedWrapper.get().listNamespaces(Namespace.of(), null, null))
.principalName(principalName)
.shouldPassWith(PolarisPrivilege.NAMESPACE_LIST)
.shouldPassWith(PolarisPrivilege.NAMESPACE_CREATE)
Expand Down Expand Up @@ -307,17 +307,17 @@ public void testListNamespacesCatalogLevelWithPrincipalRoleActivation() {
newRootAdminService()
.grantPrivilegeOnCatalogToRole(
CATALOG_NAME, CATALOG_ROLE1, PolarisPrivilege.NAMESPACE_LIST));
Assertions.assertThat(newHandler().listNamespaces(Namespace.of()).namespaces())
Assertions.assertThat(newHandler().listNamespaces(Namespace.of(), null, null).namespaces())
.containsAll(List.of(NS1, NS2));

// Just activating PRINCIPAL_ROLE1 should also work.
Assertions.assertThat(
newHandler(Set.of(PRINCIPAL_ROLE1)).listNamespaces(Namespace.of()).namespaces())
newHandler(Set.of(PRINCIPAL_ROLE1)).listNamespaces(Namespace.of(), null, null).namespaces())
.containsAll(List.of(NS1, NS2));

// If we only activate PRINCIPAL_ROLE2 it won't have the privilege.
Assertions.assertThatThrownBy(
() -> newHandler(Set.of(PRINCIPAL_ROLE2)).listNamespaces(Namespace.of()))
() -> newHandler(Set.of(PRINCIPAL_ROLE2)).listNamespaces(Namespace.of(), null, null))
.isInstanceOf(ForbiddenException.class)
.hasMessageContaining("is not authorized");

Expand All @@ -326,7 +326,7 @@ public void testListNamespacesCatalogLevelWithPrincipalRoleActivation() {
newRootAdminService()
.revokePrivilegeOnCatalogFromRole(
CATALOG_NAME, CATALOG_ROLE1, PolarisPrivilege.NAMESPACE_LIST));
Assertions.assertThatThrownBy(() -> newHandler().listNamespaces(Namespace.of()))
Assertions.assertThatThrownBy(() -> newHandler().listNamespaces(Namespace.of(), null, null))
.isInstanceOf(ForbiddenException.class);
}

Expand All @@ -339,19 +339,19 @@ public void testListNamespacesChildOnly() {
CATALOG_NAME, CATALOG_ROLE1, NS1, PolarisPrivilege.NAMESPACE_LIST));

// Listing directly on NS1 succeeds
Assertions.assertThat(newHandler().listNamespaces(NS1).namespaces())
Assertions.assertThat(newHandler().listNamespaces(NS1, null, null).namespaces())
.containsAll(List.of(NS1A, NS1B));

// Root listing fails
Assertions.assertThatThrownBy(() -> newHandler().listNamespaces(Namespace.of()))
Assertions.assertThatThrownBy(() -> newHandler().listNamespaces(Namespace.of(), null, null))
.isInstanceOf(ForbiddenException.class);

// NS2 listing fails
Assertions.assertThatThrownBy(() -> newHandler().listNamespaces(Namespace.of()))
Assertions.assertThatThrownBy(() -> newHandler().listNamespaces(Namespace.of(), null, null))
.isInstanceOf(ForbiddenException.class);

// Listing on a child of NS1 succeeds
Assertions.assertThat(newHandler().listNamespaces(NS1A).namespaces())
Assertions.assertThat(newHandler().listNamespaces(NS1A, null, null).namespaces())
.containsAll(List.of(NS1AA));
}

Expand Down
Loading