solution: configure rpc server TLS certificate
This commit is contained in:
@@ -67,11 +67,11 @@ class UpstreamsConfig {
|
||||
class EthereumConnection : UpstreamConnection() {
|
||||
var rpc: HttpEndpoint? = null
|
||||
var ws: WsEndpoint? = null
|
||||
var auth: BasicAuth? = null
|
||||
}
|
||||
|
||||
class HttpEndpoint(val url: URI) {
|
||||
var auth: Auth? = null
|
||||
var basicAuth: BasicAuth? = null
|
||||
var tls: TlsAuth? = null
|
||||
}
|
||||
|
||||
class WsEndpoint(val url: URI) {
|
||||
@@ -87,11 +87,11 @@ class UpstreamsConfig {
|
||||
val password: String
|
||||
) : Auth()
|
||||
|
||||
class TlsAuth : Auth() {
|
||||
var ca: String? = null
|
||||
var certificate: String? = null
|
||||
class TlsAuth(
|
||||
var ca: String? = null,
|
||||
var certificate: String? = null,
|
||||
var key: String? = null
|
||||
}
|
||||
) : Auth()
|
||||
|
||||
//TODO make it unmodifiable after initial load
|
||||
class Labels: HashMap<String, String>() {
|
||||
|
||||
@@ -49,10 +49,8 @@ class UpstreamsConfigReader {
|
||||
getValueAsString(node, "url")?.let { url ->
|
||||
val http = UpstreamsConfig.HttpEndpoint(URI(url))
|
||||
connection.rpc = http
|
||||
http.auth = readAuth(getMapping(node, "auth"))
|
||||
}
|
||||
readAuth(getMapping(node, "auth"))?.let { auth ->
|
||||
connection.auth = auth as UpstreamsConfig.BasicAuth
|
||||
http.basicAuth = readBasicAuth(node)
|
||||
http.tls = readTls(node)
|
||||
}
|
||||
}
|
||||
getMapping(connConfigNode, "ws")?.let { node ->
|
||||
@@ -79,7 +77,7 @@ class UpstreamsConfigReader {
|
||||
getValueAsInt(connConfigNode, "port")?.let {
|
||||
connection.port = it
|
||||
}
|
||||
connection.auth = readAuth(getMapping(connConfigNode, "auth")) as UpstreamsConfig.TlsAuth?
|
||||
connection.auth = readTls(connConfigNode)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,34 +135,29 @@ class UpstreamsConfigReader {
|
||||
return options
|
||||
}
|
||||
|
||||
private fun readAuth(authNode: MappingNode?): UpstreamsConfig.Auth? {
|
||||
return getValueAsString(authNode, "type")?.let {
|
||||
return when (it) {
|
||||
"tls" -> {
|
||||
val auth = UpstreamsConfig.TlsAuth()
|
||||
auth.ca = getValueAsString(authNode, "ca")
|
||||
auth.certificate = getValueAsString(authNode, "certificate")
|
||||
auth.key = getValueAsString(authNode, "key")
|
||||
auth
|
||||
}
|
||||
"basic" -> {
|
||||
val username = getValueAsString(authNode, "username")
|
||||
val password = getValueAsString(authNode, "password")
|
||||
if (username != null && password != null) {
|
||||
UpstreamsConfig.BasicAuth(username, password)
|
||||
} else {
|
||||
log.warn("Basic auth is not fully configured")
|
||||
null
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
log.warn("Invalid Auth type: $it")
|
||||
null
|
||||
}
|
||||
private fun readBasicAuth(node: MappingNode?): UpstreamsConfig.BasicAuth? {
|
||||
return getMapping(node, "basic-auth")?.let { authNode ->
|
||||
val username = getValueAsString(authNode, "username")
|
||||
val password = getValueAsString(authNode, "password")
|
||||
if (username != null && password != null) {
|
||||
UpstreamsConfig.BasicAuth(username, password)
|
||||
} else {
|
||||
log.warn("Basic auth is not fully configured")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun readTls(node: MappingNode?): UpstreamsConfig.TlsAuth? {
|
||||
return getMapping(node, "tls")?.let { authNode ->
|
||||
val auth = UpstreamsConfig.TlsAuth()
|
||||
auth.ca = getValueAsString(authNode, "ca")
|
||||
auth.certificate = getValueAsString(authNode, "certificate")
|
||||
auth.key = getValueAsString(authNode, "key")
|
||||
auth
|
||||
}
|
||||
}
|
||||
|
||||
private fun hasAny(mappingNode: MappingNode?, key: String): Boolean {
|
||||
if (mappingNode == null) {
|
||||
return false
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.springframework.scheduling.annotation.Scheduled
|
||||
import org.springframework.stereotype.Repository
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.TopicProcessor
|
||||
import reactor.core.publisher.toFlux
|
||||
import java.io.File
|
||||
import java.net.URI
|
||||
import java.util.*
|
||||
@@ -110,9 +109,14 @@ open class ConfiguredUpstreams(
|
||||
val urls = ArrayList<URI>()
|
||||
up.rpc?.let { endpoint ->
|
||||
val rpcTransport = DefaultRpcTransport(endpoint.url)
|
||||
up.auth?.let { auth ->
|
||||
up.rpc?.basicAuth?.let { auth ->
|
||||
rpcTransport.setBasicAuth(auth.username, auth.password)
|
||||
}
|
||||
up.rpc?.tls?.let { tls ->
|
||||
tls.ca?.let { ca ->
|
||||
File(ca).inputStream().use { cert -> rpcTransport.setTrustedCertificate(cert) }
|
||||
}
|
||||
}
|
||||
val rpcClient = DefaultRpcClient(rpcTransport)
|
||||
rpcApi = EthereumApi(
|
||||
rpcClient,
|
||||
|
||||
@@ -26,6 +26,7 @@ class UpstreamValidator(
|
||||
}
|
||||
return UpstreamAvailability.OK
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
return UpstreamAvailability.UNAVAILABLE
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user