diff --git a/README.md b/README.md index 3c3e345f..ad1e5a14 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Configure AWS CLI with your credentials as shown here - https://docs.aws.amazon. "gdk_version": "1.0.0" } ``` - 2. Replace `` with your name, `` with a s3 bucket name and `` with an aws region. + 2. Replace `` with your name, `` with a prefix for an Amazon S3 bucket name and `` with an AWS region. The specified bucket will be created in the specified region if it doesn't exist (name format: `{PLACEHOLDER_BUCKET}-{PLACEHOLDER_REGION}-{account_number}`). 3. After replace these value the `gdk-config.json` file should look similar to: ```json { diff --git a/gdk/aws_clients/S3Client.py b/gdk/aws_clients/S3Client.py index 729310dd..7623b004 100644 --- a/gdk/aws_clients/S3Client.py +++ b/gdk/aws_clients/S3Client.py @@ -84,10 +84,10 @@ def valid_bucket_for_artifacts_exists(self, bucket, region) -> bool: ) except ClientError as exc: error_code = exc.response["Error"]["Code"] - if error_code != "403" and error_code != "404": + if error_code != "AccessDenied" and error_code != "NoSuchBucket": logging.error("Could not verify if the bucket '%s' exists in the region '%s'.", bucket, region) raise - elif error_code == "403": + elif error_code == "AccessDenied": logging.error( "Bucket '%s' already exists and is not owned by you. Please provide a different name for the" " bucket in the configuration.", diff --git a/gdk/common/CaseInsensitive.py b/gdk/common/CaseInsensitive.py index c6bd5e36..1cd00c5f 100644 --- a/gdk/common/CaseInsensitive.py +++ b/gdk/common/CaseInsensitive.py @@ -1,7 +1,7 @@ import json -import yaml from pathlib import Path +import yaml from requests.structures import CaseInsensitiveDict as _CaseInsensitiveDict @@ -27,7 +27,9 @@ def _convert_nested_dict(self, case_insensitive_dict: _CaseInsensitiveDict) -> N if isinstance(value, dict): case_insensitive_dict.update({key: CaseInsensitiveDict(value)}) elif isinstance(value, list): - case_insensitive_dict.update({key: [CaseInsensitiveDict(val) for val in value if isinstance(val, dict)]}) + case_insensitive_dict.update( + {key: [CaseInsensitiveDict(val) if isinstance(val, dict) else val for val in value]} + ) def _convert_nested_case_insensitive_dict(self, dictObj: dict) -> dict: for key, value in dictObj.items(): @@ -38,8 +40,9 @@ def _convert_nested_case_insensitive_dict(self, dictObj: dict) -> dict: { key: [ self._convert_nested_case_insensitive_dict(dict(val)) - for val in value if isinstance(val, CaseInsensitiveDict) + else val + for val in value ] } ) diff --git a/tests/gdk/aws_clients/test_S3Client.py b/tests/gdk/aws_clients/test_S3Client.py index d01da4ba..5194ceb0 100644 --- a/tests/gdk/aws_clients/test_S3Client.py +++ b/tests/gdk/aws_clients/test_S3Client.py @@ -135,7 +135,7 @@ def test_valid_bucket_for_artifacts_exists_owned_by_someone(self): def throw_err(*args, **kwargs): ex = boto3.client("s3").exceptions.ClientError( - {"Error": {"Code": "403", "Message": "Forbidden"}}, "GetBucketLocation" + {"Error": {"Code": "AccessDenied", "Message": "Forbidden"}}, "GetBucketLocation" ) raise ex @@ -146,7 +146,7 @@ def throw_err(*args, **kwargs): s3_client_utils.valid_bucket_for_artifacts_exists(bucket, region) assert mock_get_bucket_location.call_args_list == [call(Bucket=bucket)] - assert "An error occurred (403) when calling the GetBucketLocation" in str(e.value.args[0]) + assert "An error occurred (AccessDenied) when calling the GetBucketLocation" in str(e.value.args[0]) def test_valid_bucket_for_artifacts_exists_not_exists(self): bucket = "test-bucket" @@ -154,7 +154,7 @@ def test_valid_bucket_for_artifacts_exists_not_exists(self): def throw_err(*args, **kwargs): ex = boto3.client("s3").exceptions.ClientError( - {"Error": {"Code": "404", "Message": "Not Found"}}, "GetBucketLocation" + {"Error": {"Code": "NoSuchBucket", "Message": "Not Found"}}, "GetBucketLocation" ) raise ex diff --git a/tests/gdk/common/test_CaseInsensitive.py b/tests/gdk/common/test_CaseInsensitive.py index 95add4cf..22d29d88 100644 --- a/tests/gdk/common/test_CaseInsensitive.py +++ b/tests/gdk/common/test_CaseInsensitive.py @@ -1,11 +1,13 @@ +import json +import tempfile from pathlib import Path from unittest import TestCase -import tempfile + import pytest import yaml -from gdk.common.CaseInsensitive import CaseInsensitiveRecipeFile -import json -from gdk.common.CaseInsensitive import CaseInsensitiveDict + +from gdk.common.CaseInsensitive import (CaseInsensitiveDict, + CaseInsensitiveRecipeFile) class CaseInsensitiveRecipeFileTest(TestCase): @@ -79,11 +81,13 @@ def test_convert_dict_to_CaseInsensitiveDict(self): "key1": "value1", "key2": [{"key21": "value21"}, {"key22": "value22"}], "key3": {"key31": {"key311": "key312"}}, + "key4": ["entry1", "entry2"] } cis = CaseInsensitiveDict(dictionary) assert "KEY1" in cis assert cis["KEY2"][0]["KEy21"] == "value21" assert cis["KEy3"]["key31"]["KeY311"] == "key312" + assert len(cis["key4"]) == 2 assert cis.to_dict() == dictionary def test_when_update_value_then_key_not_changed(self): diff --git a/tests/gdk/static/project_utils/valid_component_recipe.json b/tests/gdk/static/project_utils/valid_component_recipe.json index d5dff772..3dc317c2 100644 --- a/tests/gdk/static/project_utils/valid_component_recipe.json +++ b/tests/gdk/static/project_utils/valid_component_recipe.json @@ -6,7 +6,35 @@ "ComponentPublisher": "Amazon", "ComponentConfiguration": { "DefaultConfiguration": { - "Message": "world" + "Message": "world", + "SampleList": [ + "1", + "2", + "3" + ], + "SampleNestedList": [ + [ + "1" + ], + [ + "2" + ], + [ + "3" + ] + ], + "SampleMap": { + "key1": "value1", + "key2": { + "key3": [ + "value2", + "value3" + ], + "key4": { + "key41": "value4" + } + } + } } }, "Manifests": [ diff --git a/tests/gdk/static/project_utils/valid_component_recipe.yaml b/tests/gdk/static/project_utils/valid_component_recipe.yaml index 35e0525a..ddc93ed3 100644 --- a/tests/gdk/static/project_utils/valid_component_recipe.yaml +++ b/tests/gdk/static/project_utils/valid_component_recipe.yaml @@ -7,6 +7,22 @@ ComponentPublisher: Amazon ComponentConfiguration: DefaultConfiguration: Message: world + SampleList: + - '1' + - '2' + - '3' + SampleNestedList: + - - '1' + - - '2' + - - '3' + SampleMap: + key1: value1 + key2: + key3: + - value2 + - value3 + key4: + key41: value4 Manifests: - Platform: os: linux