use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class ReadCommits method execute.
@Override
public void execute() throws NessieNotFoundException {
try (NessieApiV1 api = createNessieApiInstance()) {
spec.commandLine().getOut().printf("Reading commits for ref '%s'\n\n", ref);
FetchOption fetchOption = isVerbose() ? FetchOption.ALL : FetchOption.MINIMAL;
LogResponse logResponse = api.getCommitLog().refName(ref).fetch(fetchOption).get();
for (LogResponse.LogEntry logEntry : logResponse.getLogEntries()) {
CommitMeta commitMeta = logEntry.getCommitMeta();
spec.commandLine().getOut().printf("%s\t%s\t%s [%s]\n", Objects.requireNonNull(commitMeta.getHash()).substring(0, 8), commitMeta.getAuthorTime(), commitMeta.getMessage(), commitMeta.getAuthor());
List<Operation> operations = logEntry.getOperations();
if (operations != null) {
for (Operation op : operations) {
spec.commandLine().getOut().printf(" %s\n", op);
if (isVerbose()) {
List<String> key = op.getKey().getElements();
for (int i = 0; i < key.size(); i++) {
spec.commandLine().getOut().printf(" key[%d]: %s\n", i, key.get(i));
}
}
}
}
}
spec.commandLine().getOut().printf("\nDone reading commits for ref '%s'\n\n", ref);
}
}
use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class ITReadCommits method readCommits.
@Test
void readCommits() throws UnsupportedEncodingException, NessieNotFoundException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream out = new PrintStream(baos);
System.setOut(out);
assertThat(NessieContentGenerator.runMain(new String[] { "commits", "--uri", NESSIE_API_URI, "--ref", branch.getName() })).isEqualTo(0);
out.close();
String[] output = baos.toString(StandardCharsets.UTF_8.toString()).split("\n");
assertThat(output).anySatisfy(s -> assertThat(s).contains(COMMIT_MSG));
assertThat(output).noneSatisfy(s -> assertThat(s).contains(CONTENT_KEY.toString()));
try (NessieApiV1 api = buildNessieApi()) {
assertThat(api.getCommitLog().refName(branch.getName()).get().getLogEntries()).hasSize(1);
}
}
use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class TestHttpClientBuilder method testAuthBasic.
@ParameterizedTest
@MethodSource("basicAuthConfigs")
void testAuthBasic(Function<HttpClientBuilder, HttpClientBuilder> config) throws Exception {
AtomicReference<String> authHeader = new AtomicReference<>();
try (TestServer server = new TestServer(handlerForHeaderTest("Authorization", authHeader))) {
NessieApiV1 client = config.apply(HttpClientBuilder.builder().withUri(server.getUri())).build(NessieApiV1.class);
client.getConfig();
}
assertThat(authHeader.get()).isNotNull().isEqualTo("Basic " + new String(Base64.getUrlEncoder().encode("my_username:very_secret".getBytes(UTF_8)), UTF_8));
}
use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class TestNessieHttpClient method testUnauthorized.
@Test
void testUnauthorized() throws IOException {
try (TestServer server = errorServer(401)) {
NessieApiV1 api = HttpClientBuilder.builder().withUri(server.getUri().resolve("/unauthorized")).build(NessieApiV1.class);
assertThatThrownBy(api::getConfig).isInstanceOf(NessieNotAuthorizedException.class).hasMessageContaining("Unauthorized");
}
}
use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class TestNessieHttpClient method testTracingNotEnabled.
@Test
void testTracingNotEnabled() throws Exception {
AtomicReference<String> traceId = new AtomicReference<>();
try (TestServer server = new TestServer(handlerForHeaderTest("Uber-trace-id", traceId))) {
NessieApiV1 api = HttpClientBuilder.builder().withUri(server.getUri()).withTracing(false).build(NessieApiV1.class);
try (Scope ignore = GlobalTracer.get().activateSpan(GlobalTracer.get().buildSpan("testOpenTracing").start())) {
api.getConfig();
}
}
assertNull(traceId.get());
}
Aggregations