use of com.artipie.asto.Key in project maven-adapter by artipie.
the class PutMetadataSlice method response.
@Override
public Response response(final String line, final Iterable<Map.Entry<String, String>> headers, final Publisher<ByteBuffer> body) {
final Response res;
final Matcher matcher = PutMetadataSlice.PTN_META.matcher(new RequestLineFrom(line).uri().getPath());
if (matcher.matches()) {
final Key pkg = new KeyFromPath(matcher.group("pkg"));
res = new AsyncResponse(new PublisherAs(body).asciiString().thenCombine(this.asto.list(new Key.From(UploadSlice.TEMP, pkg)), (xml, list) -> {
final Optional<String> snapshot = new DeployMetadata(xml).snapshots().stream().filter(item -> list.stream().anyMatch(key -> key.string().contains(item))).findFirst();
final Key key;
if (snapshot.isPresent()) {
key = new Key.From(UploadSlice.TEMP, pkg.string(), snapshot.get(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
} else {
key = new Key.From(UploadSlice.TEMP, pkg.string(), new DeployMetadata(xml).release(), PutMetadataSlice.SUB_META, PutMetadataSlice.MAVEN_METADATA);
}
return this.asto.save(key, new Content.From(xml.getBytes(StandardCharsets.US_ASCII)));
}).thenApply(nothing -> new RsWithStatus(RsStatus.CREATED)));
} else {
res = new RsWithStatus(RsStatus.BAD_REQUEST);
}
return res;
}
use of com.artipie.asto.Key in project front by artipie.
the class ArtipieYaml method credentials.
/**
* Credentials from config.
* @return Credentials
*/
public Credentials credentials() {
final Optional<Key> key = this.fileCredentialsKey();
Optional<YamlMapping> res = Optional.empty();
if (key.isPresent() && this.storage().exists(key.get())) {
try {
res = Optional.of(Yaml.createYamlInput(new String(this.storage().value(key.get()), StandardCharsets.UTF_8)).readYamlMapping());
} catch (final IOException err) {
throw new UncheckedIOException(err);
}
} else if (key.isPresent()) {
res = Optional.of(Yaml.createYamlMappingBuilder().build());
}
return new YamlCredentials(res.orElseThrow(() -> new NotImplementedException("Not implemented yet")));
}
use of com.artipie.asto.Key in project front by artipie.
the class RepoSettings method list.
/**
* List existing repositories.
* @param uid User id (=name)
* @return List of the existing repositories
*/
public Collection<String> list(final Optional<String> uid) {
Key key = Key.ROOT;
if ("org".equals(this.layout) && uid.isPresent()) {
key = new Key.From(uid.get());
}
final Collection<String> res = new ArrayList<>(5);
for (final Key item : this.repos.list(key)) {
final String name = item.string();
// @checkstyle BooleanExpressionComplexityCheck (5 lines)
if ((name.endsWith(".yaml") || name.endsWith(".yml")) && !name.contains(YamlStorages.FILE_NAME) && !name.contains("_permissions") && !name.contains("_credentials")) {
res.add(name.replaceAll("\\.yaml|\\.yml", ""));
}
}
return res;
}
use of com.artipie.asto.Key in project front by artipie.
the class DeleteRepositoryTest method removesRepository.
@ParameterizedTest
@CsvSource({ "flat,binary-repo.yaml,binary-repo", "org,Alice/docker.yml,docker" })
void removesRepository(final String layout, final String key, final String name) {
final String uid = "Alice";
this.blsto.save(new Key.From(key), new byte[] {});
final var rqs = Mockito.mock(Request.class);
Mockito.when(rqs.params(GetRepository.NAME_PARAM.toString())).thenReturn(name);
Mockito.when(rqs.attribute(RequestAttr.Standard.USER_ID.attrName())).thenReturn(uid);
MatcherAssert.assertThat("Failed to process request", new DeleteRepository(new RepoSettings(layout, this.blsto)).handle(rqs, Mockito.mock(Response.class)), new IsAnything<>());
MatcherAssert.assertThat("Item was not removed from storage", this.blsto.exists(new Key.From(key)), new IsEqual<>(false));
}
use of com.artipie.asto.Key in project maven-adapter by artipie.
the class AstoValidUploadTest method returnsTrueWhenReady.
@ParameterizedTest
@CsvSource({ "pom;pom.sha1;jar;jar.sha1,xml;xml.sha1,true", "war;war.md5;war.sha1,xml;xml.sha1;xml.md5,true", "pom;rar,xml;xml.sha1;xml.sha256,false", "'',xml;xml.sha1;xml.md5,false", "jar;jar.sha256,xml;xml.sha1,false", "war;war.sha256,xml,false" })
void returnsTrueWhenReady(final String artifacts, final String meta, final boolean res) {
final Key location = new Key.From(".upload/com/artipie/example/0.2");
Arrays.stream(artifacts.split(";")).forEach(item -> this.bsto.save(new Key.From(location, String.format("example-0.2.%s", item)), new byte[] {}));
Arrays.stream(meta.split(";")).forEach(item -> this.bsto.save(new Key.From(location, PutMetadataSlice.SUB_META, String.format("maven-metadata.%s", item)), new byte[] {}));
MatcherAssert.assertThat(this.validupload.ready(location).toCompletableFuture().join(), new IsEqual<>(res));
}
Aggregations