diff --git a/src/obs3dian/main.py b/src/obs3dian/main.py index 87e6653..ac345dc 100644 --- a/src/obs3dian/main.py +++ b/src/obs3dian/main.py @@ -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 @@ -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: @@ -189,7 +188,6 @@ def run( """ configs: Configuration = load_configs() - apply(usekey) # run apply typer.echo("") # new line diff --git a/src/obs3dian/s3.py b/src/obs3dian/s3.py index ea8087b..8e46960 100644 --- a/src/obs3dian/s3.py +++ b/src/obs3dian/s3.py @@ -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 diff --git a/src/test/test_run.py b/src/test/test_run.py index 2b137fb..1981d74 100644 --- a/src/test/test_run.py +++ b/src/test/test_run.py @@ -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