Skip to content

Commit

Permalink
add support for getApplicationConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvergnaud committed Mar 8, 2020
1 parent 5db12c0 commit 07fc7d2
Show file tree
Hide file tree
Showing 23 changed files with 337 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package prompto.config.mongo;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

import prompto.config.IHostConfiguration;

public interface IMongoReplicaSetConfiguration {

Iterable<IHostConfiguration> getNodes();
boolean isSSL();
String getName();
YamlMapping toYaml() throws YamlException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import java.util.Collection;
import java.util.Iterator;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;
import com.esotericsoftware.yamlbeans.document.YamlSequence;

import prompto.config.HostConfiguration;
import prompto.config.IConfigurationReader;
import prompto.config.IHostConfiguration;
Expand Down Expand Up @@ -43,5 +47,19 @@ public Iterator<IHostConfiguration> iterator() {

};
}

@Override
public YamlMapping toYaml() throws YamlException {
YamlMapping yaml = new YamlMapping();
yaml.setEntry("name", getName());
yaml.setEntry("ssl", isSSL());
Iterable<IHostConfiguration> nodes = getNodes();
YamlSequence sequence = new YamlSequence();
for(IHostConfiguration host : nodes) {
sequence.addElement(host.toYaml());
}
yaml.setEntry("nodes", sequence);
return yaml;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.function.Supplier;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

import prompto.config.IConfigurationReader;
import prompto.config.StoreConfiguration;

Expand Down Expand Up @@ -41,6 +44,23 @@ public IMongoStoreConfiguration withReplicaSetConfiguration(IMongoReplicaSetConf
replicaSetConfig = ()->config;
return this;
}

@Override
public YamlMapping toYaml() throws YamlException {
YamlMapping mapping = super.toYaml();
IMongoReplicaSetConfiguration config = replicaSetConfig.get();
if(config!=null) {
mapping.deleteEntry("host");
mapping.deleteEntry("port");
mapping.setEntry("replicaSet", config.toYaml());
} else if(replicaSetURI.get()!=null) {
mapping.deleteEntry("host");
mapping.deleteEntry("port");
mapping.setEntry("replicaSetURI", replicaSetURI.get());
}
return mapping;
}



}
8 changes: 8 additions & 0 deletions MongoStore/src/test/java/prompto/store/mongo/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import prompto.config.mongo.MongoStoreConfiguration;
import prompto.utils.ManualTests;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlElement;
import com.esotericsoftware.yamlbeans.document.YamlMapping;
import com.mongodb.client.MongoIterable;

@Category(ManualTests.class)
Expand Down Expand Up @@ -84,18 +87,23 @@ public Iterable<IHostConfiguration> getNodes() {
return Arrays.asList(new IHostConfiguration() {
@Override public String getHost() { return "seed-shard-00-00-cp8j5.mongodb.net"; }
@Override public Integer getPort() { return 27017; }
@Override public YamlElement toYaml() throws YamlException { return null; }
}, new IHostConfiguration() {
@Override public String getHost() { return "seed-shard-00-01-cp8j5.mongodb.net"; }
@Override public Integer getPort() { return 27017; }
@Override public YamlElement toYaml() throws YamlException { return null; }
}, new IHostConfiguration() {
@Override public String getHost() { return "seed-shard-00-02-cp8j5.mongodb.net"; }
@Override public Integer getPort() { return 27017; }
@Override public YamlElement toYaml() throws YamlException { return null; }
});
}
@Override
public boolean isSSL() { return true; }
@Override
public String getName() { return "Seed-shard-0"; }
@Override
public YamlMapping toYaml() throws YamlException { return null; }
}; }
@Override public IMongoStoreConfiguration withReplicaSetConfiguration(IMongoReplicaSetConfiguration config) { return null; }
};
Expand Down
6 changes: 6 additions & 0 deletions Server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>AwsClient</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
Expand Down
35 changes: 33 additions & 2 deletions Server/src/main/java/prompto/config/HttpConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package prompto.config;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

import prompto.config.auth.AuthenticationConfiguration;
import prompto.config.auth.IAuthenticationConfiguration;
import prompto.config.auth.IAuthenticationConfigurationFactory;
Expand All @@ -24,12 +27,12 @@ public HttpConfiguration(IConfigurationReader reader) {

private IKeyStoreConfiguration readKeyStoreConfiguration() {
IConfigurationReader child = reader.getObject("keyStore");
return new KeyStoreConfiguration(child);
return child==null ? null : new KeyStoreConfiguration(child);
}

private IKeyStoreConfiguration readTrustStoreConfiguration() {
IConfigurationReader child = reader.getObject("trustStore");
return new KeyStoreConfiguration(child);
return child==null ? null : new KeyStoreConfiguration(child);
}

private IAuthenticationConfiguration readAuthenticationConfiguration() {
Expand All @@ -47,5 +50,33 @@ private IAuthenticationConfiguration readAuthenticationConfiguration() {
}

}

@Override
public YamlMapping toYaml() throws YamlException {
YamlMapping yaml = new YamlMapping();
String value = protocol.get();
if(value!=null)
yaml.setEntry("protocol", value);
if(port.get()!=-1)
yaml.setEntry("port", port.get());
value = welcomePage.get();
if(value!=null)
yaml.setEntry("welcomePage", value);
if(redirectFrom.get()!=null)
yaml.setEntry("redirectFrom", redirectFrom.get());
value = allowedOrigins.get();
if(value!=null)
yaml.setEntry("allowedOrigins", value);
IKeyStoreConfiguration config = keyStoreConfiguration.get();
if(config!=null)
yaml.setEntry("keyStore", config.toYaml());
config = trustStoreConfiguration.get();
if(config!=null)
yaml.setEntry("trustStore", config.toYaml());
IAuthenticationConfiguration auth = authenticationConfiguration.get();
if(auth!=null)
yaml.setEntry("authentication", auth.toYaml());
return yaml;
}

}
12 changes: 12 additions & 0 deletions Server/src/main/java/prompto/config/IHttpConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import java.util.function.Supplier;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

import prompto.config.auth.IAuthenticationConfiguration;

public interface IHttpConfiguration {
Expand All @@ -25,6 +28,7 @@ public interface IHttpConfiguration {
IHttpConfiguration withTrustStoreConfiguration(IKeyStoreConfiguration config);
IHttpConfiguration withAuthenticationConfiguration(IAuthenticationConfiguration config);

YamlMapping toYaml() throws YamlException;

public static class Inline implements IHttpConfiguration {

Expand Down Expand Up @@ -91,8 +95,16 @@ public IHttpConfiguration withAuthenticationConfiguration(IAuthenticationConfigu
authenticationConfiguration = ()->config;
return this;
}

@Override
public YamlMapping toYaml() throws YamlException {
return null;
}

}





}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package prompto.config;


import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

public interface IKeyStoreConfiguration {

IKeyStoreFactoryConfiguration getKeyStoreFactoryConfiguration();
ISecretKeyConfiguration getSecretKeyConfiguration();
YamlMapping toYaml() throws YamlException;

}
15 changes: 14 additions & 1 deletion Server/src/main/java/prompto/config/KeyStoreConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package prompto.config;


import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

public class KeyStoreConfiguration implements IKeyStoreConfiguration {

Expand All @@ -19,4 +20,16 @@ public IKeyStoreFactoryConfiguration getKeyStoreFactoryConfiguration() {
public ISecretKeyConfiguration getSecretKeyConfiguration() {
return reader.readSecretKeyConfiguration("secretKey");
}

@Override
public YamlMapping toYaml() throws YamlException {
YamlMapping yaml = new YamlMapping();
IKeyStoreFactoryConfiguration provider = getKeyStoreFactoryConfiguration();
if(provider!=null)
yaml.setEntry("provider", provider.toYaml());
ISecretKeyConfiguration secretKey = getSecretKeyConfiguration();
if(secretKey!=null)
yaml.setEntry("secretKey", secretKey.toYaml());
return yaml;
}
}
18 changes: 18 additions & 0 deletions Server/src/main/java/prompto/config/ServerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.Map;
import java.util.function.Supplier;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

@SuppressWarnings("unchecked")
public class ServerConfiguration extends RuntimeConfiguration implements IServerConfiguration {

Expand Down Expand Up @@ -37,6 +40,21 @@ public <T extends IServerConfiguration> T withHttpConfiguration(IHttpConfigurati
this.httpConfiguration = ()->config;
return (T)this;
}

@Override
public YamlMapping toYaml() throws YamlException {
YamlMapping yaml = super.toYaml();
IHttpConfiguration http = httpConfiguration.get();
if(http!=null)
yaml.setEntry("http", http.toYaml());
String value = serverAboutToStartMethod.get();
if(value!=null)
yaml.setEntry("serverAboutToStart", value);
value = webSiteRoot.get();
if(value!=null)
yaml.setEntry("webSiteRoot", value);
return yaml;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.util.Collection;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;
import com.esotericsoftware.yamlbeans.document.YamlSequence;

import prompto.config.IConfigurationReader;
import prompto.config.auth.method.AuthenticationMethodConfiguration;
import prompto.config.auth.method.IAuthenticationMethodConfiguration;
Expand Down Expand Up @@ -50,5 +54,24 @@ private IAuthenticationMethodConfiguration readAuthenticationMethodConfiguration
else
return new AuthenticationMethodConfiguration(child);
}

@Override
public YamlMapping toYaml() throws YamlException {
YamlMapping yaml = new YamlMapping();
IAuthenticationSourceConfiguration source = authenticationSourceConfiguration.get();
if(source!=null)
yaml.setEntry("source", source.getAuthenticationSourceFactory().toYaml());
IAuthenticationMethodConfiguration method = authenticationMethodConfiguration.get();
if(method!=null)
yaml.setEntry("method", method.getAuthenticationMethodFactory().toYaml());
Collection<String> whiteList = reader.getArray("whiteList");
if(whiteList!=null) {
YamlSequence sequence = new YamlSequence();
for(String entry : whiteList)
sequence.addElement(entry);
yaml.setEntry("whiteList", sequence);
}
return yaml;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

import prompto.config.auth.method.IAuthenticationMethodConfiguration;
import prompto.config.auth.source.IAuthenticationSourceConfiguration;

Expand All @@ -18,6 +21,8 @@ public interface IAuthenticationConfiguration {
IAuthenticationConfiguration withAuthenticationSourceConfiguration(IAuthenticationSourceConfiguration config);
IAuthenticationConfiguration withWhiteList(Collection<String> whiteList);

YamlMapping toYaml() throws YamlException;

public static class Inline implements IAuthenticationConfiguration {

Supplier<IAuthenticationMethodConfiguration> authenticationMethodConfiguration = ()->null;
Expand Down Expand Up @@ -45,6 +50,11 @@ public IAuthenticationConfiguration withWhiteList(Collection<String> list) {
whiteList = ()->list;
return this;
}

@Override
public YamlMapping toYaml() throws YamlException {
return null;
}

}

Expand All @@ -53,4 +63,5 @@ public IAuthenticationConfiguration withWhiteList(Collection<String> list) {




}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import prompto.config.IStoreConfiguration;

import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.document.YamlMapping;

public interface IStoredAuthenticationSourceConfiguration extends IAuthenticationSourceConfiguration {

IStoreConfiguration getStoreConfiguration();
void toYaml(YamlMapping yaml) throws Throwable;
YamlMapping toYaml() throws YamlException;

}
Loading

0 comments on commit 07fc7d2

Please sign in to comment.