solution: support Basic Auth
This commit is contained in:
@@ -15,7 +15,7 @@ springVersion=5.1.4.RELEASE
|
|||||||
reactorVersion=3.2.9.RELEASE
|
reactorVersion=3.2.9.RELEASE
|
||||||
|
|
||||||
# Our Libs
|
# Our Libs
|
||||||
etherjarVersion=0.7.0-SNAPSHOT
|
etherjarVersion=0.8.0-SNAPSHOT
|
||||||
|
|
||||||
# Testing
|
# Testing
|
||||||
spockVersion=1.2-groovy-2.5
|
spockVersion=1.2-groovy-2.5
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ class UpstreamsConfig {
|
|||||||
class EthereumConnection : UpstreamConnection() {
|
class EthereumConnection : UpstreamConnection() {
|
||||||
var rpc: HttpEndpoint? = null
|
var rpc: HttpEndpoint? = null
|
||||||
var ws: WsEndpoint? = null
|
var ws: WsEndpoint? = null
|
||||||
|
var auth: BasicAuth? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class HttpEndpoint(val url: URI) {
|
class HttpEndpoint(val url: URI) {
|
||||||
@@ -82,9 +83,10 @@ class UpstreamsConfig {
|
|||||||
var type: String? = null
|
var type: String? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
class BasicAuth : Auth() {
|
class BasicAuth(
|
||||||
var key: String? = null
|
val username: String,
|
||||||
}
|
val password: String
|
||||||
|
) : Auth()
|
||||||
|
|
||||||
class TlsAuth : Auth() {
|
class TlsAuth : Auth() {
|
||||||
var ca: String? = null
|
var ca: String? = null
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ class UpstreamsConfigReader {
|
|||||||
connection.rpc = http
|
connection.rpc = http
|
||||||
http.auth = readAuth(getMapping(node, "auth"))
|
http.auth = readAuth(getMapping(node, "auth"))
|
||||||
}
|
}
|
||||||
|
readAuth(getMapping(node, "auth"))?.let { auth ->
|
||||||
|
connection.auth = auth as UpstreamsConfig.BasicAuth
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getMapping(connConfigNode, "ws")?.let { node ->
|
getMapping(connConfigNode, "ws")?.let { node ->
|
||||||
getValueAsString(node, "url")?.let { url ->
|
getValueAsString(node, "url")?.let { url ->
|
||||||
@@ -129,9 +132,14 @@ class UpstreamsConfigReader {
|
|||||||
auth
|
auth
|
||||||
}
|
}
|
||||||
"basic" -> {
|
"basic" -> {
|
||||||
val auth = UpstreamsConfig.BasicAuth()
|
val username = getValueAsString(authNode, "username")
|
||||||
auth.key = getValueAsString(authNode, "key")
|
val password = getValueAsString(authNode, "password")
|
||||||
auth
|
if (username != null && password != null) {
|
||||||
|
UpstreamsConfig.BasicAuth(username, password)
|
||||||
|
} else {
|
||||||
|
log.warn("Basic auth is not fully configured")
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
log.warn("Invalid Auth type: $it")
|
log.warn("Invalid Auth type: $it")
|
||||||
|
|||||||
@@ -98,8 +98,13 @@ open class ConfiguredUpstreams(
|
|||||||
var wsApi: EthereumWs? = null
|
var wsApi: EthereumWs? = null
|
||||||
val urls = ArrayList<URI>()
|
val urls = ArrayList<URI>()
|
||||||
up.rpc?.let { endpoint ->
|
up.rpc?.let { endpoint ->
|
||||||
|
val rpcTransport = DefaultRpcTransport(endpoint.url)
|
||||||
|
up.auth?.let { auth ->
|
||||||
|
rpcTransport.setBasicAuth(auth.username, auth.password)
|
||||||
|
}
|
||||||
|
val rpcClient = DefaultRpcClient(rpcTransport)
|
||||||
rpcApi = EthereumApi(
|
rpcApi = EthereumApi(
|
||||||
DefaultRpcClient(DefaultRpcTransport(endpoint.url)),
|
rpcClient,
|
||||||
objectMapper,
|
objectMapper,
|
||||||
chain,
|
chain,
|
||||||
availableChains.targetFor(chain)
|
availableChains.targetFor(chain)
|
||||||
|
|||||||
@@ -40,9 +40,11 @@ class UpstreamsConfigReaderSpec extends Specification {
|
|||||||
connection instanceof UpstreamsConfig.EthereumConnection
|
connection instanceof UpstreamsConfig.EthereumConnection
|
||||||
with((UpstreamsConfig.EthereumConnection)connection) {
|
with((UpstreamsConfig.EthereumConnection)connection) {
|
||||||
rpc.url == new URI("https://mainnet.infura.io/v3/fa28c968191849c1aff541ad1d8511f2")
|
rpc.url == new URI("https://mainnet.infura.io/v3/fa28c968191849c1aff541ad1d8511f2")
|
||||||
|
rpc.auth != null
|
||||||
rpc.auth instanceof UpstreamsConfig.BasicAuth
|
rpc.auth instanceof UpstreamsConfig.BasicAuth
|
||||||
with((UpstreamsConfig.BasicAuth)rpc.auth) {
|
with((UpstreamsConfig.BasicAuth)rpc.auth) {
|
||||||
key == "4fc258fe41a68149c199ad8f281f2015"
|
username == "4fc258fe41a68149c199ad8f281f2015"
|
||||||
|
password == "1a68f20154fc258fe4149c199ad8f281"
|
||||||
}
|
}
|
||||||
ws == null
|
ws == null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,5 @@ upstreams:
|
|||||||
url: "https://mainnet.infura.io/v3/fa28c968191849c1aff541ad1d8511f2"
|
url: "https://mainnet.infura.io/v3/fa28c968191849c1aff541ad1d8511f2"
|
||||||
auth:
|
auth:
|
||||||
type: basic
|
type: basic
|
||||||
key: 4fc258fe41a68149c199ad8f281f2015
|
username: 4fc258fe41a68149c199ad8f281f2015
|
||||||
|
password: 1a68f20154fc258fe4149c199ad8f281
|
||||||
Reference in New Issue
Block a user