use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class TestAuthorizationRules method testCanCommitButNotUpdateOrDeleteEntity.
@Test
// test_user2 has all permissions on a Branch, but not permissions on a Key
@TestSecurity(user = "test_user2")
void testCanCommitButNotUpdateOrDeleteEntity() throws BaseNessieClientServerException {
String role = "test_user2";
ContentKey key = ContentKey.of("allowed", "some");
String branchName = "allowedBranchForTestUser2";
createBranch(Branch.of(branchName, null), role, false);
listAllReferences(branchName, false);
final Branch branch = retrieveBranch(branchName, role, false);
assertThatThrownBy(() -> api().commitMultipleOperations().branch(branch).commitMeta(CommitMeta.fromMessage("add stuff")).operation(Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42, "cid-foo"))).commit()).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(String.format("'UPDATE_ENTITY' is not allowed for role '%s' on content '%s'", role, key.toPathString()));
readContent(branchName, key, role, true);
final Branch b = retrieveBranch(branchName, role, false);
assertThatThrownBy(() -> api().commitMultipleOperations().branch(b).commitMeta(CommitMeta.fromMessage("delete stuff")).operation(Delete.of(key)).commit()).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(String.format("'DELETE_ENTITY' is not allowed for role '%s' on content '%s'", role, key.toPathString()));
deleteBranch(branch, role, false);
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class TestAuthorizationRules method testAllOps.
private void testAllOps(String branchName, String role, boolean shouldFail) throws BaseNessieClientServerException {
boolean isAdmin = role.equals("admin_user");
ContentKey key = ContentKey.of("allowed", "x");
if (shouldFail) {
branchName = "disallowedBranchForTestUser";
key = ContentKey.of("disallowed", "x");
}
createBranch(Branch.of(branchName, null), role, shouldFail);
Branch branchWithInvalidHash = Branch.of(branchName, "1234567890123456");
Branch branch = shouldFail ? branchWithInvalidHash : retrieveBranch(branchName, role, shouldFail);
listAllReferences(branchName, shouldFail);
String cid = "cid-foo-" + UUID.randomUUID();
addContent(branch, Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42, cid)), role, shouldFail);
if (!shouldFail) {
// These requests cannot succeed, because "disallowedBranchForTestUser" could not be created
getCommitLog(branchName, role, shouldFail);
getEntriesFor(branchName, role, shouldFail);
readContent(branchName, key, role, shouldFail);
}
branch = shouldFail ? branchWithInvalidHash : retrieveBranch(branchName, role, shouldFail);
deleteContent(branch, Delete.of(key), role, shouldFail);
branch = shouldFail ? branchWithInvalidHash : retrieveBranch(branchName, role, shouldFail);
deleteBranch(branch, role, shouldFail);
getRefLog(role, !isAdmin);
Branch defaultBranch = api().getDefaultBranch();
deleteBranch(defaultBranch, role, !isAdmin);
if (isAdmin) {
// need to recreate the default branch, so the test can continue normally
api().createReference().reference(Branch.of(defaultBranch.getName(), null)).create();
}
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class TestAuthorizationRules method testCanReadTargetBranchDuringTransplant.
@Test
@TestSecurity(user = "admin_user")
void testCanReadTargetBranchDuringTransplant() throws BaseNessieClientServerException {
String role = "admin_user";
String branchName = "adminCanReadWhenTransplanting";
String targetBranchName = "targetBranchForTransplant";
createBranch(Branch.of(branchName, null), role, false);
Branch branch = retrieveBranch(branchName, role, false);
createBranch(Branch.of(targetBranchName, null), role, false);
Branch targetBranch = retrieveBranch(targetBranchName, role, false);
addContent(branch, Put.of(ContentKey.of("allowed", "x"), IcebergTable.of("foo", 42, 42, 42, 42, UUID.randomUUID().toString())), role, false);
branch = retrieveBranch(branchName, role, false);
api().transplantCommitsIntoBranch().fromRefName(branch.getName()).hashesToTransplant(api().getCommitLog().reference(branch).get().getLogEntries().stream().map(e -> e.getCommitMeta().getHash()).collect(Collectors.toList())).branch(targetBranch).transplant();
targetBranch = retrieveBranch(targetBranch.getName(), role, false);
assertThat(api().getCommitLog().reference(targetBranch).get().getLogEntries()).isNotEmpty();
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class TestAuthorizationRules method testCanReadTargetBranchDuringAssign.
@Test
@TestSecurity(user = "admin_user")
void testCanReadTargetBranchDuringAssign() throws BaseNessieClientServerException {
String role = "admin_user";
String branchName = "adminCanReadWhenAssigning";
String targetBranchName = "targetBranchForAssign";
createBranch(Branch.of(branchName, null), role, false);
Branch branch = retrieveBranch(branchName, role, false);
createBranch(Branch.of(targetBranchName, null), role, false);
Branch targetBranch = retrieveBranch(targetBranchName, role, false);
addContent(targetBranch, Put.of(ContentKey.of("allowed", "x"), IcebergTable.of("foo", 42, 42, 42, 42, UUID.randomUUID().toString())), role, false);
targetBranch = retrieveBranch(targetBranchName, role, false);
api().assignBranch().branch(branch).assignTo(targetBranch).assign();
branch = retrieveBranch(branchName, role, false);
assertThat(branch.getHash()).isEqualTo(targetBranch.getHash());
}
use of org.projectnessie.model.Branch in project nessie by projectnessie.
the class NessieViewOperations method drop.
@Override
public void drop(String viewIdentifier) {
reference.checkMutable();
IcebergView existingView = view(toCatalogTableIdentifier(viewIdentifier));
if (existingView == null) {
return;
}
CommitMultipleOperationsBuilder commitBuilderBase = api.commitMultipleOperations().commitMeta(NessieUtil.buildCommitMetadata(String.format("Iceberg delete view %s", viewIdentifier), catalogOptions)).operation(Operation.Delete.of(NessieUtil.toKey(toCatalogTableIdentifier(viewIdentifier))));
// We try to drop the view. Simple retry after ref update.
try {
Tasks.foreach(commitBuilderBase).retry(5).stopRetryOn(NessieNotFoundException.class).throwFailureWhenFinished().onFailure((o, exception) -> refresh()).run(commitBuilder -> {
Branch branch = commitBuilder.branch(reference.getAsBranch()).commit();
reference.updateReference(branch);
}, BaseNessieClientServerException.class);
} catch (NessieConflictException e) {
LOG.error("Cannot drop view: failed after retry (update ref and retry)", e);
} catch (NessieNotFoundException e) {
LOG.error("Cannot drop view: ref is no longer valid.", e);
} catch (BaseNessieClientServerException e) {
LOG.error("Cannot drop view: unknown error", e);
}
}
Aggregations