use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class AbstractRestAccessCheckDetached method detachedRefAccessChecks.
@Test
public void detachedRefAccessChecks(@NessieAccessChecker Consumer<Function<AccessContext, BatchAccessChecker>> accessCheckerConsumer) throws Exception {
accessCheckerConsumer.accept(x -> newAccessChecker());
Branch main = createBranch("committerAndAuthor");
Branch merge = createBranch("committerAndAuthorMerge");
Branch transplant = createBranch("committerAndAuthorTransplant");
IcebergTable meta1 = IcebergTable.of("meep", 42, 42, 42, 42);
ContentKey key = ContentKey.of("meep");
Branch mainCommit = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("no security context").build()).operation(Put.of(key, meta1)).commit();
Branch detachedAsBranch = Branch.of(Detached.REF_NAME, mainCommit.getHash());
Tag detachedAsTag = Tag.of(Detached.REF_NAME, mainCommit.getHash());
Detached detached = Detached.of(mainCommit.getHash());
assertThat(Stream.of(detached, detachedAsBranch, detachedAsTag)).allSatisfy(ref -> assertAll(() -> assertThatThrownBy(() -> getApi().getCommitLog().reference(ref).get()).describedAs("ref='%s', getCommitLog", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(COMMITS_MSG), () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().fromRef(ref).branch(merge).merge()).describedAs("ref='%s', mergeRefIntoBranch", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().fromRefName(ref.getName()).hashesToTransplant(singletonList(ref.getHash())).branch(transplant).transplant()).describedAs("ref='%s', transplantCommitsIntoBranch", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().getEntries().reference(ref).get()).describedAs("ref='%s', getEntries", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(READ_MSG), () -> assertThatThrownBy(() -> getApi().getContent().reference(ref).key(key).get()).describedAs("ref='%s', getContent", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(ENTITIES_MSG), () -> assertThatThrownBy(() -> getApi().getDiff().fromRef(ref).toRef(main).get()).describedAs("ref='%s', getDiff1", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().getDiff().fromRef(main).toRef(ref).get()).describedAs("ref='%s', getDiff2", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG)));
}
use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class AbstractRestSecurityContext method committerAndAuthor.
@Test
public void committerAndAuthor(@NessieSecurityContext Consumer<SecurityContext> securityContextConsumer) throws Exception {
Branch main = createBranch("committerAndAuthor");
Branch merge = createBranch("committerAndAuthorMerge");
Branch transplant = createBranch("committerAndAuthorTransplant");
IcebergTable meta1 = IcebergTable.of("meep", 42, 42, 42, 42);
IcebergTable meta2 = IcebergTable.of("meep_meep", 42, 42, 42, 42);
Branch noSecurityContext = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("no security context").build()).operation(Put.of(ContentKey.of("meep"), meta1)).commit();
assertThat(getApi().getCommitLog().reference(noSecurityContext).maxRecords(1).get().getLogEntries()).extracting(LogEntry::getCommitMeta).extracting(CommitMeta::getCommitter, CommitMeta::getAuthor, CommitMeta::getMessage).containsExactly(tuple("", "", "no security context"));
securityContextConsumer.accept(PrincipalSecurityContext.forName("ThatNessieGuy"));
Branch withSecurityContext = getApi().commitMultipleOperations().branchName(noSecurityContext.getName()).hash(noSecurityContext.getHash()).commitMeta(CommitMeta.builder().message("with security").build()).operation(Put.of(ContentKey.of("meep_meep"), meta2)).commit();
assertThat(getApi().getCommitLog().reference(withSecurityContext).maxRecords(2).get().getLogEntries()).extracting(LogEntry::getCommitMeta).extracting(CommitMeta::getCommitter, CommitMeta::getAuthor, CommitMeta::getMessage).containsExactly(tuple("ThatNessieGuy", "ThatNessieGuy", "with security"), tuple("", "", "no security context"));
securityContextConsumer.accept(PrincipalSecurityContext.forName("NessieHerself"));
// Merge
getApi().mergeRefIntoBranch().fromRef(withSecurityContext).branch(merge).merge();
merge = (Branch) getApi().getReference().refName(merge.getName()).get();
assertThat(getApi().getCommitLog().reference(merge).maxRecords(2).get().getLogEntries()).extracting(LogEntry::getCommitMeta).extracting(CommitMeta::getCommitter, CommitMeta::getAuthor, CommitMeta::getMessage).containsExactly(tuple("NessieHerself", "ThatNessieGuy", "with security"), tuple("NessieHerself", "", "no security context"));
// Transplant
getApi().transplantCommitsIntoBranch().fromRefName(withSecurityContext.getName()).hashesToTransplant(Arrays.asList(noSecurityContext.getHash(), withSecurityContext.getHash())).branch(transplant).transplant();
transplant = (Branch) getApi().getReference().refName(transplant.getName()).get();
assertThat(getApi().getCommitLog().reference(transplant).maxRecords(2).get().getLogEntries()).extracting(LogEntry::getCommitMeta).extracting(CommitMeta::getCommitter, CommitMeta::getAuthor, CommitMeta::getMessage).containsExactly(tuple("NessieHerself", "ThatNessieGuy", "with security"), tuple("NessieHerself", "", "no security context"));
}
use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class AbstractRest method createCommits.
protected String createCommits(Reference branch, int numAuthors, int commitsPerAuthor, String currentHash) throws BaseNessieClientServerException {
for (int j = 0; j < numAuthors; j++) {
String author = "author-" + j;
for (int i = 0; i < commitsPerAuthor; i++) {
IcebergTable meta = IcebergTable.of("some-file-" + i, 42, 42, 42, 42);
String nextHash = getApi().commitMultipleOperations().branchName(branch.getName()).hash(currentHash).commitMeta(CommitMeta.builder().author(author).message("committed-by-" + author).properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Put.of(ContentKey.of("table" + i), meta)).commit().getHash();
assertThat(currentHash).isNotEqualTo(nextHash);
currentHash = nextHash;
}
}
return currentHash;
}
use of org.projectnessie.model.IcebergTable in project nessie by projectnessie.
the class ITNativeNessieError method testNullParamViolation.
@Test
void testNullParamViolation() {
ContentKey k = ContentKey.of("a");
IcebergTable t = IcebergTable.of("path1", 42, 42, 42, 42);
assertEquals("Bad Request (HTTP/400): commitMultipleOperations.hash: must not be null", assertThrows(NessieBadRequestException.class, () -> api.commitMultipleOperations().branchName("branchName").operation(Put.of(k, t)).commitMeta(CommitMeta.fromMessage("message")).commit()).getMessage());
}
use of org.projectnessie.model.IcebergTable in project iceberg by apache.
the class TestNessieTable method testExistingTableUpdate.
@Test
public void testExistingTableUpdate() {
Table icebergTable = catalog.loadTable(TABLE_IDENTIFIER);
// add a column
icebergTable.updateSchema().addColumn("data", Types.LongType.get()).commit();
icebergTable = catalog.loadTable(TABLE_IDENTIFIER);
// Only 2 snapshotFile Should exist and no manifests should exist
Assertions.assertThat(metadataVersionFiles(TABLE_NAME)).isNotNull().hasSize(2);
Assertions.assertThat(manifestFiles(TABLE_NAME)).isNotNull().isEmpty();
Assertions.assertThat(altered.asStruct()).isEqualTo(icebergTable.schema().asStruct());
}
Aggregations