Search in sources :

Example 1 with MxisdConfig

use of io.kamax.mxisd.config.MxisdConfig in project mxisd by kamax-io.

the class MxisdStandaloneExec method main.

public static void main(String[] args) {
    String logLevel = System.getenv("MXISD_LOG_LEVEL");
    if (StringUtils.isNotBlank(logLevel)) {
        System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", logLevel);
    }
    try {
        MxisdConfig cfg = null;
        Iterator<String> argsIt = Arrays.asList(args).iterator();
        while (argsIt.hasNext()) {
            String arg = argsIt.next();
            if (StringUtils.equalsAny(arg, "-h", "--help", "-?", "--usage")) {
                System.out.println("Available arguments:" + System.lineSeparator());
                System.out.println("  -h, --help       Show this help message");
                System.out.println("  --version        Print the version then exit");
                System.out.println("  -c, --config     Set the configuration file location");
                System.out.println("  -v               Increase log level (log more info)");
                System.out.println("  -vv              Further increase log level");
                System.out.println(" ");
                System.exit(0);
            } else if (StringUtils.equals(arg, "-v")) {
                System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", "debug");
            } else if (StringUtils.equals(arg, "-vv")) {
                System.setProperty("org.slf4j.simpleLogger.log.io.kamax.mxisd", "trace");
            } else if (StringUtils.equalsAny(arg, "-c", "--config")) {
                String cfgFile = argsIt.next();
                cfg = YamlConfigLoader.loadFromFile(cfgFile);
            } else if (StringUtils.equals("--version", arg)) {
                System.out.println(Mxisd.Version);
                System.exit(0);
            } else {
                System.err.println("Invalid argument: " + arg);
                System.err.println("Try '--help' for available arguments");
                System.exit(1);
            }
        }
        if (Objects.isNull(cfg)) {
            cfg = YamlConfigLoader.tryLoadFromFile("mxisd.yaml").orElseGet(MxisdConfig::new);
        }
        log.info("mxisd starting");
        log.info("Version: {}", Mxisd.Version);
        HttpMxisd mxisd = new HttpMxisd(cfg);
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            mxisd.stop();
            log.info("mxisd stopped");
        }));
        mxisd.start();
        log.info("mxisd started");
    } catch (ConfigurationException e) {
        log.error(e.getDetailedMessage());
        log.error(e.getMessage());
        System.exit(2);
    } catch (Throwable t) {
        t.printStackTrace();
        System.exit(1);
    }
}
Also used : MxisdConfig(io.kamax.mxisd.config.MxisdConfig) ConfigurationException(io.kamax.mxisd.exception.ConfigurationException)

Example 2 with MxisdConfig

use of io.kamax.mxisd.config.MxisdConfig in project mxisd by kamax-io.

the class AuthManagerTest method beforeClass.

// FIXME we should be able to easily build the class ourselves
// FIXME use constants
@BeforeClass
public static void beforeClass() {
    MxisdConfig cfg = new MxisdConfig();
    cfg.getMatrix().setDomain("localhost");
    cfg.getKey().setPath(":memory:");
    cfg.getStorage().getProvider().getSqlite().setDatabase(":memory:");
    MemoryThreePid mem3pid = new MemoryThreePid();
    mem3pid.setMedium("email");
    mem3pid.setAddress("john@localhost");
    MemoryIdentityConfig validCfg = new MemoryIdentityConfig();
    validCfg.setUsername("john");
    validCfg.setPassword("doe");
    validCfg.getThreepids().add(mem3pid);
    MemoryIdentityConfig illegalUser = new MemoryIdentityConfig();
    illegalUser.setUsername("JANE");
    illegalUser.setPassword("doe");
    cfg.getMemory().setEnabled(true);
    cfg.getMemory().getIdentities().add(validCfg);
    cfg.getMemory().getIdentities().add(illegalUser);
    Mxisd m = new Mxisd(cfg);
    m.start();
    mgr = m.getAuth();
}
Also used : MxisdConfig(io.kamax.mxisd.config.MxisdConfig) MemoryIdentityConfig(io.kamax.mxisd.config.memory.MemoryIdentityConfig) Mxisd(io.kamax.mxisd.Mxisd) MemoryThreePid(io.kamax.mxisd.config.memory.MemoryThreePid) BeforeClass(org.junit.BeforeClass)

Example 3 with MxisdConfig

use of io.kamax.mxisd.config.MxisdConfig in project mxisd by kamax-io.

the class MxisdTest method before.

@Before
public void before() {
    MxisdConfig cfg = MxisdConfig.forDomain("localhost").inMemory();
    MemoryThreePid mem3pid = new MemoryThreePid();
    mem3pid.setMedium("email");
    mem3pid.setAddress("john@localhost");
    MemoryIdentityConfig memCfg = new MemoryIdentityConfig();
    memCfg.setUsername("john");
    memCfg.getThreepids().add(mem3pid);
    cfg.getMemory().setEnabled(true);
    cfg.getMemory().getIdentities().add(memCfg);
    m = new Mxisd(cfg);
    m.start();
}
Also used : MxisdConfig(io.kamax.mxisd.config.MxisdConfig) MemoryIdentityConfig(io.kamax.mxisd.config.memory.MemoryIdentityConfig) Mxisd(io.kamax.mxisd.Mxisd) MemoryThreePid(io.kamax.mxisd.config.memory.MemoryThreePid) Before(org.junit.Before)

Example 4 with MxisdConfig

use of io.kamax.mxisd.config.MxisdConfig in project mxisd by kamax-io.

the class HomeserverFederationResolverTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    CloseableHttpClient client = HttpClients.custom().setUserAgent(Mxisd.Agent).setMaxConnPerRoute(Integer.MAX_VALUE).setMaxConnTotal(Integer.MAX_VALUE).build();
    FederationDnsOverwrite fedDns = new FederationDnsOverwrite(new MxisdConfig().getDns().getOverwrite());
    resolver = new HomeserverFederationResolver(fedDns, client);
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) MxisdConfig(io.kamax.mxisd.config.MxisdConfig) HomeserverFederationResolver(io.kamax.mxisd.matrix.HomeserverFederationResolver) FederationDnsOverwrite(io.kamax.mxisd.dns.FederationDnsOverwrite) BeforeClass(org.junit.BeforeClass)

Example 5 with MxisdConfig

use of io.kamax.mxisd.config.MxisdConfig in project mxisd by kamax-io.

the class EmailNotificationTest method before.

@Before
public void before() {
    EmailSmtpConfig smtpCfg = new EmailSmtpConfig();
    smtpCfg.setPort(3025);
    smtpCfg.setLogin(user);
    smtpCfg.setPassword(user);
    EmailConfig eCfg = new EmailConfig();
    eCfg.setConnector(EmailSmtpConnector.ID);
    eCfg.getIdentity().setFrom(sender);
    eCfg.getIdentity().setName(senderName);
    eCfg.getConnectors().put(EmailSmtpConnector.ID, GsonUtil.makeObj(smtpCfg));
    MxisdConfig cfg = new MxisdConfig();
    cfg.getMatrix().setDomain(domain);
    cfg.getKey().setPath(":memory:");
    cfg.getStorage().getProvider().getSqlite().setDatabase(":memory:");
    cfg.getThreepid().getMedium().put(ThreePidMedium.Email.getId(), GsonUtil.makeObj(eCfg));
    m = new Mxisd(cfg);
    m.start();
    gm = new GreenMail(ServerSetupTest.SMTP_IMAP);
    gm.start();
}
Also used : MxisdConfig(io.kamax.mxisd.config.MxisdConfig) EmailConfig(io.kamax.mxisd.config.threepid.medium.EmailConfig) GreenMail(com.icegreen.greenmail.util.GreenMail) Mxisd(io.kamax.mxisd.Mxisd) EmailSmtpConfig(io.kamax.mxisd.config.threepid.connector.EmailSmtpConfig) Before(org.junit.Before)

Aggregations

MxisdConfig (io.kamax.mxisd.config.MxisdConfig)6 Mxisd (io.kamax.mxisd.Mxisd)4 MemoryIdentityConfig (io.kamax.mxisd.config.memory.MemoryIdentityConfig)2 MemoryThreePid (io.kamax.mxisd.config.memory.MemoryThreePid)2 Before (org.junit.Before)2 BeforeClass (org.junit.BeforeClass)2 GreenMail (com.icegreen.greenmail.util.GreenMail)1 EmailSmtpConfig (io.kamax.mxisd.config.threepid.connector.EmailSmtpConfig)1 EmailConfig (io.kamax.mxisd.config.threepid.medium.EmailConfig)1 FederationDnsOverwrite (io.kamax.mxisd.dns.FederationDnsOverwrite)1 ConfigurationException (io.kamax.mxisd.exception.ConfigurationException)1 HomeserverFederationResolver (io.kamax.mxisd.matrix.HomeserverFederationResolver)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 Test (org.junit.Test)1