Search in sources :

Example 11 with YamlMapping

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

the class AuthFromYaml method user.

@Override
public Optional<Authentication.User> user(final String user, final String pass) {
    final YamlMapping users = this.cred.yamlMapping("credentials");
    Optional<Authentication.User> res = Optional.empty();
    if (users != null && users.yamlMapping(user) != null) {
        final String stored = users.yamlMapping(user).string("pass");
        final Optional<String> type = Optional.ofNullable(users.yamlMapping(user).string("type"));
        if (stored != null && checkPswdByType(stored, type, pass)) {
            res = Optional.of(new User(user, AuthFromYaml.groups(users.yamlMapping(user))));
        }
    }
    return res;
}
Also used : YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

Example 12 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping in project MC-Server-Bot by polarbub.

the class config method readConfig.

public static void readConfig() throws IOException, InterruptedException, LoginException {
    YamlMapping config = Yaml.createYamlInput(new File(Main.runTimeArgs[0])).readYamlMapping();
    YamlMapping backupConfig = config.yamlMapping("BACKUP");
    YamlMapping discordConfig = config.yamlMapping("DISCORD_BOT");
    YamlMapping minecraftConfig = config.yamlMapping("MC_SERVER");
    permissionsConfig = config.yamlMapping("PERMISSIONS");
    serverArgs.clear();
    YamlSequence startCMD = minecraftConfig.yamlSequence("startCMD");
    if (System.getProperty("os.name").equals("Linux")) {
        StringBuilder s = new StringBuilder();
        int i = 0;
        for (YamlNode node : startCMD) {
            s.append(startCMD.string(i));
            s.append(" ");
            i++;
        }
        s.delete(s.length() - 1, s.length());
        serverArgs.add(s.toString());
    } else {
        int i = 0;
        for (YamlNode node : startCMD) {
            serverArgs.add(startCMD.string(i));
            i++;
        }
    }
    webHookURL = new URL(discordConfig.string("chatBridgeWebHookURL"));
    // Get the channel IDs
    token = discordConfig.string("TOKEN");
    pre = discordConfig.string("PREFIX");
    // init discord jda
    bot = JDABuilder.createLight(token, GatewayIntent.GUILD_MESSAGES, GatewayIntent.DIRECT_MESSAGES).addEventListeners(new Main()).build();
    while (!String.valueOf(bot.getStatus()).equals("CONNECTED")) {
        // wait for connected
        Thread.sleep(10);
    }
    Thread.sleep(1000);
    consoleChannel = bot.getTextChannelById(discordConfig.longNumber("CONSOLE_CHANNEL"));
    chatBridgeChannel = bot.getTextChannelById(discordConfig.longNumber("CHAT_CHANNEL"));
    test = discordConfig.string("test");
    // Add all normal regexs to list
    normalPatterns.clear();
    YamlSequence normalRegexes = minecraftConfig.yamlSequence("normalRegexes");
    for (YamlNode regexNode : normalRegexes) {
        net.polarbub.botv2.config.normalPattern NormalPattern = new normalPattern();
        YamlMapping regexSequence = regexNode.asMapping().yamlMapping("regex");
        NormalPattern.pattern = Pattern.compile(regexSequence.string("string"));
        NormalPattern.dataGroup = regexSequence.integer("contentGroup");
        normalPatterns.add(NormalPattern);
    }
    // Add all named regexs to list
    namedPatterns.clear();
    YamlSequence namedRegexs = minecraftConfig.yamlSequence("webHookRegexes");
    for (YamlNode regexNode : namedRegexs) {
        net.polarbub.botv2.config.namedPattern NamedPattern = new namedPattern();
        YamlMapping regexSequence = regexNode.asMapping().yamlMapping("regex");
        NamedPattern.pattern = Pattern.compile(regexSequence.string("string"));
        if (regexSequence.string("prefix").equals("\"\"")) {
            NamedPattern.prefix = "";
        } else {
            NamedPattern.prefix = regexSequence.string("prefix");
        }
        NamedPattern.dataGroup = regexSequence.integer("contentGroup");
        NamedPattern.nameGroup = regexSequence.integer("nameGroup");
        namedPatterns.add(NamedPattern);
    }
    startPattern = Pattern.compile(minecraftConfig.string("startRegex"));
    startPattern = Pattern.compile("^\\[\\d\\d:\\d\\d:\\d\\d] \\[Server thread\\/INFO\\]: Done \\(\\d+.\\d+s\\)! For help, type \"help");
    pingPort = minecraftConfig.integer("pingPort");
    queryPort = minecraftConfig.integer("queryPort");
    realIP = minecraftConfig.string("realIP");
    showIP = minecraftConfig.string("showIP");
    backupTime = backupConfig.longNumber("backup_time");
    if (backupTime < 0)
        throw new IllegalArgumentException("Backup Time cannon be less than zero");
    backupWarn = backupConfig.longNumber("backup_alert");
    serverDir = backupConfig.string("gitDirectory");
    gitsavereturnPattern = Pattern.compile(backupConfig.string("gitsavereturnRegex"));
}
Also used : URL(java.net.URL) YamlSequence(com.amihaiemil.eoyaml.YamlSequence) YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) File(java.io.File) Main(net.polarbub.botv2.Main)

Example 13 with YamlMapping

use of com.amihaiemil.eoyaml.YamlMapping 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")));
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) UncheckedIOException(java.io.UncheckedIOException) YamlCredentials(com.artipie.front.auth.YamlCredentials) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Key(com.artipie.asto.Key)

Example 14 with YamlMapping

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

the class YamlStorage method etcdClient.

/**
 * Build etcd client from yaml config.
 * @param yaml Etcd config
 * @return Etcd client
 */
private static Client etcdClient(final YamlMapping yaml) {
    final ClientBuilder builder = Client.builder().endpoints(yaml.yamlSequence("endpoints").values().stream().map(node -> node.asScalar().value()).collect(Collectors.toList()).toArray(new String[0]));
    final String sto = yaml.string("timeout");
    if (sto != null) {
        builder.connectTimeoutMs(Integer.valueOf(sto));
    }
    return builder.build();
}
Also used : ClientBuilder(io.etcd.jetcd.ClientBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) Client(io.etcd.jetcd.Client) S3AsyncClient(software.amazon.awssdk.services.s3.S3AsyncClient) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) Collectors(java.util.stream.Collectors) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder) StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) S3Storage(com.artipie.asto.s3.S3Storage) URI(java.net.URI) AwsBasicCredentials(software.amazon.awssdk.auth.credentials.AwsBasicCredentials) Region(software.amazon.awssdk.regions.Region) Path(java.nio.file.Path) ClientBuilder(io.etcd.jetcd.ClientBuilder) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder)

Example 15 with YamlMapping

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

the class YamlUsers method add.

@Override
public void add(final JsonObject info, final String uid) {
    YamlMappingBuilder builder = Yaml.createYamlMappingBuilder();
    final Optional<YamlMapping> users = this.users();
    if (users.isPresent()) {
        for (final YamlNode node : users.get().keys()) {
            final String val = node.asScalar().value();
            builder = builder.add(val, users.get().yamlMapping(val));
        }
    }
    builder = builder.add(uid, new Json2Yaml().apply(info.toString()));
    this.blsto.save(this.key, Yaml.createYamlMappingBuilder().add(ArtipieYaml.NODE_CREDENTIALS, builder.build()).build().toString().getBytes(StandardCharsets.UTF_8));
}
Also used : Json2Yaml(com.artipie.front.misc.Json2Yaml) YamlNode(com.amihaiemil.eoyaml.YamlNode) YamlMappingBuilder(com.amihaiemil.eoyaml.YamlMappingBuilder) YamlMapping(com.amihaiemil.eoyaml.YamlMapping)

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