Skip to content

Commit 5b6f52b

Browse files
committed
Add logging whenever patches happen for transparency
1 parent d48831d commit 5b6f52b

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

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

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def patched_make_cvat_cloud_storage_params(bucket_info: BucketAccessInfo) -> dic
3939
bucket_info.host_url = str(
4040
URL(original_host_url).copy_with(host=Config.development_config.cvat_local_host)
4141
)
42+
logger.info(
43+
f"DEV: Changed {original_host_url} to {bucket_info.host_url} for CVAT storage"
44+
)
4245
try:
4346
return original_make_cvat_cloud_storage_params(bucket_info)
4447
finally:
@@ -57,7 +60,9 @@ def prepare_signed_message(
5760
digest = hashlib.sha256(
5861
(escrow_address + ":".join(map(str, (chain_id, message, body)))).encode()
5962
).hexdigest()
60-
return None, f"{OracleWebhookTypes.recording_oracle}:{digest}"
63+
signature = f"{OracleWebhookTypes.recording_oracle}:{digest}"
64+
logger.info(f"DEV: Generated patched signature {signature}")
65+
return None, signature
6166

6267
src.utils.webhooks.prepare_signed_message = prepare_signed_message
6368

@@ -71,8 +76,9 @@ def prepare_signed_message(
7176
def get_local_escrow(chain_id: int, escrow_address: str) -> EscrowData:
7277
possible_manifest_name = escrow_address.split(":")[0]
7378
local_manifests = minio_client.list_files(bucket="manifests")
74-
logger.info(f"Local manifests: {local_manifests}")
79+
logger.info(f"DEV: Local manifests: {local_manifests}")
7580
if possible_manifest_name in local_manifests:
81+
logger.info(f"DEV: Using local manifest {escrow_address}")
7682
return EscrowData(
7783
chain_id=ChainId(chain_id),
7884
id="test",
@@ -104,7 +110,8 @@ async def lenient_validate_oracle_webhook_signature(request, signature, webhook)
104110
from src.validators.signature import validate_oracle_webhook_signature
105111

106112
try:
107-
return OracleWebhookTypes(signature.split(":")[0])
113+
parsed_type = OracleWebhookTypes(signature.split(":")[0])
114+
logger.info(f"DEV: Recovered {parsed_type} from the signature {signature}")
108115
except (ValueError, TypeError):
109116
return await validate_oracle_webhook_signature(request, signature, webhook)
110117

@@ -113,9 +120,22 @@ async def lenient_validate_oracle_webhook_signature(request, signature, webhook)
113120
src.endpoints.webhook.validate_oracle_webhook_signature = (
114121
lenient_validate_oracle_webhook_signature
115122
)
116-
import logging
117123

118-
logging.warning("Local development patches applied.")
124+
import src.endpoints.authentication
125+
126+
original_decode_token = src.endpoints.authentication.TokenAuthenticator._decode_token
127+
128+
def decode_plain_json_token(self, token) -> dict[str, Any]:
129+
"""
130+
Allows Authentication: Bearer {"wallet_address": "...", "email": "..."}
131+
"""
132+
try:
133+
decoded = json.loads(token)
134+
logger.info(f"DEV: Decoded plain JSON auth token: {decoded}")
135+
except (ValueError, TypeError):
136+
return original_decode_token(self, token)
137+
138+
src.endpoints.authentication.TokenAuthenticator._decode_token = decode_plain_json_token
119139

120140
from tests.api.test_exchange_api import generate_ecdsa_keys
121141

@@ -134,20 +154,7 @@ async def lenient_validate_oracle_webhook_signature(request, signature, webhook)
134154

135155
Config.human_app_config.jwt_public_key = public_key
136156

137-
import src.endpoints.authentication
138-
139-
original_decode_token = src.endpoints.authentication.TokenAuthenticator._decode_token
140-
141-
def decode_plain_json_token(self, token) -> dict[str, Any]:
142-
"""
143-
Allows Authentication: Bearer {"wallet_address": "...", "email": "..."}
144-
"""
145-
try:
146-
return json.loads(token)
147-
except (ValueError, TypeError):
148-
return original_decode_token(self, token)
149-
150-
src.endpoints.authentication.TokenAuthenticator._decode_token = decode_plain_json_token
157+
logger.warning("DEV: Local development patches applied.")
151158

152159

153160
if __name__ == "__main__":

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def apply_local_development_patches():
2323
- Replaces `src.validators.signature.validate_oracle_webhook_signature` to always return
2424
`OracleWebhookTypes.exchange_oracle`.
2525
"""
26+
logger = get_function_logger(apply_local_development_patches.__name__)
27+
2628
import src.crons._utils
2729

2830
def prepare_signed_message(
@@ -34,12 +36,12 @@ def prepare_signed_message(
3436
digest = hashlib.sha256(
3537
(escrow_address + ":".join(map(str, (chain_id, message, body)))).encode()
3638
).hexdigest()
37-
return None, f"{OracleWebhookTypes.recording_oracle}:{digest}"
39+
signature = f"{OracleWebhookTypes.recording_oracle}:{digest}"
40+
logger.info(f"DEV: Generated patched signature {signature}")
41+
return None, signature
3842

3943
src.crons._utils.prepare_signed_message = prepare_signed_message
4044

41-
logger = get_function_logger(apply_local_development_patches.__name__)
42-
4345
from human_protocol_sdk.constants import ChainId
4446
from human_protocol_sdk.escrow import EscrowData, EscrowUtils
4547

@@ -50,6 +52,7 @@ def get_local_escrow(chain_id: int, escrow_address: str) -> EscrowData:
5052
local_manifests = minio_client.list_files(bucket="manifests")
5153
logger.info(f"Local manifests: {local_manifests}")
5254
if possible_manifest_name in local_manifests:
55+
logger.info(f"DEV: Using local manifest {escrow_address}")
5356
return EscrowData(
5457
chain_id=ChainId(chain_id),
5558
id="test",
@@ -83,8 +86,10 @@ async def lenient_validate_oracle_webhook_signature(
8386
webhook, # noqa: ARG001 (not relevant here)
8487
):
8588
try:
86-
return OracleWebhookTypes(signature.split(":")[0])
89+
parsed_type = OracleWebhookTypes(signature.split(":")[0])
90+
logger.info(f"DEV: Recovered {parsed_type} from the signature {signature}")
8791
except (ValueError, TypeError):
92+
logger.info(f"DEV: Falling back to {OracleWebhookTypes.exchange_oracle} webhook sender")
8893
return OracleWebhookTypes.exchange_oracle
8994

9095
import src.endpoints.webhook

0 commit comments

Comments
 (0)