use of org.projectnessie.model.ContentKey in project nessie by projectnessie.
the class AbstractRestInvalidRefs method testValidHashesOnValidNamedRefs.
@Test
public void testValidHashesOnValidNamedRefs() throws BaseNessieClientServerException {
Branch branch = createBranch("testValidHashesOnValidNamedRefs");
int commits = 10;
String currentHash = branch.getHash();
createCommits(branch, 1, commits, currentHash);
LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
assertThat(entireLog).isNotNull();
assertThat(entireLog.getLogEntries()).hasSize(commits);
EntriesResponse allEntries = getApi().getEntries().refName(branch.getName()).get();
assertThat(allEntries).isNotNull();
assertThat(allEntries.getEntries()).hasSize(commits);
List<ContentKey> keys = new ArrayList<>();
IntStream.range(0, commits).forEach(i -> keys.add(ContentKey.of("table" + i)));
// TODO: check where hashOnRef is set
Map<ContentKey, Content> allContent = getApi().getContent().keys(keys).refName(branch.getName()).get();
for (int i = 0; i < commits; i++) {
String hash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(hash).get();
assertThat(log).isNotNull();
assertThat(log.getLogEntries()).hasSize(commits - i);
assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, commits)).containsExactlyElementsOf(log.getLogEntries());
EntriesResponse entries = getApi().getEntries().refName(branch.getName()).hashOnRef(hash).get();
assertThat(entries).isNotNull();
assertThat(entries.getEntries()).hasSize(commits - i);
int idx = commits - 1 - i;
ContentKey key = ContentKey.of("table" + idx);
Content c = getApi().getContent().key(key).refName(branch.getName()).hashOnRef(hash).get().get(key);
assertThat(c).isNotNull().isEqualTo(allContent.get(key));
}
}
use of org.projectnessie.model.ContentKey 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.ContentKey in project nessie by projectnessie.
the class ContentApiImpl method getMultipleContents.
@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
try {
WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
List<ContentKey> externalKeys = request.getRequestedKeys();
List<Key> internalKeys = externalKeys.stream().map(ContentApiImpl::toKey).collect(Collectors.toList());
Map<Key, Content> values = getStore().getValues(ref.getHash(), internalKeys);
List<ContentWithKey> output = values.entrySet().stream().map(e -> ContentWithKey.of(toContentKey(e.getKey()), e.getValue())).collect(Collectors.toList());
return ImmutableGetMultipleContentsResponse.builder().contents(output).build();
} catch (ReferenceNotFoundException ex) {
throw new NessieReferenceNotFoundException(ex.getMessage(), ex);
}
}
use of org.projectnessie.model.ContentKey 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.ContentKey in project nessie by projectnessie.
the class AbstractTestBasicOperations method testAdmin.
@Test
@TestSecurity(user = "admin_user", roles = { "admin", "user" })
void testAdmin() throws BaseNessieClientServerException {
getCatalog("testx");
Branch branch = (Branch) api.getReference().refName("testx").get();
List<Entry> tables = api.getEntries().refName("testx").get().getEntries();
Assertions.assertTrue(tables.isEmpty());
ContentKey key = ContentKey.of("x", "x");
tryEndpointPass(() -> api.commitMultipleOperations().branch(branch).operation(Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42, "cid-foo"))).commitMeta(CommitMeta.fromMessage("empty message")).commit());
Assertions.assertTrue(api.getContent().refName("testx").key(key).get().get(key).unwrap(IcebergTable.class).isPresent());
Branch master = (Branch) api.getReference().refName("testx").get();
Branch test = Branch.of("testy", master.getHash());
tryEndpointPass(() -> api.createReference().sourceRefName(master.getName()).reference(test).create());
Branch test2 = (Branch) api.getReference().refName("testy").get();
tryEndpointPass(() -> api.deleteBranch().branch(test2).delete());
tryEndpointPass(() -> api.commitMultipleOperations().branch(master).operation(Delete.of(key)).commitMeta(CommitMeta.fromMessage("")).commit());
assertThat(api.getContent().refName("testx").key(key).get()).isEmpty();
tryEndpointPass(() -> {
Branch b = (Branch) api.getReference().refName(branch.getName()).get();
// Note: the initial version-store implementations just committed this operation, but it
// should actually fail, because the operations of the 1st commit above and this commit
// have conflicts.
api.commitMultipleOperations().branch(b).operation(Put.of(key, IcebergTable.of("bar", 42, 42, 42, 42, "cid-bar"))).commitMeta(CommitMeta.fromMessage("")).commit();
});
}
Aggregations