Skip to content

Commit

Permalink
[FX-45] adds option to download libs without credentials (#110)
Browse files Browse the repository at this point in the history
* adds option to download libs without credentials

* Bumps version.

---------

Co-authored-by: Jared <jcoughlin@dephy.com>
Co-authored-by: Jared Coughlin <30010597+jcoughlin11@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 14, 2023
1 parent 9473109 commit 3d2179b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion flexsea/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "10.1.8"
__version__ = "10.1.9"
30 changes: 19 additions & 11 deletions flexsea/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import boto3
import botocore.exceptions as bce
from botocore.client import BaseClient
from botocore.handlers import disable_signing
from serial.tools.list_ports import comports

import flexsea.enums as fxe
Expand Down Expand Up @@ -161,7 +162,7 @@ def load_clib(
# ============================================
# download
# ============================================
def download(fileObj: str, bucket: str, dest: str, profile: str = "dephy") -> None:
def download(fileObj: str, bucket: str, dest: str, profile: str | None = None) -> None:
"""
Downloads `fileObj` from `bucket` to `dest` with the AWS
credentials profile `profile`.
Expand All @@ -178,19 +179,26 @@ def download(fileObj: str, bucket: str, dest: str, profile: str = "dephy") -> No
AssertionError
If the download fails.
"""
try:
session = boto3.Session(profile_name=profile)
except bce.ProfileNotFound as err:
raise err

try:
client = session.client("s3")
except bce.PartialCredentialsError as err:
raise err
if profile is None:
resource = boto3.resource("s3")
resource.meta.client.meta.events.register("choose-signer.s3.*", disable_signing)
bucket = resource.Bucket(bucket)
bucket.download_file(fileObj, dest)
else:
try:
session = boto3.Session(profile_name=profile)
except bce.ProfileNotFound as err:
raise err

client.download_file(bucket, fileObj, dest)
try:
client = session.client("s3")
except bce.PartialCredentialsError as err:
raise err

_validate_download(client, bucket, fileObj, dest)
client.download_file(bucket, fileObj, dest)
# TODO(CA): Make validate download work when no profile is given
_validate_download(client, bucket, fileObj, dest)


# ============================================
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "flexsea"
version = "10.1.8"
version = "10.1.9"
description = "Python API to interact with Dephy devices."
authors = ["Jared <jcoughlin@dephy.com>", "Carlos <casmat@dephy.com>"]
readme = "README.md"
Expand Down

0 comments on commit 3d2179b

Please sign in to comment.