Skip to content

Commit 96d3df0

Browse files
committed
lazyload base64
1 parent b922ee6 commit 96d3df0

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

datadog_lambda/api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import logging
3-
import base64
43

54
logger = logging.getLogger(__name__)
65
KMS_ENCRYPTION_CONTEXT_KEY = "LambdaFunctionName"
@@ -9,6 +8,7 @@
98

109
def decrypt_kms_api_key(kms_client, ciphertext):
1110
from botocore.exceptions import ClientError
11+
import base64
1212

1313
"""
1414
Decodes and deciphers the base64-encoded ciphertext given as a parameter using KMS.

datadog_lambda/tracing.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Copyright 2019 Datadog, Inc.
55
import logging
66
import os
7-
import base64
87
import traceback
98
import ujson as json
109
from datetime import datetime, timezone
@@ -258,6 +257,8 @@ def extract_context_from_sqs_or_sns_event_or_context(event, lambda_context):
258257
dd_json_data = None
259258
dd_json_data_type = dd_payload.get("Type") or dd_payload.get("dataType")
260259
if dd_json_data_type == "Binary":
260+
import base64
261+
261262
dd_json_data = dd_payload.get("binaryValue") or dd_payload.get("Value")
262263
if dd_json_data:
263264
dd_json_data = base64.b64decode(dd_json_data)
@@ -372,6 +373,8 @@ def extract_context_from_kinesis_event(event, lambda_context):
372373
return extract_context_from_lambda_context(lambda_context)
373374
data = kinesis.get("data")
374375
if data:
376+
import base64
377+
375378
b64_bytes = data.encode("ascii")
376379
str_bytes = base64.b64decode(b64_bytes)
377380
data_str = str_bytes.decode("ascii")
@@ -552,6 +555,8 @@ def get_injected_authorizer_data(event, is_http_api) -> dict:
552555
if not dd_data_raw:
553556
return None
554557

558+
import base64
559+
555560
injected_data = json.loads(base64.b64decode(dd_data_raw))
556561

557562
# Lambda authorizer's results can be cached. But the payload will still have the injected

datadog_lambda/trigger.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# This product includes software developed at Datadog (https://www.datadoghq.com/).
44
# Copyright 2019 Datadog, Inc.
55

6-
import base64
76
import gzip
87
import ujson as json
98
from io import BytesIO, BufferedReader
@@ -242,6 +241,8 @@ def parse_event_source_arn(source: _EventSource, event: dict, context: Any) -> s
242241

243242
# e.g. arn:aws:logs:us-west-1:123456789012:log-group:/my-log-group-xyz
244243
if source.event_type == EventTypes.CLOUDWATCH_LOGS:
244+
import base64
245+
245246
with gzip.GzipFile(
246247
fileobj=BytesIO(base64.b64decode(event.get("awslogs", {}).get("data")))
247248
) as decompress_stream:

datadog_lambda/wrapper.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# under the Apache License Version 2.0.
33
# This product includes software developed at Datadog (https://www.datadoghq.com/).
44
# Copyright 2019 Datadog, Inc.
5-
import base64
65
import os
76
import logging
87
import traceback
@@ -273,6 +272,9 @@ def _inject_authorizer_span_headers(self, request_id):
273272
injected_headers[Headers.Parent_Span_Finish_Time] = finish_time_ns
274273
if request_id is not None:
275274
injected_headers[Headers.Authorizing_Request_Id] = request_id
275+
276+
import base64
277+
276278
datadog_data = base64.b64encode(
277279
json.dumps(injected_headers, escape_forward_slashes=False).encode()
278280
).decode()

0 commit comments

Comments
 (0)