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));
}
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);
}
}
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);
}
}
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));
}
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;
}
Aggregations