from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): iot = boto3.client('iot', region_name=target["region"]) things = iot.list_things()['things'] things = [ dalek("iot_thing", region=target["region"], names=[thing["thingName"]]) for thing in things ] return things chaser("iot_things", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): iot = boto3.client('iot', region_name=target["region"]) certs = iot.list_certificates()['certificates'] daleks = [] for cert in certs: if cert["status"] == "ACTIVE": daleks.append( dalek("iot_certificate", region=target["region"], names=[cert["certificateId"]])) return daleks chaser("iot_certificates", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): region_name = target["region"] ec2 = boto3.client('ec2', region_name=region_name) describe_instances = ec2.describe_instances( Filters=[{ 'Name': 'instance-state-name', 'Values': [ 'running' ] }] ) reservations = describe_instances['Reservations'] instancess = [r['Instances'] for r in reservations] instances = [i for instances in instancess for i in instances] instance_ids = [i['InstanceId'] for i in instances] daleks = [dalek("ec2_instance", region=region_name, names=instance_ids)] return daleks chaser("ec2_instances", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): iot = boto3.client('iot', region_name=target["region"]) pols = iot.list_policies()['policies'] pols = [pol["policyName"] for pol in pols] daleks = [ dalek("iot_policy", region=target["region"], names=[pol]) for pol in pols ] return daleks chaser("iot_policies", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): iot = boto3.client('iot', region_name=target["region"]) things = iot.list_things()['things'] things = [dalek("iot_thing", region=target["region"], names=[thing["thingName"]]) for thing in things] return things chaser("iot_things", lambda r: chase(r))
from awsdaleks import chaser, newTarget import boto3 service = "cloudformation" def mkstack(region, stack_summary): return newTarget("cloudformation_stack", region, [stack_summary['StackName']], { "StackStatus": stack_summary['StackStatus'], "ExtraStr": stack_summary['StackStatus'], }) def chase(t): region = t["region"] client = boto3.client(service, region_name=region) response = client.list_stacks(StackStatusFilter=[ 'CREATE_FAILED', 'CREATE_COMPLETE', 'ROLLBACK_FAILED', 'ROLLBACK_COMPLETE', 'DELETE_FAILED', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE']) stacks = response["StackSummaries"] targets = list(map(lambda ss: mkstack(region, ss), stacks)) return targets chaser("cloudformation", lambda r: chase(r))
from awsdaleks import chaser, newTarget import boto3 def chase(target): return [newTarget("ec2_instances", region=target["region"])] chaser("ec2", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): iot = boto3.client('iot', region_name=target["region"]) rules = iot.list_topic_rules()['rules'] rules = [rule["ruleName"] for rule in rules] daleks = [dalek("iot_rule", region=target["region"], names=[rule]) for rule in rules] return daleks chaser("iot_rules", lambda r: chase(r))
def list_objects(bucketName, region): kwargs = {'Bucket': bucketName} # TODO: Support large (>1000) buckets list_object_versions = s3.list_object_versions(**kwargs) versions = list_object_versions.get("Versions", []) objects = list(map(mkversion, versions)) result = [] if objects: result = [ newTarget("s3_objects", region, objects, {"bucket-name": bucketName}) ] return result def chase(bucket): bucketNames = bucket.get("resource_names", []) if len(bucketNames) > 0: bucketName = bucketNames[0] region = bucket["region"] objects = list_objects(bucketName, region) empty_bucket = newTarget("s3_empty_bucket", bucket["region_name"], [bucketName]) targets = objects + [empty_bucket] return targets else: return [] chaser("s3_bucket", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): client = boto3.client('lambda', region_name=target["region"]) functions = client.list_functions()["Functions"] functions = [fun["FunctionName"] for fun in functions] daleks = [dalek("lambda_function", region=target["region"], names=[fun]) for fun in functions] return daleks chaser("lambda", lambda r: chase(r))
from awsdaleks import chaser, dalek import boto3 def chase(target): return [ dalek("iot_things", region=target["region"]), dalek("iot_rules", region=target["region"]), dalek("iot_policies", region=target["region"]), dalek("iot_certificates", region=target["region"]) ] chaser("iot", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): client = boto3.client('lambda', region_name=target["region"]) functions = client.list_functions()["Functions"] functions = [fun["FunctionName"] for fun in functions] daleks = [ dalek("lambda_function", region=target["region"], names=[fun]) for fun in functions ] return daleks chaser("lambda", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): iot = boto3.client('iot', region_name=target["region"]) certs = iot.list_certificates()['certificates'] daleks = [] for cert in certs: if cert["status"] == "ACTIVE": daleks.append(dalek("iot_certificate", region=target["region"], names=[ cert["certificateId"]])) return daleks chaser("iot_certificates", lambda r: chase(r))
from awsdaleks import chaser, newTarget import boto3 s3 = boto3.client('s3') def mkbucket(bucket): name = bucket['Name'] region_name = s3.get_bucket_location(Bucket=name)[ "LocationConstraint"] return newTarget("s3_bucket", region_name, [name]) def chase(target): buckets = s3.list_buckets()['Buckets'] targets = [mkbucket(b) for b in buckets] return targets chaser("s3global", lambda r: chase(r))
list_object_versions = s3.list_object_versions(**kwargs) versions = list_object_versions.get("Versions", []) objects = list(map(mkversion, versions)) result = [] if objects: result = [newTarget("s3_objects", region, objects, { "bucket-name": bucketName })] return result def chase(bucket): bucketNames = bucket.get("resource_names", []) if len(bucketNames) > 0: bucketName = bucketNames[0] region = bucket["region"] objects = list_objects(bucketName, region) empty_bucket = newTarget("s3_empty_bucket", bucket["region_name"], [bucketName]) targets = objects + [empty_bucket] return targets else: return [] chaser("s3_bucket", lambda r: chase(r))
from awsdaleks import chaser, dalek import boto3 def daleks(*args): return [dalek(arg) for arg in args] def chase(target): return daleks( #"iot", "lambda", # dalek("cloudformation"), # "ec2" # , # dalek("s3global"), # dalek("iam_users") ) chaser("aws", lambda r: chase(r))
from awsdaleks import chaser, newTarget import boto3 s3 = boto3.client('s3') def mkbucket(bucket): name = bucket['Name'] region_name = s3.get_bucket_location(Bucket=name)["LocationConstraint"] return newTarget("s3_bucket", region_name, [name]) def chase(target): buckets = s3.list_buckets()['Buckets'] targets = [mkbucket(b) for b in buckets] return targets chaser("s3global", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 iam = boto3.client('iam') def chase(target): list_users = iam.list_users()['Users'] daleks = [dalek("iam-user", None, user['UserName']) for user in list_users] return daleks chaser("iam-users", lambda r: chase(r))
from awsdaleks import chaser, warrior, dalek import boto3 def chase(target): region_name = target["region"] ec2 = boto3.client('ec2', region_name=region_name) describe_instances = ec2.describe_instances(Filters=[{ 'Name': 'instance-state-name', 'Values': ['running'] }]) reservations = describe_instances['Reservations'] instancess = [r['Instances'] for r in reservations] instances = [i for instances in instancess for i in instances] instance_ids = [i['InstanceId'] for i in instances] daleks = [dalek("ec2_instance", region=region_name, names=instance_ids)] return daleks chaser("ec2_instances", lambda r: chase(r))
from awsdaleks import chaser, newTarget import boto3 service = "cloudformation" def mkstack(region, stack_summary): return newTarget( "cloudformation_stack", region, [stack_summary['StackName']], { "StackStatus": stack_summary['StackStatus'], "ExtraStr": stack_summary['StackStatus'], }) def chase(t): region = t["region"] client = boto3.client(service, region_name=region) response = client.list_stacks(StackStatusFilter=[ 'CREATE_FAILED', 'CREATE_COMPLETE', 'ROLLBACK_FAILED', 'ROLLBACK_COMPLETE', 'DELETE_FAILED', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_FAILED', 'UPDATE_ROLLBACK_COMPLETE' ]) stacks = response["StackSummaries"] targets = list(map(lambda ss: mkstack(region, ss), stacks)) return targets chaser("cloudformation", lambda r: chase(r))