Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
Fully describes an ALB (ELBv2).
:param alb: Could be an ALB Name, ALB ARN, or a dictionary. Likely the return value from a previous call to describe_load_balancers. At a minimum, must contain a key titled 'LoadBalancerArn'.
:param flags: Flags describing which sections should be included in the return value. Default is FLAGS.ALL.
:return: Returns a dictionary describing the ALB with the fields described in the flags parameter.
"""
# Python 2 and 3 support:
try:
basestring
except NameError as _:
basestring = str
if isinstance(alb, basestring):
from cloudaux.orchestration.aws.arn import ARN
alb_arn = ARN(alb)
if alb_arn.error:
alb = dict(LoadBalancerName=alb)
else:
alb = dict(LoadBalancerArn=alb)
return registry.build_out(flags, start_with=alb, pass_datastructure=True, **conn)
def _conn_from_arn(arn):
"""
Extracts the account number from an ARN.
:param arn: Amazon ARN containing account number.
:return: dictionary with a single account_number key that can be merged with an existing
connection dictionary containing fields such as assume_role, session_name, region.
"""
arn = ARN(arn)
if arn.error:
raise CloudAuxException('Bad ARN: {arn}'.format(arn=arn))
return dict(
account_number=arn.account_number,
)
"CreationDate" ...,
"LastInventoryDate" ...,
"NumberOfArchives" ...,
"SizeInBytes" ...,
"Policy" ...,
"Tags" ...
}
Args:
vault_obj: name, ARN, or dict of Glacier Vault
flags: Flags describing which sections should be included in the return value. Default ALL
Returns:
dictionary describing the requested Vault
"""
if isinstance(vault_obj, string_types):
vault_arn = ARN(vault_obj)
if vault_arn.error:
vault_obj = {'VaultName': vault_obj}
else:
vault_obj = {'VaultName': vault_arn.parsed_name}
return registry.build_out(flags, vault_obj, **conn)
def _get_name_from_structure(item, default):
"""
Given a possibly sparsely populated item dictionary, try to retrieve the item name.
First try the default field. If that doesn't exist, try to parse the from the ARN.
:param item: dict containing (at the very least) item_name and/or arn
:return: item name
"""
if item.get(default):
return item.get(default)
if item.get('Arn'):
arn = item.get('Arn')
item_arn = ARN(arn)
if item_arn.error:
raise CloudAuxException('Bad ARN: {arn}'.format(arn=arn))
return item_arn.parsed_name
raise MissingFieldException('Cannot extract item name from input: {input}.'.format(input=item))
def create_item_aws(item, technology, account):
arn = ARN(item.config.get('Arn'))
return Item(
region=arn.region or 'universal',
name=arn.parsed_name or arn.name,
arn=item.config.get('Arn'),
tech_id=technology.id,
account_id=account.id
)