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