Skip to content
Merged
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 @@ -190,7 +190,7 @@ private UserSecretsManager getUserSecretsManager() {
return userSecretsManager;
}

private Optional<CatalogEntity> findCatalogByName(String name) {
private Optional<CatalogEntity> currentCatalog() {
return Optional.ofNullable(resolutionManifest.getResolvedReferenceCatalogEntity())
.map(path -> CatalogEntity.of(path.getRawLeafEntity()));
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 =
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1427,7 +1424,7 @@ public List<CatalogRole> listCatalogRoles(String catalogName) {
authorizeBasicTopLevelEntityOperationOrThrow(op, catalogName, PolarisEntityType.CATALOG);

PolarisEntity catalogEntity =
findCatalogByName(catalogName)
currentCatalog()
.orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName));
List<PolarisEntityCore> catalogPath = PolarisEntity.toCoreList(List.of(catalogEntity));
return metaStoreManager
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -1597,7 +1594,7 @@ public List<PolarisEntity> 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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -1965,7 +1962,7 @@ public List<PolarisEntity> 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 =
Expand Down Expand Up @@ -2129,7 +2126,7 @@ private PrivilegeResult grantPrivilegeOnTableLikeToRole(
List<PolarisEntitySubType> subTypes,
PolarisPrivilege privilege) {
CatalogEntity catalogEntity =
findCatalogByName(catalogName)
currentCatalog()
.orElseThrow(() -> new NotFoundException("Parent catalog %s not found", catalogName));
PolarisEntity catalogRoleEntity =
findCatalogRoleByName(catalogName, catalogRoleName)
Expand Down Expand Up @@ -2253,7 +2250,7 @@ private PrivilegeResult revokePrivilegeOnTableLikeFromRole(
TableIdentifier identifier,
List<PolarisEntitySubType> subTypes,
PolarisPrivilege privilege) {
if (findCatalogByName(catalogName).isEmpty()) {
if (currentCatalog().isEmpty()) {
throw new NotFoundException("Parent catalog %s not found", catalogName);
}
PolarisEntity catalogRoleEntity =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down