use of com.amihaiemil.eoyaml.YamlMapping in project front by artipie.
the class YamlStorages method remove.
@Override
public void remove(final String alias) {
final Optional<YamlMapping> storages = this.storages();
if (storages.isPresent() && storages.get().value(alias) != null) {
YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
for (final YamlNode node : storages.get().keys()) {
final String name = node.asScalar().value();
if (!alias.equals(name)) {
builder = builder.add(name, storages.get().yamlMapping(name));
}
}
this.blsto.save(this.key().get(), Yaml.createYamlMappingBuilder().add(YamlStorages.STORAGES_NODE, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
return;
}
throw new NotFoundException(String.format("Storage alias %s does not exist", alias));
}
use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.
the class CachedCredsTest method getsOriginForSameConfigurationButDifferentStorages.
@Test
void getsOriginForSameConfigurationButDifferentStorages() {
final String path = "_credentials.yaml";
final Key key = new Key.From(path);
final CredsConfigCache configs = new CachedCreds(this.cache);
final Storage another = new InMemoryStorage();
new TestResource(path).saveTo(this.storage);
new BlockingStorage(another).save(key, "credentials: another val".getBytes(StandardCharsets.UTF_8));
final YamlMapping frst = configs.credentials(this.storage, key).toCompletableFuture().join();
final YamlMapping scnd = configs.credentials(another, key).toCompletableFuture().join();
MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.
the class CachedCredsTest method getsValueFromCache.
@Test
void getsValueFromCache() {
final Key path = new Key.From("creds.yaml");
final CredsConfigCache configs = new CachedCreds(this.cache);
this.storage.save(path, Content.EMPTY).join();
final YamlMapping creds = configs.credentials(this.storage, path).toCompletableFuture().join();
final YamlMapping same = configs.credentials(this.storage, path).toCompletableFuture().join();
MatcherAssert.assertThat("Obtained configurations were different", creds.equals(same), new IsEqual<>(true));
MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(1L));
}
use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.
the class CachedCredsTest method getsOriginForDifferentConfigurations.
@Test
void getsOriginForDifferentConfigurations() {
final CredsConfigCache configs = new CachedCreds(this.cache);
final Key onekey = new Key.From("first.yml");
final Key twokey = new Key.From("credentials.yml");
final BlockingStorage blck = new BlockingStorage(this.storage);
blck.save(onekey, "credentials: val".getBytes(StandardCharsets.UTF_8));
blck.save(twokey, "credentials: another val".getBytes(StandardCharsets.UTF_8));
final YamlMapping frst = configs.credentials(this.storage, onekey).toCompletableFuture().join();
final YamlMapping scnd = configs.credentials(this.storage, twokey).toCompletableFuture().join();
MatcherAssert.assertThat("Obtained configurations were the same", frst.equals(scnd), new IsEqual<>(false));
MatcherAssert.assertThat("Credentials configuration was not cached", this.cache.size(), new IsEqual<>(2L));
}
use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.
the class UsersFromStorageYaml method removeUserRecord.
/**
* Removes user record from credentials.yaml.
* @param username User name to remove
* @param yaml Credentials mapping
* @return YamlMappingBuilder without removed user
*/
private static YamlMappingBuilder removeUserRecord(final String username, final YamlMapping yaml) {
YamlMappingBuilder result = Yaml.createYamlMappingBuilder();
final YamlMapping credentials = yaml.yamlMapping(UsersFromStorageYaml.CREDENTIALS);
final List<YamlNode> keep = credentials.keys().stream().filter(node -> !node.asScalar().value().equals(username)).collect(Collectors.toList());
for (final YamlNode node : keep) {
result = result.add(node, credentials.value(node));
}
return result;
}
Aggregations