Fix Exec store breakage following change to new config format
This commit is contained in:
@@ -212,21 +212,25 @@ The command will use the default values for:
|
||||
#### Advanced
|
||||
Given the fictional `placeholder` feature:
|
||||
```yaml
|
||||
exec.enabled: true
|
||||
exec.token.mxid: '{matrixId}'
|
||||
|
||||
exec.placeholder.token.localpart: '{username}'
|
||||
exec.placeholder.command: '/path/to/executable'
|
||||
exec.placeholder.args:
|
||||
- '-u'
|
||||
- '{username}'
|
||||
exec.placeholder.env:
|
||||
MATRIX_DOMAIN: '{domain}'
|
||||
MATRIX_USER_ID: '{matrixId}'
|
||||
|
||||
exec.placeholder.output.type: 'json'
|
||||
exec.placeholder.exit.success: [0, 128]
|
||||
exec.placeholder.exit.failure: [1, 129]
|
||||
exec:
|
||||
enabled: true
|
||||
token:
|
||||
mxid: '{matrixId}'
|
||||
auth:
|
||||
token:
|
||||
localpart: '{username}'
|
||||
command: '/path/to/executable'
|
||||
args:
|
||||
- '-u'
|
||||
- '{username}'
|
||||
env:
|
||||
MATRIX_DOMAIN: '{domain}'
|
||||
MATRIX_USER_ID: '{matrixId}'
|
||||
output:
|
||||
type: 'json'
|
||||
exit:
|
||||
success: [0, 128]
|
||||
failure: [1, 129]
|
||||
```
|
||||
With:
|
||||
- The Identity store enabled for all features
|
||||
|
@@ -44,6 +44,7 @@ public class ExecAuthStore extends ExecStore implements AuthenticatorProvider {
|
||||
private ExecConfig.Auth cfg;
|
||||
|
||||
public ExecAuthStore(ExecConfig cfg) {
|
||||
super(cfg);
|
||||
this.cfg = Objects.requireNonNull(cfg.getAuth());
|
||||
}
|
||||
|
||||
|
@@ -36,11 +36,12 @@ public class ExecDirectoryStore extends ExecStore implements DirectoryProvider {
|
||||
private MatrixConfig mxCfg;
|
||||
|
||||
public ExecDirectoryStore(MxisdConfig cfg) {
|
||||
this(cfg.getExec().getDirectory(), cfg.getMatrix());
|
||||
this(cfg.getExec(), cfg.getMatrix());
|
||||
}
|
||||
|
||||
public ExecDirectoryStore(ExecConfig.Directory cfg, MatrixConfig mxCfg) {
|
||||
this.cfg = cfg;
|
||||
public ExecDirectoryStore(ExecConfig cfg, MatrixConfig mxCfg) {
|
||||
super(cfg);
|
||||
this.cfg = cfg.getDirectory();
|
||||
this.mxCfg = mxCfg;
|
||||
}
|
||||
|
||||
|
@@ -55,11 +55,8 @@ public class ExecIdentityStore extends ExecStore implements IThreePidProvider {
|
||||
private final MatrixConfig mxCfg;
|
||||
|
||||
public ExecIdentityStore(ExecConfig cfg, MatrixConfig mxCfg) {
|
||||
this(cfg.getIdentity(), mxCfg);
|
||||
}
|
||||
|
||||
public ExecIdentityStore(ExecConfig.Identity cfg, MatrixConfig mxCfg) {
|
||||
this.cfg = cfg;
|
||||
super(cfg);
|
||||
this.cfg = cfg.getIdentity();
|
||||
this.mxCfg = mxCfg;
|
||||
}
|
||||
|
||||
|
@@ -38,11 +38,8 @@ public class ExecProfileStore extends ExecStore implements ProfileProvider {
|
||||
private ExecConfig.Profile cfg;
|
||||
|
||||
public ExecProfileStore(ExecConfig cfg) {
|
||||
this(cfg.getProfile());
|
||||
}
|
||||
|
||||
public ExecProfileStore(ExecConfig.Profile cfg) {
|
||||
this.cfg = cfg;
|
||||
super(cfg);
|
||||
this.cfg = cfg.getProfile();
|
||||
}
|
||||
|
||||
private Optional<JsonProfileResult> getFull(_MatrixID userId, ExecConfig.Process cfg) {
|
||||
|
@@ -43,14 +43,19 @@ public class ExecStore {
|
||||
public static final String JsonType = "json";
|
||||
public static final String PlainType = "plain";
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ExecStore.class);
|
||||
|
||||
protected static String toJson(Object o) {
|
||||
return GsonUtil.get().toJson(o);
|
||||
}
|
||||
|
||||
private transient final Logger log = LoggerFactory.getLogger(ExecStore.class);
|
||||
|
||||
private final ExecConfig cfg;
|
||||
private Supplier<ProcessExecutor> executorSupplier = () -> new ProcessExecutor().readOutput(true);
|
||||
|
||||
public ExecStore(ExecConfig cfg) {
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
public void setExecutorSupplier(Supplier<ProcessExecutor> supplier) {
|
||||
executorSupplier = supplier;
|
||||
}
|
||||
@@ -64,7 +69,7 @@ public class ExecStore {
|
||||
private Function<String, String> inputUnknownTypeMapper;
|
||||
private Map<String, Supplier<String>> inputTypeSuppliers;
|
||||
|
||||
private Map<String, Function<ExecConfig.TokenOverride, String>> inputTypeTemplates;
|
||||
private Map<String, Function<ExecConfig.Token, String>> inputTypeTemplates;
|
||||
private Supplier<String> inputTypeNoTemplateHandler;
|
||||
private Map<String, Supplier<String>> tokenMappers;
|
||||
private Function<String, String> tokenHandler;
|
||||
@@ -156,11 +161,11 @@ public class ExecStore {
|
||||
inputTypeSuppliers.put(type, handler);
|
||||
}
|
||||
|
||||
protected void addInputTemplate(String type, Function<ExecConfig.TokenOverride, String> template) {
|
||||
protected void addInputTemplate(String type, Function<ExecConfig.Token, String> template) {
|
||||
inputTypeTemplates.put(type, template);
|
||||
}
|
||||
|
||||
public void addJsonInputTemplate(Function<ExecConfig.TokenOverride, Object> template) {
|
||||
public void addJsonInputTemplate(Function<ExecConfig.Token, Object> template) {
|
||||
inputTypeTemplates.put(JsonType, token -> GsonUtil.get().toJson(template.apply(token)));
|
||||
}
|
||||
|
||||
|
@@ -20,13 +20,11 @@
|
||||
|
||||
package io.kamax.mxisd.config;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class ExecConfig {
|
||||
|
||||
public class IO {
|
||||
public static class IO {
|
||||
|
||||
private String type;
|
||||
private String template;
|
||||
@@ -49,7 +47,7 @@ public class ExecConfig {
|
||||
|
||||
}
|
||||
|
||||
public class Exit {
|
||||
public static class Exit {
|
||||
|
||||
private List<Integer> success = Collections.singletonList(0);
|
||||
private List<Integer> failure = Collections.singletonList(1);
|
||||
@@ -72,84 +70,7 @@ public class ExecConfig {
|
||||
|
||||
}
|
||||
|
||||
public class TokenOverride {
|
||||
|
||||
private String localpart;
|
||||
private String domain;
|
||||
private String mxid;
|
||||
private String password;
|
||||
private String medium;
|
||||
private String address;
|
||||
private String type;
|
||||
private String query;
|
||||
|
||||
public String getLocalpart() {
|
||||
return StringUtils.defaultIfEmpty(localpart, getToken().getLocalpart());
|
||||
}
|
||||
|
||||
public void setLocalpart(String localpart) {
|
||||
this.localpart = localpart;
|
||||
}
|
||||
|
||||
public String getDomain() {
|
||||
return StringUtils.defaultIfEmpty(domain, getToken().getDomain());
|
||||
}
|
||||
|
||||
public void setDomain(String domain) {
|
||||
this.domain = domain;
|
||||
}
|
||||
|
||||
public String getMxid() {
|
||||
return StringUtils.defaultIfEmpty(mxid, getToken().getMxid());
|
||||
}
|
||||
|
||||
public void setMxid(String mxid) {
|
||||
this.mxid = mxid;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return StringUtils.defaultIfEmpty(password, getToken().getPassword());
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getMedium() {
|
||||
return StringUtils.defaultIfEmpty(medium, getToken().getMedium());
|
||||
}
|
||||
|
||||
public void setMedium(String medium) {
|
||||
this.medium = medium;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return StringUtils.defaultIfEmpty(address, getToken().getAddress());
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return StringUtils.defaultIfEmpty(type, getToken().getType());
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return StringUtils.defaultIfEmpty(query, getToken().getQuery());
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class Token {
|
||||
public static class Token {
|
||||
|
||||
private String localpart = "{localpart}";
|
||||
private String domain = "{domain}";
|
||||
@@ -226,9 +147,9 @@ public class ExecConfig {
|
||||
|
||||
}
|
||||
|
||||
public class Process {
|
||||
public static class Process {
|
||||
|
||||
private TokenOverride token = new TokenOverride();
|
||||
private Token token = new Token();
|
||||
private String command;
|
||||
|
||||
private List<String> args = new ArrayList<>();
|
||||
@@ -238,11 +159,11 @@ public class ExecConfig {
|
||||
private Exit exit = new Exit();
|
||||
private IO output = new IO();
|
||||
|
||||
public TokenOverride getToken() {
|
||||
public Token getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(TokenOverride token) {
|
||||
public void setToken(Token token) {
|
||||
this.token = token;
|
||||
}
|
||||
|
||||
@@ -300,7 +221,7 @@ public class ExecConfig {
|
||||
|
||||
}
|
||||
|
||||
public class Auth extends Process {
|
||||
public static class Auth extends Process {
|
||||
|
||||
private Boolean enabled;
|
||||
|
||||
@@ -314,9 +235,9 @@ public class ExecConfig {
|
||||
|
||||
}
|
||||
|
||||
public class Directory {
|
||||
public static class Directory {
|
||||
|
||||
public class Search {
|
||||
public static class Search {
|
||||
|
||||
private Process byName = new Process();
|
||||
private Process byThreepid = new Process();
|
||||
@@ -360,7 +281,7 @@ public class ExecConfig {
|
||||
|
||||
}
|
||||
|
||||
public class Lookup {
|
||||
public static class Lookup {
|
||||
|
||||
private Process single = new Process();
|
||||
private Process bulk = new Process();
|
||||
@@ -383,7 +304,7 @@ public class ExecConfig {
|
||||
|
||||
}
|
||||
|
||||
public class Identity {
|
||||
public static class Identity {
|
||||
|
||||
private Boolean enabled;
|
||||
private int priority;
|
||||
@@ -415,7 +336,7 @@ public class ExecConfig {
|
||||
|
||||
}
|
||||
|
||||
public class Profile {
|
||||
public static class Profile {
|
||||
|
||||
private Boolean enabled;
|
||||
private Process displayName = new Process();
|
||||
|
@@ -56,32 +56,32 @@ public class ExecDirectoryStoreTest extends ExecStoreTest {
|
||||
}));
|
||||
}
|
||||
|
||||
private ExecConfig.Directory getCfg() {
|
||||
ExecConfig.Directory cfg = new ExecConfig().build().getDirectory();
|
||||
private ExecConfig getCfg() {
|
||||
ExecConfig cfg = new ExecConfig().build();
|
||||
assertFalse(cfg.isEnabled());
|
||||
cfg.setEnabled(true);
|
||||
assertTrue(cfg.isEnabled());
|
||||
cfg.getSearch().getByName().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getDirectory().getSearch().getByName().getOutput().setType(ExecStore.JsonType);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private ExecDirectoryStore getStore(ExecConfig.Directory cfg) {
|
||||
private ExecDirectoryStore getStore(ExecConfig cfg) {
|
||||
ExecDirectoryStore store = new ExecDirectoryStore(cfg, getMatrixCfg());
|
||||
store.setExecutorSupplier(this::build);
|
||||
return store;
|
||||
}
|
||||
|
||||
private ExecDirectoryStore getStore(String command) {
|
||||
ExecConfig.Directory cfg = getCfg();
|
||||
cfg.getSearch().getByName().setCommand(command);
|
||||
cfg.getSearch().getByThreepid().setCommand(command);
|
||||
ExecConfig cfg = getCfg();
|
||||
cfg.getDirectory().getSearch().getByName().setCommand(command);
|
||||
cfg.getDirectory().getSearch().getByThreepid().setCommand(command);
|
||||
return getStore(cfg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byNameNoCommandDefined() {
|
||||
ExecConfig.Directory cfg = getCfg();
|
||||
assertTrue(StringUtils.isEmpty(cfg.getSearch().getByName().getCommand()));
|
||||
ExecConfig cfg = getCfg();
|
||||
assertTrue(StringUtils.isEmpty(cfg.getDirectory().getSearch().getByName().getCommand()));
|
||||
ExecDirectoryStore store = getStore(cfg);
|
||||
|
||||
UserDirectorySearchResult result = store.searchByDisplayName("user");
|
||||
|
@@ -62,17 +62,17 @@ public class ExecIdentityStoreTest extends ExecStoreTest {
|
||||
}));
|
||||
}
|
||||
|
||||
private ExecConfig.Identity getCfg() {
|
||||
ExecConfig.Identity cfg = new ExecConfig().build().getIdentity();
|
||||
private ExecConfig getCfg() {
|
||||
ExecConfig cfg = new ExecConfig().build();
|
||||
assertFalse(cfg.isEnabled());
|
||||
cfg.setEnabled(true);
|
||||
assertTrue(cfg.isEnabled());
|
||||
cfg.getLookup().getSingle().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getLookup().getBulk().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getIdentity().getLookup().getSingle().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getIdentity().getLookup().getBulk().getOutput().setType(ExecStore.JsonType);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private ExecIdentityStore getStore(ExecConfig.Identity cfg) {
|
||||
private ExecIdentityStore getStore(ExecConfig cfg) {
|
||||
ExecIdentityStore store = new ExecIdentityStore(cfg, getMatrixCfg());
|
||||
store.setExecutorSupplier(this::build);
|
||||
assertTrue(store.isLocal());
|
||||
@@ -80,9 +80,9 @@ public class ExecIdentityStoreTest extends ExecStoreTest {
|
||||
}
|
||||
|
||||
private ExecIdentityStore getStore(String command) {
|
||||
ExecConfig.Identity cfg = getCfg();
|
||||
cfg.getLookup().getSingle().setCommand(command);
|
||||
cfg.getLookup().getBulk().setCommand(command);
|
||||
ExecConfig cfg = getCfg();
|
||||
cfg.getIdentity().getLookup().getSingle().setCommand(command);
|
||||
cfg.getIdentity().getLookup().getBulk().setCommand(command);
|
||||
return getStore(cfg);
|
||||
}
|
||||
|
||||
|
@@ -70,28 +70,28 @@ public class ExecProfileStoreTest extends ExecStoreTest {
|
||||
|
||||
}
|
||||
|
||||
private ExecConfig.Profile getCfg() {
|
||||
ExecConfig.Profile cfg = new ExecConfig().build().getProfile();
|
||||
private ExecConfig getCfg() {
|
||||
ExecConfig cfg = new ExecConfig().build();
|
||||
assertFalse(cfg.isEnabled());
|
||||
cfg.setEnabled(true);
|
||||
assertTrue(cfg.isEnabled());
|
||||
cfg.getDisplayName().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getThreePid().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getRole().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getProfile().getDisplayName().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getProfile().getThreePid().getOutput().setType(ExecStore.JsonType);
|
||||
cfg.getProfile().getRole().getOutput().setType(ExecStore.JsonType);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private ExecProfileStore getStore(ExecConfig.Profile cfg) {
|
||||
private ExecProfileStore getStore(ExecConfig cfg) {
|
||||
ExecProfileStore store = new ExecProfileStore(cfg);
|
||||
store.setExecutorSupplier(this::build);
|
||||
return store;
|
||||
}
|
||||
|
||||
private ExecProfileStore getStore(String command) {
|
||||
ExecConfig.Profile cfg = getCfg();
|
||||
cfg.getDisplayName().setCommand(command);
|
||||
cfg.getThreePid().setCommand(command);
|
||||
cfg.getRole().setCommand(command);
|
||||
ExecConfig cfg = getCfg();
|
||||
cfg.getProfile().getDisplayName().setCommand(command);
|
||||
cfg.getProfile().getThreePid().setCommand(command);
|
||||
cfg.getProfile().getRole().setCommand(command);
|
||||
return getStore(cfg);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user