Skip to content

Commit

Permalink
Add assertion error on wrong config
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkjin99 committed Mar 4, 2024
1 parent 9026b03 commit 795c1dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/obs3dian/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def apply(
typer.Option(
help="Use cli profile when connect to S3. If you want to connect by key uses --no-usekey"
),
] = True
] = False
):
"""
Apply settings from config.json file
Expand All @@ -86,7 +86,6 @@ def apply(
print("Bucket has public read access so anyone can see files in your bucket")
else:
print(f"Bucket {configs.bucket_name} is already exists try with other name")
return

if not output_folder_path.exists():
try:
Expand Down Expand Up @@ -189,7 +188,6 @@ def run(
"""

configs: Configuration = load_configs()

apply(usekey) # run apply
typer.echo("") # new line

Expand Down
22 changes: 11 additions & 11 deletions src/obs3dian/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def __init__(
) -> None:

if usekey:
if aws_access_key and aws_secret_key: # if user has cli profile
self.session = boto3.Session(
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key,
region_name="ap-northeast-2",
)

elif profile_name:
self.session = boto3.Session(profile_name=profile_name)

assert (
aws_access_key and aws_secret_key
), "AWS Key error" # if user has cli profile
self.session = boto3.Session(
aws_access_key_id=aws_access_key,
aws_secret_access_key=aws_secret_key,
region_name="ap-northeast-2",
)

else:
raise ValueError("AWS key is required")
assert profile_name, "AWS profile is required"
self.session = boto3.Session(profile_name=profile_name)

self.s3 = self.session.client("s3")
self.bucket_name = bucket_name
Expand Down
14 changes: 11 additions & 3 deletions src/test/test_run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import pytest
import pathlib
from obs3dian.main import run


class TestRun:
# test first init run
# test with profile
# test with access key
user_input_path = pathlib.Path("./test_files")

def test_by_profile_run(self):
# test by profile
run(user_input_path=self.user_input_path, overwrite=False, useprofile=True)

def test_by_keys(self):
# test with access key
run(user_input_path=self.user_input_path, overwrite=False, useprofile=False)

pass

0 comments on commit 795c1dc

Please sign in to comment.