Skip to content

Commit

Permalink
Merge pull request #92 from schireson/dc/s3-stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCardin authored Apr 21, 2023
2 parents 39984fc + 4d3d978 commit 8ed8cdd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "databudgie"
version = "2.7.3"
version = "2.7.4"
packages = [
{ include = "databudgie", from = "src" },
]
Expand Down Expand Up @@ -42,6 +42,12 @@ sentry-sdk = { version = "*", optional = true }
psycopg2 = { version = ">=2.7", optional = true }
psycopg2-binary = { version = ">=2.7", optional = true }

[tool.poetry.extras]
sentry = ["sentry-sdk"]
s3 = ["boto3"]
psycopg2 = ["psycopg2"]
psycopg2-binary = ["psycopg2-binary"]

[tool.poetry.dev-dependencies]
boto3 = "^1.16.10,<1.17.72"
black = "22.3.0"
Expand All @@ -60,12 +66,6 @@ moto = {extras = ["s3"], version = "^2.2.6"}
sqlalchemy-model-factory = "^0.4.5"
types-click = "^7.1.5"

[tool.poetry.extras]
sentry = ["sentry-sdk"]
s3 = ["boto3"]
psycopg2 = ["psycopg2"]
psycopg2-binary = ["psycopg2-binary"]

[tool.black]
line_length = 120

Expand Down
19 changes: 11 additions & 8 deletions src/databudgie/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,28 @@


def optional_s3_resource(config: BackupConfig | RestoreConfig) -> S3ServiceResource | None:
if config_uses_s3(config) and config.s3:
if config_uses_s3(config):
return s3_resource(config.s3)
return None


def s3_resource(config: S3Config) -> S3ServiceResource:
def s3_resource(config: S3Config | None = None) -> S3ServiceResource:
try:
import boto3
except ImportError:
raise RuntimeError('Use of S3 requires the "s3" python extra')

# Boto loads all config as environment variables by default, this config
# section can be entirely optional.
session = boto3.session.Session(
aws_access_key_id=config.aws_access_key_id,
aws_secret_access_key=config.aws_secret_access_key,
profile_name=config.profile,
region_name=config.region,
)
if not config:
session = boto3.session.Session()
else:
session = boto3.session.Session(
aws_access_key_id=config.aws_access_key_id,
aws_secret_access_key=config.aws_secret_access_key,
profile_name=config.profile,
region_name=config.region,
)

s3: S3ServiceResource = session.resource("s3")
return s3
Expand Down
1 change: 0 additions & 1 deletion src/databudgie/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ def write_buffer(
# `name` is primarily omitted for things spanning individual tables, like schemas.
if name and self.manifest and file_type == FileTypes.data:
self.manifest.record(name, filename)
print(filename)

return filename

Expand Down

0 comments on commit 8ed8cdd

Please sign in to comment.