Merge pull request #1244 from radhus/sg_filter_tag_wildcard
Support wildcard tag filters on SecurityGroups
This commit is contained in:
commit
c23c5057f2
@ -109,6 +109,7 @@ from .utils import (
|
|||||||
random_vpn_connection_id,
|
random_vpn_connection_id,
|
||||||
random_customer_gateway_id,
|
random_customer_gateway_id,
|
||||||
is_tag_filter,
|
is_tag_filter,
|
||||||
|
tag_filter_matches,
|
||||||
)
|
)
|
||||||
|
|
||||||
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), 'resources')
|
RESOURCES_DIR = os.path.join(os.path.dirname(__file__), 'resources')
|
||||||
@ -1309,7 +1310,7 @@ class SecurityGroup(TaggedEC2Resource):
|
|||||||
elif is_tag_filter(key):
|
elif is_tag_filter(key):
|
||||||
tag_value = self.get_filter_value(key)
|
tag_value = self.get_filter_value(key)
|
||||||
if isinstance(filter_value, list):
|
if isinstance(filter_value, list):
|
||||||
return any(v in tag_value for v in filter_value)
|
return tag_filter_matches(self, key, filter_value)
|
||||||
return tag_value in filter_value
|
return tag_value in filter_value
|
||||||
else:
|
else:
|
||||||
attr_name = to_attr(key)
|
attr_name = to_attr(key)
|
||||||
|
@ -613,6 +613,20 @@ def test_security_group_tagging_boto3():
|
|||||||
tag['Key'].should.equal("Test")
|
tag['Key'].should.equal("Test")
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_security_group_wildcard_tag_filter_boto3():
|
||||||
|
conn = boto3.client('ec2', region_name='us-east-1')
|
||||||
|
sg = conn.create_security_group(GroupName="test-sg", Description="Test SG")
|
||||||
|
conn.create_tags(Resources=[sg['GroupId']], Tags=[
|
||||||
|
{'Key': 'Test', 'Value': 'Tag'}])
|
||||||
|
describe = conn.describe_security_groups(
|
||||||
|
Filters=[{'Name': 'tag-value', 'Values': ['*']}])
|
||||||
|
|
||||||
|
tag = describe["SecurityGroups"][0]['Tags'][0]
|
||||||
|
tag['Value'].should.equal("Tag")
|
||||||
|
tag['Key'].should.equal("Test")
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
def test_authorize_and_revoke_in_bulk():
|
def test_authorize_and_revoke_in_bulk():
|
||||||
ec2 = boto3.resource('ec2', region_name='us-west-1')
|
ec2 = boto3.resource('ec2', region_name='us-west-1')
|
||||||
|
Loading…
Reference in New Issue
Block a user