use of com.artipie.asto.Key in project front by artipie.
the class HeadRepositoryTest method returnOkWhenRepoFound.
@ParameterizedTest
@CsvSource({ "flat,binary-repo.yaml,binary-repo", "org,Mark/pypi.yml,pypi" })
void returnOkWhenRepoFound(final String layout, final String key, final String name) {
final String uid = "Mark";
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(new HeadRepository(new RepoSettings(layout, this.blsto)).handle(rqs, Mockito.mock(Response.class)), new IsAnything<>());
}
use of com.artipie.asto.Key in project front by artipie.
the class RepoSettings method key.
/**
* Find repository settings key by repository name and username, throws exception
* if settings file is not found.
* @param name Repository name
* @param uid User id (=name)
* @return Repository settings
* @throws NotFoundException If such repository does not exist
*/
public Key key(final String name, final String uid) {
final Pair<Key, Key> pair = this.keys(name, uid);
Key res = pair.getLeft();
if (!this.repos.exists(res)) {
res = pair.getRight();
if (!this.repos.exists(res)) {
throw new NotFoundException(String.format("Repository %s not found", name));
}
}
return res;
}
use of com.artipie.asto.Key in project front by artipie.
the class YamlStorages method storages.
/**
* Returns storages yaml mapping if found.
* @return Settings storages yaml
*/
private Optional<YamlMapping> storages() {
final Optional<Key> key = this.key();
Optional<YamlMapping> res = Optional.empty();
if (key.isPresent()) {
try {
res = Optional.ofNullable(Yaml.createYamlInput(new String(this.blsto.value(key.get()), StandardCharsets.UTF_8)).readYamlMapping().yamlMapping(YamlStorages.STORAGES_NODE));
} catch (final IOException err) {
throw new UncheckedIOException(err);
}
}
return res;
}
use of com.artipie.asto.Key in project front by artipie.
the class YamlStorages method add.
@Override
public void add(final String alias, final JsonObject info) {
YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
final Optional<YamlMapping> storages = this.storages();
if (storages.isPresent()) {
for (final YamlNode node : storages.get().keys()) {
final String name = node.asScalar().value();
builder = builder.add(name, storages.get().yamlMapping(name));
}
}
builder = builder.add(alias, new Json2Yaml().apply(info.toString()));
this.blsto.save(this.key().orElse(this.repo.<Key>map(val -> new Key.From(val, YamlStorages.YAML)).orElse(YamlStorages.YAML)), Yaml.createYamlMappingBuilder().add(YamlStorages.STORAGES_NODE, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
}
use of com.artipie.asto.Key in project artipie by artipie.
the class StorageYamlConfigTest method returnsSubStorageWithCorrectPrefix.
@Test
void returnsSubStorageWithCorrectPrefix() throws IOException {
final Key prefix = new Key.From("prefix");
final Key path = new Key.From("some/path");
final Key full = new Key.From(prefix, path);
final byte[] data = "content".getBytes();
this.config().subStorage(prefix).save(path, new Content.From(data)).join();
MatcherAssert.assertThat(new PublisherAs(new FileStorage(this.tmp).value(full).join()).bytes().toCompletableFuture().join(), new IsEqual<>(data));
}
Aggregations