diff options
| author | Alex Schofield <git@ajschof.me> | 2025-02-18 22:50:57 +0000 |
|---|---|---|
| committer | Alex Schofield <git@ajschof.me> | 2025-02-18 22:50:57 +0000 |
| commit | 31d01d5efbccbf923e9131c0b67aa916be873e9e (patch) | |
| tree | d485fcd5c2826d031125a48313242712bb8fd4b8 /obfuscator | |
| parent | 6e8c602b7cce9244e66fb0056eeba5e6ab697e6a (diff) | |
| download | gdpr-obfuscator-31d01d5efbccbf923e9131c0b67aa916be873e9e.tar.gz gdpr-obfuscator-31d01d5efbccbf923e9131c0b67aa916be873e9e.zip | |
change boto3 endpoint if debug mode is enabled
should this go here in 'production' code, even though it's a
testing tool? this may be changed in the near future. i've just
got a gut feeling that this might not be right.
Diffstat (limited to 'obfuscator')
| -rw-r--r-- | obfuscator/csv_reader.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/obfuscator/csv_reader.py b/obfuscator/csv_reader.py index c777998..8f4ebea 100644 --- a/obfuscator/csv_reader.py +++ b/obfuscator/csv_reader.py @@ -1,6 +1,7 @@ import csv import io import boto3 +import os from typing import List, Dict from obfuscator.logger import get_logger from obfuscator.utils import get_s3_path @@ -52,7 +53,19 @@ class CSVReader: bucket, key = get_s3_path(path) logger.debug(f"Reading S3 CSV from: {bucket}/{key}") - client = boto3.client("s3") + # If DEBUG=TRUE, use the localstack endpoint for testing + if os.getenv("DEBUG", "FALSE").upper() == "TRUE": + localstack_endpoint = "http://localhost.localstack.cloud:4566" + logger.debug("Using LocalStack endpoint for S3") + client = boto3.client( + "s3", + endpoint_url=localstack_endpoint, + aws_access_key_id="dummy", + aws_secret_access_key="dummy", + ) + logger.debug(f"endpoint_url: {localstack_endpoint}") + else: + client = boto3.client("s3") try: # Attempt to read the S3 object and return the data as a list of dictionaries |
