Skip to content

Commit d48831d

Browse files
committed
[Exchange Oracle] Support host substitution for CVAT storage config
1 parent c880e18 commit d48831d

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

packages/examples/cvat/exchange-oracle/debug.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any
66

77
import uvicorn
8+
from httpx import URL
89

910
from src.chain.kvstore import register_in_kvstore
1011
from src.core.config import Config
@@ -25,7 +26,27 @@ def apply_local_development_patches():
2526
- Generates ECDSA keys if not already present for local JWT signing,
2627
and sets the public key in `Config.human_app_config`.
2728
"""
28-
import src.utils.webhooks
29+
import src.handlers.job_creation
30+
31+
original_make_cvat_cloud_storage_params = (
32+
src.handlers.job_creation._make_cvat_cloud_storage_params
33+
)
34+
35+
def patched_make_cvat_cloud_storage_params(bucket_info: BucketAccessInfo) -> dict:
36+
original_host_url = bucket_info.host_url
37+
38+
if Config.development_config.cvat_in_docker:
39+
bucket_info.host_url = str(
40+
URL(original_host_url).copy_with(host=Config.development_config.cvat_local_host)
41+
)
42+
try:
43+
return original_make_cvat_cloud_storage_params(bucket_info)
44+
finally:
45+
bucket_info.host_url = original_host_url
46+
47+
src.handlers.job_creation._make_cvat_cloud_storage_params = (
48+
patched_make_cvat_cloud_storage_params
49+
)
2950

3051
def prepare_signed_message(
3152
escrow_address,

packages/examples/cvat/exchange-oracle/src/.env.template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,7 @@ LOCALHOST_REPUTATION_ORACLE_URL=
121121
PGP_PRIVATE_KEY=
122122
PGP_PASSPHRASE=
123123
PGP_PUBLIC_KEY_URL=
124+
125+
126+
# Development
127+
DEV_CVAT_IN_DOCKER=

packages/examples/cvat/exchange-oracle/src/core/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ def _missing_(cls, value: str) -> Optional["Environment"]:
313313
return None
314314

315315

316+
class Development:
317+
cvat_in_docker = bool(int(os.environ.get("CVAT_IN_DOCKER", "0")))
318+
# might be `host.docker.internal` or `172.22.0.1` if CVAT is running in docker
319+
cvat_local_host = os.environ.get("CVAT_LOCAL_HOST", "localhost")
320+
321+
316322
class Config:
317323
debug = to_bool(os.environ.get("DEBUG", "false"))
318324
port = int(os.environ.get("PORT", 8000))
@@ -337,6 +343,7 @@ class Config:
337343
features = FeaturesConfig
338344
core_config = CoreConfig
339345
encryption_config = EncryptionConfig
346+
development_config = Development
340347

341348
@classmethod
342349
def is_development_mode(cls) -> bool:

0 commit comments

Comments
 (0)