Skip to content

Commit

Permalink
chore: allow checking http fullnodes (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
luislhl authored Jun 28, 2024
1 parent d6ea5c6 commit 7ad42c9
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ AWS_SUBNET_ID_3=subnet3
API_PORT=3001
LAMBDA_INVOKE_URL=http://explorer-service:3002/
DATA_AGGREGATOR_LAMBDA_NAME=hathor-explorer-service-dev-node_data_aggregator_handler
HATHOR_CORE_DOMAIN=node.explorer.testnet.hathor.network
HATHOR_NODES=node.explorer.testnet.hathor.network
HATHOR_CORE_URL=https://node.explorer.testnet.hathor.network
HATHOR_NODES=https://node.explorer.testnet.hathor.network
REDIS_KEY_PREFIX=hathor-explorer-service-dev
REDIS_HOST=redis
REDIS_PORT=6379
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ jobs:
make deploy-lambdas-ci stage=dev
env:
API_PORT: 3001
HATHOR_CORE_DOMAIN: node.explorer.testnet.hathor.network
HATHOR_NODES: node1.testnet.hathor.network,node.explorer.testnet.hathor.network
HATHOR_CORE_URL: https://node.explorer.testnet.hathor.network
HATHOR_NODES: https://node1.testnet.hathor.network,https://node.explorer.testnet.hathor.network
REDIS_KEY_PREFIX: hathor-explorer-service-dev
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: 6379
Expand All @@ -112,8 +112,8 @@ jobs:
make deploy-lambdas-ci stage=testnet
env:
API_PORT: 3001
HATHOR_CORE_DOMAIN: node.explorer.testnet.hathor.network
HATHOR_NODES: node1.testnet.hathor.network,node.explorer.testnet.hathor.network
HATHOR_CORE_URL: https://node.explorer.testnet.hathor.network
HATHOR_NODES: https://node1.testnet.hathor.network,https://node.explorer.testnet.hathor.network
REDIS_KEY_PREFIX: hathor-explorer-service-testnet
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: 6379
Expand All @@ -134,8 +134,8 @@ jobs:
make deploy-lambdas-ci stage=mainnet
env:
API_PORT: 3001
HATHOR_CORE_DOMAIN: node.explorer.hathor.network
HATHOR_NODES: node.explorer.hathor.network,node1.mainnet.hathor.network,node2.mainnet.hathor.network
HATHOR_CORE_URL: https://node.explorer.hathor.network
HATHOR_NODES: https://node.explorer.hathor.network,https://node1.mainnet.hathor.network,https://node2.mainnet.hathor.network
REDIS_KEY_PREFIX: hathor-explorer-service-mainnet
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: 6379
Expand Down
2 changes: 1 addition & 1 deletion common/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def default(cls) -> "LogRenderer":

DATA_AGGREGATOR_LAMBDA_NAME = config("DATA_AGGREGATOR_LAMBDA_NAME", default=None)

HATHOR_CORE_DOMAIN = config("HATHOR_CORE_DOMAIN", default=None)
HATHOR_CORE_URL = config("HATHOR_CORE_URL", default=None)

HATHOR_NODES = config("HATHOR_NODES", default="", cast=Csv())
NODE_CACHE_TTL = config("NODE_CACHE_TTL", default=30)
Expand Down
26 changes: 13 additions & 13 deletions gateways/clients/hathor_core_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import aiohttp
import requests

from common.configuration import HATHOR_CORE_DOMAIN
from common.configuration import HATHOR_CORE_URL
from common.errors import HathorCoreTimeout
from common.logging import get_logger

Expand Down Expand Up @@ -33,13 +33,13 @@
class HathorCoreAsyncClient:
DEFAULT_TIMEOUT = 60 # seconds

def __init__(self, domain: Optional[str] = None) -> None:
def __init__(self, url: Optional[str] = None) -> None:
"""Client to make async requests
:param domain: domain where the requests will be made, defaults to config `hathor_core_domain`
:type domain: str, optional
:param url: url where the requests will be made, defaults to config `hathor_core_url`
:type url: str, optional
"""
self.domain = domain or HATHOR_CORE_DOMAIN
self.url = url or HATHOR_CORE_URL
self.log = logger.new(client="async")

async def get(
Expand All @@ -54,7 +54,7 @@ async def get(
:param timeout: timeout in seconds
:type timeout: Optional[float]
"""
url = parse.urljoin(f"https://{self.domain}", path)
url = parse.urljoin(self.url, path)

if not timeout:
timeout = self.DEFAULT_TIMEOUT
Expand Down Expand Up @@ -88,7 +88,7 @@ async def post(
:param timeout: timeout in seconds
:type timeout: Optional[float]
"""
url = parse.urljoin(f"https://{self.domain}", path)
url = parse.urljoin(self.url, path)

if not timeout:
timeout = self.DEFAULT_TIMEOUT
Expand All @@ -114,12 +114,12 @@ async def post(
class HathorCoreClient:
"""Client to make requests
:param domain: domain where the requests will be made, defaults to config `hathor_core_domain`
:type domain: str, optional
:param url: url where the requests will be made, defaults to config `hathor_core_url`
:type url: str, optional
"""

def __init__(self, domain: Optional[str] = None) -> None:
self.domain = domain or HATHOR_CORE_DOMAIN
def __init__(self, url: Optional[str] = None) -> None:
self.url = url or HATHOR_CORE_URL
self.log = logger.new(client="sync")

def get_text(
Expand All @@ -136,7 +136,7 @@ def get_text(
:return: request response
:rtype: Optional[str]
"""
url = parse.urljoin(f"https://{self.domain}", path)
url = parse.urljoin(self.url, path)

try:
response = requests.get(url, params=params, **kwargs)
Expand Down Expand Up @@ -172,7 +172,7 @@ def post_text(
:return: request response
:rtype: Optional[str]
"""
url = parse.urljoin(f"https://{self.domain}", path)
url = parse.urljoin(self.url, path)

try:
response = requests.post(url, json=body, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ provider:
- ${env:AWS_SUBNET_ID_2}
- ${env:AWS_SUBNET_ID_3}
environment:
HATHOR_CORE_DOMAIN: ${env:HATHOR_CORE_DOMAIN}
HATHOR_CORE_URL: ${env:HATHOR_CORE_URL}
HATHOR_NODES: ${env:HATHOR_NODES}
REDIS_KEY_PREFIX: ${env:REDIS_KEY_PREFIX}
REDIS_HOST: ${env:REDIS_HOST}
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/gateways/clients/test_hathor_core_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_get_text(self, mocked_get):
expected = json.dumps({"success": True})
mocked_get.return_value.text = expected

client = HathorCoreClient("mydomain.com")
client = HathorCoreClient("https://mydomain.com")

result = client.get_text("/some/path", {"page": 2})

Expand All @@ -29,12 +29,12 @@ def test_get(self, mocked_get):
mocked_get.return_value.status_code = 200
mocked_get.return_value.text = json.dumps({"success": True})

client = HathorCoreClient("mydomain.com")
client = HathorCoreClient("http://mydomain.com")

result = client.get("/some/path", {"page": 2})

mocked_get.assert_called_once_with(
"https://mydomain.com/some/path", params={"page": 2}
"http://mydomain.com/some/path", params={"page": 2}
)
assert result
assert result["success"] is True
Expand All @@ -43,7 +43,7 @@ def test_get(self, mocked_get):
def test_get_no_200(self, mocked_get):
mocked_get.return_value.status_code = 404

client = HathorCoreClient("mydomain.com")
client = HathorCoreClient("https://mydomain.com")

result = client.get("/some/path", {"id": 42})

Expand All @@ -56,7 +56,7 @@ def test_get_no_200(self, mocked_get):
def test_get_raises(self, mocked_get):
mocked_get.side_effect = Exception("Boom!")

client = HathorCoreClient("mydomain.com")
client = HathorCoreClient("https://mydomain.com")

with raises(Exception, match=r"Boom!"):
result = client.get("/some/path", {"page": -12})
Expand All @@ -72,7 +72,7 @@ def test_get_raises(self, mocked_get):
def test_get_timeout(self, mocked_get):
mocked_get.side_effect = requests.ReadTimeout("reason")

client = HathorCoreClient("mydomain.com")
client = HathorCoreClient("https://mydomain.com")

with raises(Exception, match=r"timeout"):
client.get("/some/path", {"page": 69})
Expand Down

0 comments on commit 7ad42c9

Please sign in to comment.