Skip to content

Commit bfebbd1

Browse files
authored
feat: Make it possible to specify RPC_URL via env var (#47)
1 parent 49ec3a3 commit bfebbd1

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def metrics_endpoint():
4747
config_file_path = os.getenv("CONFIG_FILE", "config.yml")
4848
config = config_loader.load_config(config_file_path)
4949

50-
rpc_url = config.rpc_url
50+
rpc_url = os.getenv("RPC_URL") or config.rpc_url
5151
graph_node_url = config.graph_node_url
5252
port = int(os.getenv("PORT", str(config.port)))
5353

deployment/job.nomad.hcl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ job "fluence-network-exporter" {
7474
env = true
7575
}
7676

77+
template {
78+
data = <<-EOH
79+
{{- with secret "kv/fluence-network-exporter/${var.region}/chain" -}}
80+
RPC_URL="{{ .Data.rpc_url }}"
81+
{{- end -}}
82+
EOH
83+
destination = "secrets/secret.env"
84+
env = true
85+
}
86+
7787
resources {
7888
cpu = 50
7989
memory = 128

deployment/job.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ resource "vault_policy" "fluence-network-exporter" {
2525
{
2626
capabilities = ["read"]
2727
}
28+
29+
path "kv/fluence-network-exporter/${local.region}/chain"
30+
{
31+
capabilities = ["read"]
32+
}
2833
EOH
2934
}
3035

network_metrics.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,34 @@
44
import threading
55
from config_loader import AddressEntry
66
import logging
7+
from urllib.parse import urlparse, urlunparse
78

89
# Set up logging
910
logger = logging.getLogger(__name__)
1011

1112

13+
def mask_secret(url: str) -> str:
14+
parsed = urlparse(url)
15+
if parsed.path and parsed.path != '/':
16+
masked_path = '/****'
17+
masked_url = urlunparse((parsed.scheme, parsed.netloc, masked_path, parsed.params, parsed.query, parsed.fragment))
18+
return masked_url
19+
return url
20+
21+
1222
def connect_rpc(url: str) -> Web3:
1323
"""Connect to RPC."""
24+
masked_url = mask_secret(url)
1425
try:
1526
web3 = Web3(Web3.HTTPProvider(url))
1627
if web3.is_connected():
17-
logger.info(f"Successfully connected to the RPC endpoint: {url}")
28+
logger.info(f"Successfully connected to the RPC endpoint: {masked_url}")
1829
return web3
1930
else:
2031
raise ConnectionError(
21-
f"Failed to connect to the RPC endpoint: {url}")
32+
f"Failed to connect to the RPC endpoint: {masked_url}")
2233
except Exception as e:
23-
logger.error(f"Error connecting to RPC endpoint {url}: {e}")
34+
logger.error(f"Error connecting to RPC endpoint {masked_url}: {e}")
2435
raise
2536

2637

0 commit comments

Comments
 (0)