Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try:
if vpc_id and vpc_name: # pylint: disable=R1705
return describe_vpcs(
account_number=account_id,
assume_role=HISTORICAL_ROLE,
region=CURRENT_REGION,
Filters=[
{
'Name': 'vpc-id',
'Values': [vpc_id]
}
]
)
elif vpc_id:
return describe_vpcs(
account_number=account_id,
assume_role=HISTORICAL_ROLE,
region=CURRENT_REGION,
VpcIds=[vpc_id]
)
else:
raise Exception('[X] Describe requires VpcId.')
except ClientError as exc:
if exc.response['Error']['Code'] == 'InvalidVpc.NotFound':
return []
raise exc
def describe_vpc(record):
"""Attempts to describe vpc ids."""
account_id = record['account']
vpc_name = cloudwatch.filter_request_parameters('vpcName', record)
vpc_id = cloudwatch.filter_request_parameters('vpcId', record)
try:
if vpc_id and vpc_name: # pylint: disable=R1705
return describe_vpcs(
account_number=account_id,
assume_role=HISTORICAL_ROLE,
region=CURRENT_REGION,
Filters=[
{
'Name': 'vpc-id',
'Values': [vpc_id]
}
]
)
elif vpc_id:
return describe_vpcs(
account_number=account_id,
assume_role=HISTORICAL_ROLE,
region=CURRENT_REGION,
VpcIds=[vpc_id]
Historical Security Group Poller Processor.
This will receive events from the Poller Tasker, and will list all objects of a given technology for an
account/region pair. This will generate `polling events` which simulate changes. These polling events contain
configuration data such as the account/region defining where the collector should attempt to gather data from.
"""
LOG.debug('[@] Running Poller...')
queue_url = get_queue_url(os.environ.get('POLLER_QUEUE_NAME', 'HistoricalVPCPoller'))
records = deserialize_records(event['Records'])
for record in records:
# Skip accounts that have role assumption errors:
try:
vpcs = describe_vpcs(
account_number=record['account_id'],
assume_role=HISTORICAL_ROLE,
region=record['region']
)
events = [VPC_POLLING_SCHEMA.serialize(record['account_id'], v) for v in vpcs]
produce_events(events, queue_url, randomize_delay=RANDOMIZE_POLLER)
LOG.debug(f"[@] Finished generating polling events. Account: {record['account_id']}/{record['region']} "
f"Events Created: {len(events)}")
except ClientError as exc:
LOG.error(f"[X] Unable to generate events for account/region. Account Id/Region: {record['account_id']}"
f"/{record['region']} Reason: {exc}")
- Tags
- IsDefault
- InstanceTenancy
- CidrBlock
- CidrBlockAssociationSet
- Ipv6CidrBlockAssociationSet
- DhcpOptionsId
- Attributes
- _version
:param bucket_name:
:param conn:
:return:
"""
# Get the base:
base_result = describe_vpcs(VpcIds=[vpc["id"]], **conn)[0]
# The name of the VPC is in the tags:
vpc_name = None
for t in base_result.get("Tags", []):
if t["Key"] == "Name":
vpc_name = t["Value"]
dhcp_opts = None
# Get the DHCP Options:
if base_result.get("DhcpOptionsId"):
# There should only be exactly 1 attached to a VPC:
dhcp_opts = describe_dhcp_options(DhcpOptionsIds=[base_result["DhcpOptionsId"]], **conn)[0]["DhcpOptionsId"]
# Get the Attributes:
attributes = {}
attr_vals = [