diff --git a/library/Aws/AwsClient.php b/library/Aws/AwsClient.php index a0d9801..c320ab0 100644 --- a/library/Aws/AwsClient.php +++ b/library/Aws/AwsClient.php @@ -189,6 +189,52 @@ public function getRdsInstances() return $this->sortByName($objects); } + public function getRoute53Records() + { + $client = $this->sdk()->createRoute53(); + $zonesPaginator = $client->getPaginator('ListHostedZones', [ + 'MaxItems' => '100' + ]); + $objects = []; + foreach ($zonesPaginator as $zonesRs) { + foreach ($zonesRs['HostedZones'] as $zone) { + $resourcesPaginator = $client->getPaginator('ListResourceRecordSets', [ + 'MaxItems' => '100', + 'HostedZoneId' => $zone['Id'] + ]); + foreach ($resourcesPaginator as $resourceRs) { + foreach ($resourceRs['ResourceRecordSets'] as $recordset) { + $objects[] = $object = $this->extractAttributes($recordset, array( + 'recordname' => 'Name', + 'type' => 'Type' + )); + // 'Name' is not necessarily unique so we have to create a unique one + if (array_key_exists('Weight', $recordset)) { + $object->name = "{$recordset["Type"]}_{$recordset["Weight"]}_{$recordset["Name"]}"; + } + else { + $object->name = "{$recordset["Type"]}_{$recordset["Name"]}"; + } + + $object->private_zone = $zone['Config']['PrivateZone']; + $object->zone_name = $zone['Name']; + $object->zone_id = $zone['Id']; + if (array_key_exists('ResourceRecords', $recordset)) { + $object->records = $recordset['ResourceRecords']; + } + if (array_key_exists('TTL', $recordset)) { + $object->ttl = $recordset['TTL']; + } + } + // One would assume that the AWS paginators handle throttling, but they don't. Throttle to 4 req/s + usleep(250000); + } + } + } + + return $this->sortByName($objects); + } + public static function enumRegions() { return array( diff --git a/library/Aws/ProvidedHook/Director/ImportSource.php b/library/Aws/ProvidedHook/Director/ImportSource.php index db30d92..632ccad 100644 --- a/library/Aws/ProvidedHook/Director/ImportSource.php +++ b/library/Aws/ProvidedHook/Director/ImportSource.php @@ -12,11 +12,12 @@ class ImportSource extends ImportSourceHook { protected static $awsObjectTypes = array( - 'asg' => 'Auto Scaling Groups', - 'lb' => 'Elastic Load Balancers', - 'lbv2' => 'Elastic Load Balancers V2', - 'ec2instance' => 'EC2 Instances', - 'rdsinstance' => 'RDS Instances' + 'asg' => 'Auto Scaling Groups', + 'lb' => 'Elastic Load Balancers', + 'lbv2' => 'Elastic Load Balancers V2', + 'ec2instance' => 'EC2 Instances', + 'rdsinstance' => 'RDS Instances', + 'route53records' => 'Route53 Records' ); protected $db; @@ -47,6 +48,8 @@ public function fetchData() return $client->getEc2Instances(); case 'rdsinstance': return $client->getRdsInstances(); + case 'route53records': + return $client->getRoute53Records(); } } @@ -144,6 +147,17 @@ public function listColumns() 'tags.aws:cloudformation:stack-id', 'tags.aws:cloudformation:stack-name', ); + case 'route53records': + return [ + 'name', + 'recordname', + 'type', + 'records', + 'ttl', + 'private_zone', + 'zone_name', + 'zone_id', + ]; } }