Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from kamax-io/dynamic-config
Browse files Browse the repository at this point in the history
Dynamic config
  • Loading branch information
Max Dor authored May 30, 2018
2 parents edf3af7 + 7fbcac1 commit 83c03ca
Show file tree
Hide file tree
Showing 32 changed files with 1,011 additions and 90 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ dependencies {
compile 'io.undertow:undertow-core:2.0.1.Final'
compile 'io.kamax:matrix-java-sdk:0.0.9'

// DB
compile 'com.j256.ormlite:ormlite-jdbc:5.0'
compile 'org.xerial:sqlite-jdbc:3.20.0'

testCompile 'junit:junit:4.12'
}

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/io/kamax/mxgwd/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@

package io.kamax.mxgwd.config;

import io.kamax.mxgwd.config.admin.Admin;
import io.kamax.mxgwd.config.matrix.Matrix;
import io.kamax.mxgwd.config.server.Server;

public class Config {

private Matrix matrix;
private Server server;
private Admin admin;
private Storage storage;

public Matrix getMatrix() {
return Value.get(matrix, Matrix::new);
Expand All @@ -44,4 +47,20 @@ public void setServer(Server server) {
this.server = server;
}

public Admin getAdmin() {
return Value.get(admin, Admin::new);
}

public void setAdmin(Admin admin) {
this.admin = admin;
}

public Storage getStorage() {
return Value.get(storage, Storage::new);
}

public void setStorage(Storage storage) {
this.storage = storage;
}

}
44 changes: 44 additions & 0 deletions src/main/java/io/kamax/mxgwd/config/Storage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Matrix Gateway Daemon
* Copyright (C) 2018 Kamax Sarl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package io.kamax.mxgwd.config;

public class Storage {

private String type;
private String location;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getLocation() {
return location;
}

public void setLocation(String location) {
this.location = location;
}

}
35 changes: 35 additions & 0 deletions src/main/java/io/kamax/mxgwd/config/admin/Admin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Matrix Gateway Daemon
* Copyright (C) 2018 Kamax Sarl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package io.kamax.mxgwd.config.admin;

public class Admin {

private int port = 8880;

public int getPort() {
return port;
}

public void setPort(int port) {
this.port = port;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

package io.kamax.mxgwd.config.matrix;

public class MatrixAcl {
public class Acl {

private String type;
private String target;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/kamax/mxgwd/config/matrix/AclType.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public boolean is(String id) {
return toString().equalsIgnoreCase(id);
}

public boolean is(MatrixAcl acl) {
public boolean is(Acl acl) {
return is(acl.getType());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
import java.util.HashMap;
import java.util.Map;

public class MatrixClient {
public class Client {

private Map<String, MatrixHost> hosts;
private Map<String, Host> hosts;

public Map<String, MatrixHost> getHosts() {
public Map<String, Host> getHosts() {
return Value.get(hosts, HashMap::new);
}

public void setHosts(Map<String, MatrixHost> hosts) {
public void setHosts(Map<String, Host> hosts) {
this.hosts = hosts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import java.util.ArrayList;
import java.util.List;

public class MatrixEndpoint {
public class Endpoint {

private String method;
private String path;
private String match;
private String action;
private URL to;
private List<MatrixAcl> acls;
private List<Acl> acls;

public String getMethod() {
return method;
Expand Down Expand Up @@ -75,11 +75,11 @@ public void setTo(URL to) {
this.to = to;
}

public List<MatrixAcl> getAcls() {
public List<Acl> getAcls() {
return Value.get(acls, ArrayList::new);
}

public void setAcls(List<MatrixAcl> acls) {
public void setAcls(List<Acl> acls) {
this.acls = acls;
}

Expand Down
102 changes: 102 additions & 0 deletions src/main/java/io/kamax/mxgwd/config/matrix/EntityIO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Matrix Gateway Daemon
* Copyright (C) 2018 Kamax Sarl
*
* https://www.kamax.io/
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package io.kamax.mxgwd.config.matrix;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "entities")
public class EntityIO {

@DatabaseField(generatedId = true)
private Long id;

@DatabaseField(canBeNull = false, uniqueCombo = true)
private String host;

@DatabaseField(canBeNull = false, uniqueCombo = true)
private String type;

@DatabaseField(canBeNull = true, uniqueCombo = true)
private String name;

@DatabaseField(canBeNull = false)
private String aclType;

@DatabaseField(canBeNull = false, uniqueCombo = true)
private String aclTarget;

@DatabaseField(canBeNull = false, uniqueCombo = true)
private String aclValue;

public Long getId() {
return id;
}

public String getHost() {
return host;
}

public void setHost(String host) {
this.host = host;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getAclType() {
return aclType;
}

public void setAclType(String aclType) {
this.aclType = aclType;
}

public String getAclTarget() {
return aclTarget;
}

public void setAclTarget(String aclTarget) {
this.aclTarget = aclTarget;
}

public String getAclValue() {
return aclValue;
}

public void setAclValue(String aclValue) {
this.aclValue = aclValue;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
import java.util.ArrayList;
import java.util.List;

public class MatrixHost {
public class Host {

private URL to;
private URL toIdentity;
private List<MatrixEndpoint> endpoints;
private List<Endpoint> endpoints;
private List<Long> entities = new ArrayList<>();

public URL getTo() {
return to;
Expand All @@ -48,12 +49,24 @@ public void setToIdentity(URL toIdentity) {
this.toIdentity = toIdentity;
}

public List<MatrixEndpoint> getEndpoints() {
public List<Endpoint> getEndpoints() {
return Value.get(endpoints, ArrayList::new);
}

public void setEndpoints(List<MatrixEndpoint> endpoints) {
public void setEndpoints(List<Endpoint> endpoints) {
this.endpoints = endpoints;
}

public List<Long> getEntities() {
return entities;
}

public void setEntities(List<Long> entities) {
this.entities = entities;
}

public void addEntity(Long id) {
entities.add(id);
}

}
8 changes: 4 additions & 4 deletions src/main/java/io/kamax/mxgwd/config/matrix/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

public class Matrix {

private MatrixClient client;
private Client client;

public MatrixClient getClient() {
return Value.get(client, MatrixClient::new);
public Client getClient() {
return Value.get(client, Client::new);
}

public void setClient(MatrixClient client) {
public void setClient(Client client) {
this.client = client;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/kamax/mxgwd/config/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class Server {
private Integer port;

public Integer getPort() {
return Value.get(port, 8007);
return Value.get(port, 8000);
}

public void setPort(Integer port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import io.kamax.mxgwd.model.acl.AclTargetHandler;
import io.kamax.mxgwd.model.acl.GroupTargetHandler;
import io.kamax.mxgwd.model.acl.MethodTargetHandler;
import io.kamax.mxgwd.model.acl.UserTargetHandler;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -36,6 +37,7 @@ public AclTargetHandlerMapper() {
handlers = new HashMap<>();
handlers.put("method", new MethodTargetHandler());
handlers.put("group", new GroupTargetHandler());
handlers.put("user", new UserTargetHandler());
}

public Optional<AclTargetHandler> map(String id) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/io/kamax/mxgwd/model/ActionMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@

public class ActionMapper {

private Map<String, MethodPath> actions;
private Map<String, MethodPath> actions = new HashMap<>();

public ActionMapper() {
actions = new HashMap<>();
actions.put("m.room.create", new MethodPath("POST", "/_matrix/client/r0/createRoom"));
}

Expand Down
Loading

0 comments on commit 83c03ca

Please sign in to comment.