use of com.artipie.asto.Key in project artipie by artipie.
the class SettingsFromPath method find.
/**
* Searches settings by the provided path, if no settings are found,
* example setting set is used.
* @param port Port for info logging
* @return Artipie settings
* @throws IOException On IO error
*/
public Settings find(final int port) throws IOException {
boolean initialize = Boolean.parseBoolean(System.getenv("ARTIPIE_INIT"));
if (!Files.exists(this.path)) {
new JavaResource("example/artipie.yaml").copy(this.path);
initialize = true;
}
final Settings settings = new YamlSettings(Yaml.createYamlInput(this.path.toFile()).readYamlMapping(), new SettingsCaches.All());
final BlockingStorage bsto = new BlockingStorage(settings.storage());
final Key init = new Key.From(".artipie", "initialized");
if (initialize && !bsto.exists(init)) {
final List<String> resources = Arrays.asList("_credentials.yaml", StorageAliases.FILE_NAME, "_permissions.yaml");
for (final String res : resources) {
final Path tmp = Files.createTempFile(res, ".tmp");
new JavaResource(String.format("example/repo/%s", res)).copy(tmp);
bsto.save(new Key.From(res), Files.readAllBytes(tmp));
Files.delete(tmp);
}
bsto.save(init, "true".getBytes());
Logger.info(VertxMain.class, String.join("\n", "", "", "\t+===============================================================+", "\t\t\t\t\tHello!", "\t\tArtipie configuration was not found, created default.", "\t\t\tDefault username/password: `artipie`/`artipie`. ", "\t\t\t\t Check the dashboard at:", String.format("\t\t\thttp://localhost:%d/dashboard/artipie", port), "\t-===============================================================-", ""));
}
return settings;
}
use of com.artipie.asto.Key in project maven-adapter by artipie.
the class CachedProxySlice method response.
@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
final RequestLineFrom req = new RequestLineFrom(line);
final Key key = new KeyFromPath(req.uri().getPath());
return new AsyncResponse(new RepoHead(this.client).head(req.uri().getPath()).thenCompose(head -> this.cache.load(key, new Remote.WithErrorHandling(() -> {
final CompletableFuture<Optional<? extends Content>> promise = new CompletableFuture<>();
this.client.response(line, Headers.EMPTY, Content.EMPTY).send((rsstatus, rsheaders, rsbody) -> {
final CompletableFuture<Void> term = new CompletableFuture<>();
if (rsstatus.success()) {
final Flowable<ByteBuffer> res = Flowable.fromPublisher(rsbody).doOnError(term::completeExceptionally).doOnTerminate(() -> term.complete(null));
promise.complete(Optional.of(new Content.From(res)));
} else {
promise.complete(Optional.empty());
}
return term;
});
return promise;
}), new CacheControl.All(StreamSupport.stream(head.orElse(Headers.EMPTY).spliterator(), false).map(Header::new).map(CachedProxySlice::checksumControl).collect(Collectors.toUnmodifiableList()))).handle((content, throwable) -> {
final Response result;
if (throwable == null && content.isPresent()) {
result = new RsWithBody(StandardRs.OK, new Content.From(content.get()));
} else {
result = StandardRs.NOT_FOUND;
}
return result;
})));
}
use of com.artipie.asto.Key in project maven-adapter by artipie.
the class AstoValidUpload method validateMetadata.
/**
* Validates uploaded and existing metadata by comparing group and artifact ids.
* @param upload Uploaded artifacts location
* @param artifact Artifact location
* @return Completable validation action: true if group and artifact ids are equal,
* false otherwise.
*/
private CompletionStage<Boolean> validateMetadata(final Key upload, final Key artifact) {
final ArtifactsMetadata metadata = new ArtifactsMetadata(this.storage);
final String meta = "maven-metadata.xml";
return this.storage.exists(new Key.From(artifact, meta)).thenCompose(exists -> {
final CompletionStage<Boolean> res;
if (exists) {
res = metadata.groupAndArtifact(new Key.From(upload, PutMetadataSlice.SUB_META)).thenCompose(existing -> metadata.groupAndArtifact(artifact).thenApply(uploaded -> uploaded.equals(existing)));
} else {
res = CompletableFuture.completedStage(true);
}
return res;
}).thenCompose(same -> {
final CompletionStage<Boolean> res;
if (same) {
res = this.validateArtifactChecksums(new Key.From(upload, meta)).to(SingleInterop.get());
} else {
res = CompletableFuture.completedStage(false);
}
return res;
});
}
use of com.artipie.asto.Key in project maven-adapter by artipie.
the class AstoMavenTest method addFilesToStorage.
private void addFilesToStorage(final Predicate<String> condition, final Key base) {
final Storage resources = new FileStorage(new TestResource("com/artipie/asto").asPath());
final BlockingStorage bsto = new BlockingStorage(resources);
bsto.list(Key.ROOT).stream().map(Key::string).filter(condition).forEach(item -> new BlockingStorage(this.storage).save(new Key.From(base, item), bsto.value(new Key.From(item))));
}
use of com.artipie.asto.Key in project maven-adapter by artipie.
the class AstoMavenTest method addsMetadataChecksums.
@Test
void addsMetadataChecksums() {
final String version = "0.1";
new TestResource("maven-metadata.xml.example").saveTo(this.storage, new Key.From(AstoMavenTest.LGR_UPLOAD, version, PutMetadataSlice.SUB_META, "maven-metadata.xml"));
new AstoMaven(this.storage).update(new Key.From(AstoMavenTest.LGR_UPLOAD, version), AstoMavenTest.LGR).toCompletableFuture().join();
MatcherAssert.assertThat(this.storage.list(AstoMavenTest.LGR).join().stream().map(key -> new KeyLastPart(key).get()).filter(key -> key.contains("maven-metadata.xml")).toArray(String[]::new), Matchers.arrayContainingInAnyOrder("maven-metadata.xml", "maven-metadata.xml.sha1", "maven-metadata.xml.sha256", "maven-metadata.xml.sha512", "maven-metadata.xml.md5"));
}
Aggregations