problem: reading yaml to both plain properties and structured objects is a mess

solution: use just objects for configs
This commit is contained in:
Igor Artamonov
2020-03-23 22:54:52 -04:00
parent d4bd180e23
commit 014461520e
37 changed files with 528 additions and 339 deletions

View File

@@ -31,7 +31,7 @@ class TlsSetupSpec extends Specification {
enabled: false
)
when:
def act = tlsSetup.setupServer("test", config)
def act = tlsSetup.setupServer("test", config, false)
then:
act == null
}
@@ -44,7 +44,7 @@ class TlsSetupSpec extends Specification {
key: "127.0.0.1.p8.key"
)
when:
def act = tlsSetup.setupServer("test", config)
def act = tlsSetup.setupServer("test", config, false)
then:
act != null
act.server
@@ -67,7 +67,7 @@ class TlsSetupSpec extends Specification {
clientCa: "ca.myhost.dev.crt"
)
when:
def act = tlsSetup.setupServer("test", config)
def act = tlsSetup.setupServer("test", config, false)
then:
act != null
act.server
@@ -87,7 +87,7 @@ class TlsSetupSpec extends Specification {
key: "127.0.0.1.p8.key",
)
when:
tlsSetup.setupServer("test", config)
tlsSetup.setupServer("test", config, false)
then:
def t = thrown(IllegalArgumentException)
t.message == "Certificate not set"
@@ -100,7 +100,7 @@ class TlsSetupSpec extends Specification {
certificate: "127.0.0.1.crt"
)
when:
tlsSetup.setupServer("test", config)
tlsSetup.setupServer("test", config, false)
then:
def t = thrown(IllegalArgumentException)
t.message == "Certificate Key not set"
@@ -114,7 +114,7 @@ class TlsSetupSpec extends Specification {
key: "127.0.0.1.p8.key",
)
when:
tlsSetup.setupServer("test", config)
tlsSetup.setupServer("test", config, false)
then:
def t = thrown(IllegalArgumentException)
}
@@ -127,7 +127,7 @@ class TlsSetupSpec extends Specification {
key: "none.p8.key",
)
when:
tlsSetup.setupServer("test", config)
tlsSetup.setupServer("test", config, false)
then:
def t = thrown(IllegalArgumentException)
}
@@ -140,7 +140,7 @@ class TlsSetupSpec extends Specification {
key: "127.0.0.1.key",
)
when:
tlsSetup.setupServer("test", config)
tlsSetup.setupServer("test", config, false)
then:
def t = thrown(IllegalArgumentException)
}
@@ -154,7 +154,7 @@ class TlsSetupSpec extends Specification {
clientRequire: true
)
when:
tlsSetup.setupServer("test", config)
tlsSetup.setupServer("test", config, false)
then:
def t = thrown(IllegalArgumentException)
}
@@ -169,7 +169,7 @@ class TlsSetupSpec extends Specification {
clientCa: "none.crt"
)
when:
tlsSetup.setupServer("test", config)
tlsSetup.setupServer("test", config, false)
then:
def t = thrown(IllegalArgumentException)
}
@@ -184,7 +184,7 @@ class TlsSetupSpec extends Specification {
clientCa: "ca.myhost.dev.key"
)
when:
tlsSetup.setupServer("test", config)
tlsSetup.setupServer("test", config, false)
then:
def t = thrown(IllegalArgumentException)
}

View File

@@ -0,0 +1,24 @@
package io.emeraldpay.dshackle.config
import spock.lang.Specification
class CacheConfigReaderSpec extends Specification {
CacheConfigReader reader = new CacheConfigReader()
def "Read full"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("cache-redis-full.yaml")
when:
def act = reader.read(config)
then:
act.redis != null
with(act.redis) {
host == "redis-master"
port == 1234
db == 5
password == "HelloWorld!1"
}
}
}

View File

@@ -0,0 +1,73 @@
package io.emeraldpay.dshackle.config
import io.emeraldpay.dshackle.FileResolver
import io.emeraldpay.dshackle.test.TestingCommons
import io.emeraldpay.grpc.Chain
import spock.lang.Specification
class MainConfigReaderSpec extends Specification {
MainConfigReader reader = new MainConfigReader(TestingCommons.fileResolver())
def "Read full config"() {
setup:
def config = this.class.getClassLoader().getResourceAsStream("dshackle-full.yaml")
when:
def act = reader.read(config)
then:
act != null
act.host == "192.168.1.101"
act.port == 2448
act.tls != null
with(act.tls) {
certificate == "/path/127.0.0.1.crt"
key == "/path/127.0.0.1.p8.key"
!clientRequire
clientCa == "/path/ca.dshackle.test.crt"
}
act.cache != null
with(act.cache) {
redis != null
redis.host == "redis-master"
}
act.proxy != null
with(act.proxy) {
port == 8082
tls != null
routes != null
routes.size() == 3
with(routes[0]) {
id == "eth"
blockchain == Chain.ETHEREUM
}
with(routes[1]) {
id == "etc"
blockchain == Chain.ETHEREUM_CLASSIC
}
with(routes[2]) {
id == "kovan"
blockchain == Chain.TESTNET_KOVAN
}
}
act.upstreams != null
with(act.upstreams) {
defaultOptions != null
defaultOptions.size() == 1
with(defaultOptions[0]) {
chains == ["ethereum"]
options.minPeers == 3
}
upstreams.size() == 3
with(upstreams[0]) {
id == "remote"
}
with(upstreams[1]) {
id == "local"
}
with(upstreams[2]) {
id == "infura"
}
}
}
}

View File

@@ -23,7 +23,7 @@ import spock.lang.Specification
class UpstreamsConfigReaderSpec extends Specification {
UpstreamsConfigReader reader = new UpstreamsConfigReader()
UpstreamsConfigReader reader = new UpstreamsConfigReader(TestingCommons.fileResolver())
def "Parse standard config"() {
setup:
@@ -32,7 +32,6 @@ class UpstreamsConfigReaderSpec extends Specification {
def act = reader.read(config)
then:
act != null
act.version == "v1"
with(act.defaultOptions) {
size() == 1
with(get(0)) {
@@ -81,7 +80,6 @@ class UpstreamsConfigReaderSpec extends Specification {
def act = reader.read(config)
then:
act != null
act.version == "v1"
act.upstreams.size() == 1
with(act.upstreams.get(0)) {
id == "remote"
@@ -141,7 +139,6 @@ class UpstreamsConfigReaderSpec extends Specification {
def act = reader.read(config)
then:
act != null
act.version == "v1"
with(act.defaultOptions) {
size() == 0
}

View File

@@ -22,6 +22,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule
import io.emeraldpay.dshackle.FileResolver
import io.emeraldpay.dshackle.cache.Caches
import io.emeraldpay.dshackle.cache.CachesFactory
import io.emeraldpay.dshackle.config.CacheConfig
import io.emeraldpay.dshackle.upstream.AggregatedUpstream
import io.emeraldpay.dshackle.upstream.ChainUpstreams
import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods
@@ -78,7 +79,7 @@ class TestingCommons {
}
static CachesFactory emptyCaches() {
return new CachesFactory(objectMapper(), new StandardEnvironment())
return new CachesFactory(objectMapper(), new CacheConfig())
}
static FileResolver fileResolver() {

View File

@@ -0,0 +1,7 @@
cache:
redis:
enabled: true
host: redis-master
port: 1234
db: 5
password: HelloWorld!1

View File

@@ -0,0 +1,66 @@
version: v1
host: 192.168.1.101
port: 2448
tls:
enabled: true
server:
certificate: "/path/127.0.0.1.crt"
key: "/path/127.0.0.1.p8.key"
client:
require: false
ca: "/path/ca.dshackle.test.crt"
cache:
redis:
enabled: true
host: redis-master
proxy:
port: 8082
tls:
enabled: true
server:
certificate: "/path/second/127.0.0.1.crt"
key: "/path/second/127.0.0.1.p8.key"
client:
require: false
ca: "/path/second/ca.dshackle.test.crt"
routes:
- id: eth
blockchain: ethereum
- id: etc
blockchain: ethereum_classic
- id: kovan
blockchain: kovan
upstreams:
defaults:
- chains:
- ethereum
options:
min-peers: 3
include:
- "upstreams-extra.yaml"
upstreams:
- id: local
chain: ethereum
connection:
ethereum:
rpc:
url: "http://localhost:8545"
ws:
url: "ws://localhost:8546"
origin: "http://localhost"
basic-auth:
username: 9c199ad8f281f20154fc258fe41a6814
password: 258fe4149c199ad8f2811a68f20154fc
- id: infura
chain: ethereum
connection:
ethereum:
rpc:
url: "https://mainnet.infura.io/v3/fa28c968191849c1aff541ad1d8511f2"
basic-auth:
username: 4fc258fe41a68149c199ad8f281f2015
password: 1a68f20154fc258fe4149c199ad8f281

View File

@@ -1,6 +1,6 @@
version: v1
defaultOptions:
defaults:
- chains:
- ethereum
options:

View File

@@ -0,0 +1,9 @@
upstreams:
- id: remote
connection:
grpc:
host: "10.2.0.15"
tls:
ca: /etc/ca.myservice.com.crt
certificate: /etc/client1.myservice.com.crt
key: /etc/client1.myservice.com.key