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