sync
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 57s

This commit is contained in:
2025-12-15 08:14:41 -08:00
parent b602f4bb4f
commit 190371b099

View File

@@ -148,10 +148,19 @@ class ConfigManager:
logger.info("No configuration found in Consul at key: %s", full_config_key) logger.info("No configuration found in Consul at key: %s", full_config_key)
return return
# Value is base64 encoded JSON # Value from Consul might be raw bytes of the JSON, or it might be base64 encoded.
encoded_value = data['Value'] # We'll try to decode directly first, and fall back to base64.
logger.debug(f"Consul raw value type: {type(encoded_value)}, value: {encoded_value[:50]}...") # Log type and first 50 chars raw_value_from_consul = data['Value'] # This should be bytes
logger.debug(f"Consul encoded value: {encoded_value}") logger.debug(f"Consul raw value type: {type(raw_value_from_consul)}, value (first 100 bytes): {raw_value_from_consul[:100]}...")
try:
# Attempt 1: Assume the value is the direct UTF-8 bytes of the JSON string.
decoded_json_str = raw_value_from_consul.decode('utf-8')
logger.info("Successfully decoded Consul value directly as UTF-8.")
except UnicodeDecodeError:
logger.warning("Direct UTF-8 decoding failed. Falling back to base64 decoding.")
# Attempt 2: Assume the value is base64 encoded.
encoded_value = raw_value_from_consul
# Add padding if necessary for base64 decoding # Add padding if necessary for base64 decoding
padding_needed = len(encoded_value) % 4 padding_needed = len(encoded_value) % 4
@@ -159,7 +168,9 @@ class ConfigManager:
encoded_value += b'=' * (4 - padding_needed) encoded_value += b'=' * (4 - padding_needed)
decoded_json_str = base64.b64decode(encoded_value).decode('utf-8') decoded_json_str = base64.b64decode(encoded_value).decode('utf-8')
logger.debug(f"Consul decoded JSON string: {decoded_json_str}") logger.info("Successfully decoded Consul value using base64 fallback.")
logger.debug(f"Decoded JSON string: {decoded_json_str}")
consul_conf = json.loads(decoded_json_str) # Parse the JSON consul_conf = json.loads(decoded_json_str) # Parse the JSON
logger.debug(f"Consul parsed config (dict): {consul_conf}") logger.debug(f"Consul parsed config (dict): {consul_conf}")