use of com.artipie.asto.Key in project maven-adapter by artipie.
the class LocalMavenSlice method response.
@Override
public Response response(final String line, final Iterable<Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
final RequestLineFrom rline = new RequestLineFrom(line);
final Key key = new KeyFromPath(rline.uri().getPath());
final Matcher match = LocalMavenSlice.PTN_ARTIFACT.matcher(new KeyLastPart(key).get());
final Response response;
if (match.matches()) {
response = this.artifactResponse(rline.method(), key);
} else {
response = this.plainResponse(rline.method(), key);
}
return response;
}
use of com.artipie.asto.Key in project maven-adapter by artipie.
the class AstoMaven method moveToTheRepository.
/**
* Moves artifacts from temp location to repository.
* @param upload Upload temp location
* @param target Repository
* @param artifact Artifact repository location
* @return Completion action
*/
private CompletableFuture<Void> moveToTheRepository(final Key upload, final Storage target, final Key artifact) {
final Storage sub = new SubStorage(new Key.From(upload, PutMetadataSlice.SUB_META), this.storage);
final Storage subversion = new SubStorage(upload.parent().get(), this.storage);
return sub.list(Key.ROOT).thenCompose(list -> new Copy(sub, list.stream().filter(key -> key.string().contains(AstoMaven.MAVEN_META)).collect(Collectors.toList())).copy(new SubStorage(artifact, target))).thenCompose(nothing -> subversion.list(Key.ROOT).thenCompose(list -> new Copy(subversion, list.stream().filter(key -> !key.string().contains(String.format("/%s/", PutMetadataSlice.SUB_META))).collect(Collectors.toList())).copy(new SubStorage(artifact, target))));
}
use of com.artipie.asto.Key in project artipie by artipie.
the class RepositoriesFromStorageCacheTest method readConfigFromCacheAfterSavingNewValueInStorage.
@Test
void readConfigFromCacheAfterSavingNewValueInStorage() {
final Key key = new Key.From("some-repo.yaml");
final byte[] old = "some: data".getBytes();
final byte[] upd = "some: new data".getBytes();
new BlockingStorage(this.storage).save(key, old);
final ClientSlices http = new JettyClientSlices();
new RepositoriesFromStorage(http, this.storage).config(key.string()).toCompletableFuture().join();
new BlockingStorage(this.storage).save(key, upd);
MatcherAssert.assertThat(new RepositoriesFromStorage(http, this.storage).config(key.string()).toCompletableFuture().join().toString(), new IsEqual<>(new String(old)));
}
use of com.artipie.asto.Key in project artipie by artipie.
the class MetricSliceTest method shouldReturnMetricsInJsonArray.
@Test
void shouldReturnMetricsInJsonArray() {
final String keyone = "one";
final String keytwo = "two";
final String json = "[{\"key\":\"%s\",\"value\":%s},{\"key\":\"%s\",\"value\":%s}]";
final long valone = 1;
final long valtwo = 2;
final String dirorder = String.format(json, keyone, valone, keytwo, valtwo);
final String revorder = String.format(json, keytwo, valtwo, keyone, valone);
final Storage storage = new InMemoryStorage();
storage.save(new Key.From(keyone), this.getContent(valone));
storage.save(new Key.From(keytwo), this.getContent(valtwo));
MatcherAssert.assertThat(new MetricSlice(storage), new SliceHasResponse(new AllOf<>(Arrays.asList(new RsHasStatus(RsStatus.OK), new AnyOf<>(Arrays.asList(new RsHasBody(dirorder, StandardCharsets.UTF_8), new RsHasBody(revorder, StandardCharsets.UTF_8))))), new RequestLine(RqMethod.GET, "/api/repositories/")));
}
use of com.artipie.asto.Key in project artipie by artipie.
the class ConfigFile method valueFrom.
/**
* Obtains contents from the specified storage. If files with both extensions
* exists, the file with `.yaml` extension will be obtained.
* @param storage Storage from which the file is obtained
* @return Content of the file.
*/
public CompletionStage<Content> valueFrom(final Storage storage) {
if (!(this.isYamlOrYml() || this.extension().isEmpty())) {
throw new IllegalStateException(String.format("Filename `%s` should have `.yaml` or `.yml` extension or be without extension", this.filename));
}
final String name = this.name();
final Key yaml = Extension.YAML.key(name);
return storage.exists(yaml).thenCompose(exists -> {
final CompletionStage<Content> result;
if (exists) {
result = storage.value(yaml);
} else {
final Key yml = Extension.YML.key(name);
result = storage.value(yml);
}
return result;
});
}
Aggregations