Skip to content

Commit

Permalink
Merge pull request #3 from NERC-CEH/consistent-arg-names
Browse files Browse the repository at this point in the history
update arg names + readme
  • Loading branch information
nkshaw23 authored Oct 2, 2024
2 parents e112df8 + e618f91 commit 02a884e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ body = b"I'm a byte encoded document"
writer = S3Writer(client)

# Submit a file to AWS S3

object_bytes = reader.read(bucket="my-bucket", key="Path/to/file", body=body)
writer.wite(bucket="my-bucket", key="Path/to/file", body=body)
```

#### Reading/Writing Combo Class
Expand Down
8 changes: 4 additions & 4 deletions src/driutils/io/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ def __init__(self, s3_client: S3Client) -> None:
class S3Reader(S3Base, ReaderInterface):
"""Class for handling file reads using the AWS S3 client"""

def read(self, bucket_name: str, s3_key: str) -> bytes:
def read(self, bucket_name: str, key: str) -> bytes:
"""
Retrieves an object from an S3 bucket.
If any step fails, it logs an error and re-raises the exception.
Args:
bucket_name: The name of the S3 bucket.
s3_key: The key (path) of the object within the bucket.
key: The key (path) of the object within the bucket.
Returns:
bytes: raw bytes of the S3 object
Expand All @@ -48,10 +48,10 @@ def read(self, bucket_name: str, s3_key: str) -> bytes:
Exception: If there's any error in retrieving or parsing the object.
"""
try:
data = self._connection.get_object(Bucket=bucket_name, Key=s3_key)
data = self._connection.get_object(Bucket=bucket_name, Key=key)
return data["Body"].read()
except (RuntimeError, ClientError) as e:
logger.error(f"Failed to get {s3_key} from {bucket_name}")
logger.error(f"Failed to get {key} from {bucket_name}")
logger.exception(e)
raise e

Expand Down
4 changes: 2 additions & 2 deletions src/driutils/io/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _authenticate(self, method: str, endpoint_url: Optional[str] = None, use_ssl
def _auto_auth(self) -> None:
"""Automatically authenticates using environment variables"""
logger.info("Initalized DuckDB with 'auto' secret")

self._connection.install_extension("aws")
self._connection.load_extension("aws")
self._connection.execute("""
Expand All @@ -111,7 +111,7 @@ def _sts_auth(self) -> None:
"""Authenicates using assumed roles on AWS"""

logger.info("Initalized DuckDB with 'sts' secret")

self._connection.install_extension("aws")
self._connection.load_extension("aws")
self._connection.execute("""
Expand Down

0 comments on commit 02a884e

Please sign in to comment.