diff --git a/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java b/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java index bd8a1d6a49..651920a001 100644 --- a/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java +++ b/runtime/service/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java @@ -190,7 +190,7 @@ private UserSecretsManager getUserSecretsManager() { return userSecretsManager; } - private Optional findCatalogByName(String name) { + private Optional currentCatalog() { return Optional.ofNullable(resolutionManifest.getResolvedReferenceCatalogEntity()) .map(path -> CatalogEntity.of(path.getRawLeafEntity())); } @@ -513,7 +513,7 @@ private void authorizeGrantOnTableLikeOperationOrThrow( CatalogEntity catalogEntity = CatalogEntity.of( - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Catalog %s not found", catalogName))); PolarisResolvedPathWrapper tableLikeWrapper = resolutionManifest.getResolvedPath( @@ -797,8 +797,7 @@ public void deleteCatalog(String name) { authorizeBasicTopLevelEntityOperationOrThrow(op, name, PolarisEntityType.CATALOG); PolarisEntity entity = - findCatalogByName(name) - .orElseThrow(() -> new NotFoundException("Catalog %s not found", name)); + currentCatalog().orElseThrow(() -> new NotFoundException("Catalog %s not found", name)); // TODO: Handle return value in case of concurrent modification boolean cleanup = realmConfig.getConfig(FeatureConfiguration.CLEANUP_ON_CATALOG_DROP); DropEntityResult dropEntityResult = @@ -823,8 +822,7 @@ public void deleteCatalog(String name) { PolarisAuthorizableOperation op = PolarisAuthorizableOperation.GET_CATALOG; authorizeBasicTopLevelEntityOperationOrThrow(op, name, PolarisEntityType.CATALOG); - return findCatalogByName(name) - .orElseThrow(() -> new NotFoundException("Catalog %s not found", name)); + return currentCatalog().orElseThrow(() -> new NotFoundException("Catalog %s not found", name)); } /** @@ -883,8 +881,7 @@ private void validateUpdateCatalogDiffOrThrow( authorizeBasicTopLevelEntityOperationOrThrow(op, name, PolarisEntityType.CATALOG); CatalogEntity currentCatalogEntity = - findCatalogByName(name) - .orElseThrow(() -> new NotFoundException("Catalog %s not found", name)); + currentCatalog().orElseThrow(() -> new NotFoundException("Catalog %s not found", name)); if (currentCatalogEntity.getEntityVersion() != updateRequest.getCurrentEntityVersion()) { throw new CommitConflictException( @@ -1321,7 +1318,7 @@ public PolarisEntity createCatalogRole(String catalogName, PolarisEntity entity) checkArgument(entity.getId() == -1, "Entity to be created must have no ID assigned"); PolarisEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); PolarisEntity returnedEntity = @@ -1386,7 +1383,7 @@ public void deleteCatalogRole(String catalogName, String name) { authorizeBasicCatalogRoleOperationOrThrow(op, catalogName, name); CatalogEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Catalog %s not found", catalogName)); CatalogRoleEntity currentCatalogRoleEntity = findCatalogRoleByName(catalogName, name) @@ -1427,7 +1424,7 @@ public List listCatalogRoles(String catalogName) { authorizeBasicTopLevelEntityOperationOrThrow(op, catalogName, PolarisEntityType.CATALOG); PolarisEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); List catalogPath = PolarisEntity.toCoreList(List.of(catalogEntity)); return metaStoreManager @@ -1509,7 +1506,7 @@ public PrivilegeResult assignCatalogRoleToPrincipalRole( .orElseThrow( () -> new NotFoundException("PrincipalRole %s not found", principalRoleName)); PolarisEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); PolarisEntity catalogRoleEntity = findCatalogRoleByName(catalogName, catalogRoleName) @@ -1531,7 +1528,7 @@ public PrivilegeResult revokeCatalogRoleFromPrincipalRole( .orElseThrow( () -> new NotFoundException("PrincipalRole %s not found", principalRoleName)); PolarisEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); PolarisEntity catalogRoleEntity = findCatalogRoleByName(catalogName, catalogRoleName) @@ -1597,7 +1594,7 @@ public List listCatalogRolesForPrincipalRole( op, principalRoleName, PolarisEntityType.PRINCIPAL_ROLE, catalogName); PolarisEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); PolarisEntity principalRoleEntity = findPrincipalRoleByName(principalRoleName) @@ -1659,7 +1656,7 @@ public PrivilegeResult grantPrivilegeOnCatalogToRole( authorizeGrantOnCatalogOperationOrThrow(op, catalogName, catalogRoleName); PolarisEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); PolarisEntity catalogRoleEntity = findCatalogRoleByName(catalogName, catalogRoleName) @@ -1681,7 +1678,7 @@ public PrivilegeResult revokePrivilegeOnCatalogFromRole( authorizeGrantOnCatalogOperationOrThrow(op, catalogName, catalogRoleName); PolarisEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); PolarisEntity catalogRoleEntity = findCatalogRoleByName(catalogName, catalogRoleName) @@ -1703,7 +1700,7 @@ public PrivilegeResult grantPrivilegeOnNamespaceToRole( authorizeGrantOnNamespaceOperationOrThrow(op, catalogName, namespace, catalogRoleName); CatalogEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); PolarisEntity catalogRoleEntity = findCatalogRoleByName(catalogName, catalogRoleName) @@ -1965,7 +1962,7 @@ public List listAssigneePrincipalRolesForCatalogRole( PolarisAuthorizableOperation.LIST_ASSIGNEE_PRINCIPAL_ROLES_FOR_CATALOG_ROLE; authorizeBasicCatalogRoleOperationOrThrow(op, catalogName, catalogRoleName); - if (findCatalogByName(catalogName).isEmpty()) { + if (currentCatalog().isEmpty()) { throw new NotFoundException("Parent catalog %s not found", catalogName); } PolarisEntity catalogRoleEntity = @@ -2129,7 +2126,7 @@ private PrivilegeResult grantPrivilegeOnTableLikeToRole( List subTypes, PolarisPrivilege privilege) { CatalogEntity catalogEntity = - findCatalogByName(catalogName) + currentCatalog() .orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName)); PolarisEntity catalogRoleEntity = findCatalogRoleByName(catalogName, catalogRoleName) @@ -2253,7 +2250,7 @@ private PrivilegeResult revokePrivilegeOnTableLikeFromRole( TableIdentifier identifier, List subTypes, PolarisPrivilege privilege) { - if (findCatalogByName(catalogName).isEmpty()) { + if (currentCatalog().isEmpty()) { throw new NotFoundException("Parent catalog %s not found", catalogName); } PolarisEntity catalogRoleEntity = @@ -2283,7 +2280,7 @@ private PrivilegeResult grantPrivilegeOnPolicyEntityToRole( String catalogRoleName, PolicyIdentifier identifier, PolarisPrivilege privilege) { - if (findCatalogByName(catalogName).isEmpty()) { + if (currentCatalog().isEmpty()) { throw new NotFoundException("Parent catalog %s not found", catalogName); } PolarisEntity catalogRoleEntity = @@ -2311,7 +2308,7 @@ private PrivilegeResult revokePrivilegeOnPolicyEntityFromRole( String catalogRoleName, PolicyIdentifier identifier, PolarisPrivilege privilege) { - if (findCatalogByName(catalogName).isEmpty()) { + if (currentCatalog().isEmpty()) { throw new NotFoundException("Parent catalog %s not found", catalogName); } PolarisEntity catalogRoleEntity =