aboutsummaryrefslogtreecommitdiffstats
path: root/obfuscator
diff options
context:
space:
mode:
authorAlex Schofield <git@ajschof.me>2025-02-18 22:38:48 +0000
committerAlex Schofield <git@ajschof.me>2025-02-18 22:38:48 +0000
commit6e8c602b7cce9244e66fb0056eeba5e6ab697e6a (patch)
treeddf08ed12361bf25385ee4261406d5aea64b97d0 /obfuscator
parent5875763f8e384a50004c4dd8ea08598d68f251ed (diff)
downloadgdpr-obfuscator-6e8c602b7cce9244e66fb0056eeba5e6ab697e6a.tar.gz
gdpr-obfuscator-6e8c602b7cce9244e66fb0056eeba5e6ab697e6a.zip
add untested read_s3 logic to CSVReader
Diffstat (limited to 'obfuscator')
-rw-r--r--obfuscator/csv_reader.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/obfuscator/csv_reader.py b/obfuscator/csv_reader.py
index 578b96b..c777998 100644
--- a/obfuscator/csv_reader.py
+++ b/obfuscator/csv_reader.py
@@ -1,5 +1,6 @@
import csv
import io
+import boto3
from typing import List, Dict
from obfuscator.logger import get_logger
from obfuscator.utils import get_s3_path
@@ -48,10 +49,25 @@ class CSVReader:
A method to read an S3 object containing CSV data
and return the data as a list of dictionaries.
"""
- # Yet to be implemented.
bucket, key = get_s3_path(path)
logger.debug(f"Reading S3 CSV from: {bucket}/{key}")
+ client = boto3.client("s3")
+
+ try:
+ # Attempt to read the S3 object and return the data as a list of dictionaries
+ response = client.get_object(Bucket=bucket, Key=key)
+ logger.info("S3 object read successfully")
+ # Read and decode the content
+ content = response["Body"].read().decode("utf-8")
+ # Even though the read_string method was only created for testing,
+ # it can be reused here to read and return the CSV data
+ return CSVReader.read_string(content)
+ # TODO: Add more specific exceptions to catch
+ except Exception as e:
+ logger.error(f"Error reading S3 object: {e}")
+ raise
+
@staticmethod
def read_string(content: str) -> List[Dict[str, str]]:
"""
git.ajschof.me — hosted by ajschofield — powered by cgit