Search in sources :

Example 16 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project front by artipie.

the class YamlUsers method remove.

@Override
public void remove(final String uid) {
    if (this.users().map(yaml -> yaml.yamlMapping(uid) != null).orElse(false)) {
        YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
        final YamlMapping users = this.users().get();
        for (final YamlNode node : users.keys()) {
            final String val = node.asScalar().value();
            if (!uid.equals(val)) {
                builder = builder.add(val, users.yamlMapping(val));
            }
        }
        this.blsto.save(this.key, Yaml.createYamlMappingBuilder().add(ArtipieYaml.NODE_CREDENTIALS, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
        return;
    }
    throw new NotFoundException(String.format("User %s does not exist", uid));
}
Also used : JsonObject(javax.json.JsonObject) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Collection(java.util.Collection) IOException(java.io.IOException) Key(com.artipie.asto.Key) BlockingStorage(com.artipie.asto.blocking.BlockingStorage) Yaml(com.amihaiemil.eoyaml.Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ArtipieYaml(com.artipie.front.settings.ArtipieYaml) UncheckedIOException(java.io.UncheckedIOException) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) Optional(java.util.Optional) NotFoundException(com.artipie.front.api.NotFoundException) Json2Yaml(com.artipie.front.misc.Json2Yaml) Collections(java.util.Collections) YamlNode(com.amihaiemil.eoyaml.YamlNode) NotFoundException(com.artipie.front.api.NotFoundException) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Example 17 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project adif-processor by urbancamo.

the class PrintJobConfig method configure.

public void configure(String filename, InputStream yamlConfig) throws IOException {
    this.filename = filename;
    YamlMapping config = Yaml.createYamlInput(yamlConfig).readYamlMapping();
    YamlMapping printJob = config.yamlMapping("printJob");
    setName(printJob.string("name"));
    setInEncoding(printJob.string("inEncoding"));
    setOutEncoding(printJob.string("outEncoding"));
    setStartCommand(printJob.string("startCommand"));
    setEndCommand(printJob.string("endCommand"));
    setFilenameExtension(printJob.string("filenameExtension"));
    YamlMapping page = config.yamlMapping("page");
    pageConfig = new PageConfig();
    setPageConfig(pageConfig);
    pageConfig.setPageHeight(page.integer("pageHeight"));
    pageConfig.setPageWidth(page.integer("pageWidth"));
    pageConfig.setTopMargin(page.integer("topMargin"));
    pageConfig.setBottomMargin(page.integer("bottomMargin"));
    pageConfig.setLeftMargin(page.integer("leftMargin"));
    pageConfig.setRightMargin(page.integer("rightMargin"));
    pageConfig.setPageEnd(stripQuotes(page.string("pageEnd")));
    pageConfig.setLineEnd(stripQuotes(page.string("lineEnd")));
    pageConfig.setHeaderLine(stripQuotes(page.string("headerLine")));
    pageConfig.setColumnSeparator(stripQuotes(page.string("columnSeparator")));
    pageConfig.setHeaderSeparator(stripQuotes(page.string("headerSeparator")));
    LineConfig line = new LineConfig();
    pageConfig.setLine(line);
    Collection<YamlNode> nodes = config.yamlSequence("columns").values();
    for (YamlNode node : nodes) {
        ColumnConfig column = new ColumnConfig();
        YamlMapping colMap = node.asMapping().yamlMapping("column");
        // each column is a mapping
        column.setAdif(colMap.string("adif"));
        column.setHeader(colMap.string("header"));
        column.setStart(colMap.integer("start"));
        column.setLength(colMap.integer("length"));
        column.setAlign(colMap.string("align"));
        column.setFormat(colMap.string("format"));
        line.addColumn(column);
    }
}
Also used : YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Example 18 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project adif-processor by urbancamo.

the class AdifReaderTest method testAdifFLE.

@Test
public void testAdifFLE() throws Exception {
    AdiReader reader = new AdiReader();
    BufferedReader inputReader = resourceInput("adif/2021-01-09-Queen-Adelaides-Hill.adi");
    Optional<Adif3> result = reader.read(inputReader);
    // System.out.println(new File("tmp.txt").getAbsolutePath());
    YamlMapping config = Yaml.createYamlInput(new File("adif-processor.yaml")).readYamlMapping();
    if (result.isPresent()) {
        Adif3 log = result.get();
        Qsos qsos = new Qsos(log);
        assertThat(log.getHeader().getProgramId()).isEqualTo("FLE");
        ActivityDatabases summits = new ActivityDatabases();
        summits.loadData();
        QrzXmlService qrzXmlService = new QrzXmlService(null, null);
        if (!qrzXmlService.getSessionKey()) {
            System.err.println("Could not connect to QRZ.COM, continuing...");
        }
        TransformResults results = new TransformResults();
        Adif3RecordTransformer transformer = new CommentParsingAdifRecordTransformer(config, summits, qrzXmlService, control, results);
        int index = 1;
        for (Adif3Record rec : log.getRecords()) {
            transformer.transform(qsos, rec, index++);
        }
        assertThat(log.getRecords()).hasSize(16);
    }
}
Also used : Qsos(uk.m0nom.adif3.contacts.Qsos) TransformResults(uk.m0nom.adif3.transform.TransformResults) AdiReader(org.marsik.ham.adif.AdiReader) Adif3RecordTransformer(uk.m0nom.adif3.transform.Adif3RecordTransformer) Adif3(org.marsik.ham.adif.Adif3) Adif3Record(org.marsik.ham.adif.Adif3Record) BufferedReader(java.io.BufferedReader) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) ActivityDatabases(uk.m0nom.activity.ActivityDatabases) QrzXmlService(uk.m0nom.qrz.QrzXmlService) File(java.io.File) CommentParsingAdifRecordTransformer(uk.m0nom.adif3.transform.CommentParsingAdifRecordTransformer) Test(org.junit.Test)

Example 19 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.

the class YamlPermissionsTest method checksGroups.

@ParameterizedTest
@CsvSource(value = { "mark,read,readers,true", "olga,write,group-a;group-b,true", "john,read,abc;def,false", "jane,manage,readers;leaders,false", "ann,read,'',false" }, nullValues = "''")
void checksGroups(final String name, final String action, final String groups, final boolean res) {
    final YamlMapping settings = new RepoPerms(new ListOf<>(new RepoPermissions.PermissionItem(name, "write"), new RepoPermissions.PermissionItem("/readers", "read"))).permsYaml();
    MatcherAssert.assertThat(new YamlPermissions(settings).allowed(new Authentication.User(name, new ListOf<String>(groups.split(";"))), action), new IsEqual<>(res));
}
Also used : ListOf(org.cactoos.list.ListOf) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) RepoPerms(com.artipie.repo.RepoPerms) RepoPermissions(com.artipie.repo.RepoPermissions) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project artipie by artipie.

the class RepoPermissionsFromStorage method copyRepoSection.

/**
 * Copy `repo` section without permissions from existing yaml setting.
 * @param mapping Repo section mapping
 * @return Setting without permissions
 */
private static YamlMappingBuilder copyRepoSection(final YamlMapping mapping) {
    YamlMappingBuilder res = Yaml.createYamlMappingBuilder();
    final List<YamlNode> keep = mapping.keys().stream().filter(node -> !new SetOf<>(RepoPermissionsFromStorage.PERMS, RepoPermissionsFromStorage.INCLUDE_PATTERNS).contains(node.asScalar().value())).collect(Collectors.toList());
    for (final YamlNode node : keep) {
        res = res.add(node, mapping.value(node));
    }
    return res;
}
Also used : YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Collection(java.util.Collection) CompletableFuture(java.util.concurrent.CompletableFuture) Content(com.artipie.asto.Content) Key(com.artipie.asto.Key) Yaml(com.amihaiemil.eoyaml.Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) SingleInterop(hu.akarnokd.rxjava2.interop.SingleInterop) YamlSequenceBuilder(com.amihaiemil.eoyaml.YamlSequenceBuilder) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) ContentAsYaml(com.artipie.misc.ContentAsYaml) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Storage(com.artipie.asto.Storage) Optional(java.util.Optional) Collections(java.util.Collections) SetOf(org.cactoos.set.SetOf) YamlNode(com.amihaiemil.eoyaml.YamlNode) SetOf(org.cactoos.set.SetOf) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder)

Aggregations

YamlMapping (com.amihaiemil.eoyaml.YamlMapping)23 YamlNode (com.amihaiemil.eoyaml.YamlNode)10 Key (com.artipie.asto.Key)9 YamlMappingBuilder (com.amihaiemil.eoyaml.YamlMappingBuilder)8 Storage (com.artipie.asto.Storage)7 Collectors (java.util.stream.Collectors)6 IOException (java.io.IOException)5 UncheckedIOException (java.io.UncheckedIOException)5 StrictYamlMapping (com.amihaiemil.eoyaml.StrictYamlMapping)4 Yaml (com.amihaiemil.eoyaml.Yaml)4 BlockingStorage (com.artipie.asto.blocking.BlockingStorage)4 EtcdStorage (com.artipie.asto.etcd.EtcdStorage)4 FileStorage (com.artipie.asto.fs.FileStorage)4 S3Storage (com.artipie.asto.s3.S3Storage)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Collections (java.util.Collections)4 Optional (java.util.Optional)4 YamlSequenceBuilder (com.amihaiemil.eoyaml.YamlSequenceBuilder)3 NotFoundException (com.artipie.front.api.NotFoundException)3 Json2Yaml (com.artipie.front.misc.Json2Yaml)3