Skip to content

Commit

Permalink
[#5947] fix(auth): It will throw error if we enable authorization and…
Browse files Browse the repository at this point in the history
… rename catalog (#5949)

### What changes were proposed in this pull request?

Fix the issue of renaming catalogs or metalakes.

### Why are the changes needed?

Fix: #5947

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?
Add UT.
  • Loading branch information
jerqi authored Dec 23, 2024
1 parent 7a1abf5 commit 74c7aac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.CatalogChange;
import org.apache.gravitino.MetadataObject;
import org.apache.gravitino.MetadataObjects;
import org.apache.gravitino.MetalakeChange;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.auth.AuthConstants;
import org.apache.gravitino.authorization.Owner;
Expand Down Expand Up @@ -203,6 +205,20 @@ protected static void waitForUpdatingPolicies() {

protected abstract void testAlterTable();

// ISSUE-5947: can't rename a catalog or a metalake
@Test
void testRenameMetalakeOrCatalog() {
Assertions.assertDoesNotThrow(
() -> client.alterMetalake(metalakeName, MetalakeChange.rename("new_name")));
Assertions.assertDoesNotThrow(
() -> client.alterMetalake("new_name", MetalakeChange.rename(metalakeName)));

Assertions.assertDoesNotThrow(
() -> metalake.alterCatalog(catalogName, CatalogChange.rename("new_name")));
Assertions.assertDoesNotThrow(
() -> metalake.alterCatalog("new_name", CatalogChange.rename(catalogName)));
}

@Test
protected void testCreateSchema() throws InterruptedException {
// Choose a catalog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,14 @@ public static void authorizationPluginRenamePrivileges(
NameIdentifierUtil.toMetadataObject(NameIdentifier.of(ident.namespace(), newName), type);
MetadataObjectChange renameObject =
MetadataObjectChange.rename(oldMetadataObject, newMetadataObject);

String metalake = type == Entity.EntityType.METALAKE ? newName : ident.namespace().level(0);

// For a renamed catalog, we should pass the new name catalog, otherwise we can't find the
// catalog in the entity store
callAuthorizationPluginForMetadataObject(
ident.namespace().level(0),
oldMetadataObject,
metalake,
newMetadataObject,
authorizationPlugin -> {
authorizationPlugin.onMetadataUpdated(renameObject);
});
Expand Down

0 comments on commit 74c7aac

Please sign in to comment.