From a59420f00dd20f8ffaa7cf1983d679f912c375ee Mon Sep 17 00:00:00 2001 From: Matthias Veit Date: Fri, 2 Jun 2023 13:28:00 +0200 Subject: [PATCH] [aws][fix] AWS Artifacts are referenced by arn not name (#1630) --- .../resoto_plugin_aws/resource/sagemaker.py | 8 +++--- plugins/aws/test/collector_test.py | 4 +-- ...s_sagemaker_us_east_1_test_artifact_2.json | 25 +++++++++++++++++++ .../files/sagemaker/list-artifacts.json | 10 ++++++++ plugins/aws/test/resources/sagemaker_test.py | 2 +- 5 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 plugins/aws/test/resources/files/sagemaker/describe-artifact__arn_aws_sagemaker_us_east_1_test_artifact_2.json diff --git a/plugins/aws/resoto_plugin_aws/resource/sagemaker.py b/plugins/aws/resoto_plugin_aws/resource/sagemaker.py index 7408de51a..69dab8778 100644 --- a/plugins/aws/resoto_plugin_aws/resource/sagemaker.py +++ b/plugins/aws/resoto_plugin_aws/resource/sagemaker.py @@ -827,9 +827,11 @@ def called_collect_apis(cls) -> List[AwsApiSpec]: @classmethod def collect(cls: Type[AwsResource], json: List[Json], builder: GraphBuilder) -> None: - # TODO don't collect Apps with status "deleted" for app in json: - if app["UserProfileName"]: + # Don't collect Apps that are deleted + if app.get("AppStatus") == "Deleted": + continue + elif app["UserProfileName"]: app_description = builder.client.get( service_name, "describe-app", @@ -1922,7 +1924,7 @@ class AwsSagemakerArtifact(AwsResource): } api_spec: ClassVar[AwsApiSpec] = AwsApiSpec(service_name, "list-artifacts", "ArtifactSummaries") mapping: ClassVar[Dict[str, Bender]] = { - "id": S("ArtifactName"), + "id": S("ArtifactArn"), "name": S("ArtifactName"), "ctime": S("CreationTime"), "mtime": S("LastModifiedTime"), diff --git a/plugins/aws/test/collector_test.py b/plugins/aws/test/collector_test.py index ba1aa7de2..428310ebc 100644 --- a/plugins/aws/test/collector_test.py +++ b/plugins/aws/test/collector_test.py @@ -31,8 +31,8 @@ def count_kind(clazz: Type[AwsResource]) -> int: # make sure all threads have been joined assert len(threading.enumerate()) == 1 # ensure the correct number of nodes and edges - assert count_kind(AwsResource) == 204 - assert len(account_collector.graph.edges) == 476 + assert count_kind(AwsResource) == 205 + assert len(account_collector.graph.edges) == 477 assert len(account_collector.graph.deferred_edges) == 2 diff --git a/plugins/aws/test/resources/files/sagemaker/describe-artifact__arn_aws_sagemaker_us_east_1_test_artifact_2.json b/plugins/aws/test/resources/files/sagemaker/describe-artifact__arn_aws_sagemaker_us_east_1_test_artifact_2.json new file mode 100644 index 000000000..cd12dcf38 --- /dev/null +++ b/plugins/aws/test/resources/files/sagemaker/describe-artifact__arn_aws_sagemaker_us_east_1_test_artifact_2.json @@ -0,0 +1,25 @@ +{ + "ArtifactArn": "arn:aws:sagemaker:us-east-1:test:artifact/2", + "Source": { + "SourceUri": "s3://my_account_alias-sagemaker/sagemaker/prediction/train/linear_train.data", + "SourceTypes": [] + }, + "ArtifactType": "DataSet", + "Properties": {}, + "CreationTime": "2021-08-07T13:44:46Z", + "CreatedBy": {}, + "LastModifiedTime": "2021-08-07T13:44:46Z", + "LastModifiedBy": {}, + "LineageGroupArn": "arn:aws-cn:sagemaker:us-east-1:test:lineage-group/sagemaker-default-lineage-group", + "ResponseMetadata": { + "RequestId": "8340bd3f-0bf6-40e9-a93e-1940de09ce2c", + "HTTPStatusCode": 200, + "HTTPHeaders": { + "x-amzn-requestid": "8340bd3f-0bf6-40e9-a93e-1940de09ce2c", + "content-type": "application/x-amz-json-1.1", + "content-length": "487", + "date": "Thu, 01 Jun 2023 17:28:46 GMT" + }, + "RetryAttempts": 0 + } +} diff --git a/plugins/aws/test/resources/files/sagemaker/list-artifacts.json b/plugins/aws/test/resources/files/sagemaker/list-artifacts.json index 0420d7100..9ab9bbab2 100644 --- a/plugins/aws/test/resources/files/sagemaker/list-artifacts.json +++ b/plugins/aws/test/resources/files/sagemaker/list-artifacts.json @@ -15,6 +15,16 @@ "ArtifactType": "string", "CreationTime": "2015-01-01T00:00:00Z", "LastModifiedTime": "2015-01-01T00:00:00Z" + }, + { + "ArtifactArn": "arn:aws:sagemaker:us-east-1:test:artifact/2", + "Source": { + "SourceUri": "s3://my_account_alias-sagemaker/sagemaker/prediction/train/linear_train.data", + "SourceTypes": [] + }, + "ArtifactType": "DataSet", + "CreationTime": "2021-08-07T13:44:46Z", + "LastModifiedTime": "2021-08-07T13:44:46Z" } ], "NextToken": "string" diff --git a/plugins/aws/test/resources/sagemaker_test.py b/plugins/aws/test/resources/sagemaker_test.py index 397a4ab27..d4ab60063 100644 --- a/plugins/aws/test/resources/sagemaker_test.py +++ b/plugins/aws/test/resources/sagemaker_test.py @@ -110,7 +110,7 @@ def test_image() -> None: def test_artifact() -> None: first, builder = round_trip_for(AwsSagemakerArtifact) - assert len(builder.resources_of(AwsSagemakerArtifact)) == 1 + assert len(builder.resources_of(AwsSagemakerArtifact)) == 2 def test_user_profile() -> None: