added resourcegroupstaggingapi support for ssm (#7430)
This commit is contained in:
parent
40a86b7fb4
commit
c0152f206f
@ -22,6 +22,7 @@ from moto.redshift.models import RedshiftBackend, redshift_backends
|
|||||||
from moto.s3.models import S3Backend, s3_backends
|
from moto.s3.models import S3Backend, s3_backends
|
||||||
from moto.sns.models import SNSBackend, sns_backends
|
from moto.sns.models import SNSBackend, sns_backends
|
||||||
from moto.sqs.models import SQSBackend, sqs_backends
|
from moto.sqs.models import SQSBackend, sqs_backends
|
||||||
|
from moto.ssm.models import SimpleSystemManagerBackend, ssm_backends
|
||||||
from moto.utilities.tagging_service import TaggingService
|
from moto.utilities.tagging_service import TaggingService
|
||||||
|
|
||||||
# Left: EC2 ElastiCache RDS ELB CloudFront WorkSpaces Lambda EMR Glacier Kinesis Redshift Route53
|
# Left: EC2 ElastiCache RDS ELB CloudFront WorkSpaces Lambda EMR Glacier Kinesis Redshift Route53
|
||||||
@ -102,6 +103,10 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
|
|||||||
@property
|
@property
|
||||||
def sns_backend(self) -> SNSBackend:
|
def sns_backend(self) -> SNSBackend:
|
||||||
return sns_backends[self.account_id][self.region_name]
|
return sns_backends[self.account_id][self.region_name]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ssm_backend(self) -> SimpleSystemManagerBackend:
|
||||||
|
return ssm_backends[self.account_id][self.region_name]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sqs_backend(self) -> SQSBackend:
|
def sqs_backend(self) -> SQSBackend:
|
||||||
@ -512,6 +517,22 @@ class ResourceGroupsTaggingAPIBackend(BaseBackend):
|
|||||||
continue
|
continue
|
||||||
yield {"ResourceARN": f"{topic.arn}", "Tags": tags}
|
yield {"ResourceARN": f"{topic.arn}", "Tags": tags}
|
||||||
|
|
||||||
|
|
||||||
|
# SSM
|
||||||
|
if not resource_type_filters or "ssm" in resource_type_filters:
|
||||||
|
for document in self.ssm_backend._documents.values():
|
||||||
|
doc_name = document.describe()["Name"]
|
||||||
|
tags = self.ssm_backend._get_documents_tags(doc_name)
|
||||||
|
if not tags or not tag_filter(
|
||||||
|
tags
|
||||||
|
): # Skip if no tags, or invalid filter
|
||||||
|
continue
|
||||||
|
yield {
|
||||||
|
"ResourceARN": f"arn:aws:ssm:{self.region_name}:{self.account_id}:document/{doc_name}",
|
||||||
|
"Tags": tags,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# VPC
|
# VPC
|
||||||
if (
|
if (
|
||||||
not resource_type_filters
|
not resource_type_filters
|
||||||
|
@ -759,6 +759,34 @@ def test_get_resources_sns():
|
|||||||
"Tags"
|
"Tags"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@mock_aws
|
||||||
|
def test_get_resources_ssm():
|
||||||
|
import json
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
from tests.test_ssm.test_ssm_docs import _get_yaml_template
|
||||||
|
|
||||||
|
template_file = _get_yaml_template()
|
||||||
|
json_doc = yaml.safe_load(template_file)
|
||||||
|
|
||||||
|
ssm = boto3.client("ssm", region_name="us-east-1")
|
||||||
|
ssm.create_document(
|
||||||
|
Content=json.dumps(json_doc),
|
||||||
|
Name="TestDocument",
|
||||||
|
DocumentType="Command",
|
||||||
|
DocumentFormat="JSON",
|
||||||
|
Tags=[{"Key": 'testing', "Value": "testingValue"}],
|
||||||
|
)
|
||||||
|
|
||||||
|
rtapi = boto3.client("resourcegroupstaggingapi", region_name="us-east-1")
|
||||||
|
resp = rtapi.get_resources(ResourceTypeFilters=["ssm"])
|
||||||
|
|
||||||
|
assert len(resp["ResourceTagMappingList"]) == 1
|
||||||
|
assert {"Key": 'testing', "Value": "testingValue"} in resp["ResourceTagMappingList"][0][
|
||||||
|
"Tags"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
@mock_aws
|
@mock_aws
|
||||||
def test_tag_resources_for_unknown_service():
|
def test_tag_resources_for_unknown_service():
|
||||||
|
Loading…
Reference in New Issue
Block a user