Skip to content

Commit

Permalink
Merge pull request #38 from mzhaase/feature/route53-records
Browse files Browse the repository at this point in the history
Add Route53 Record support
  • Loading branch information
lippserd authored Oct 9, 2020
2 parents d2e583b + 3cc5937 commit 5b8818d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
46 changes: 46 additions & 0 deletions library/Aws/AwsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 19 additions & 5 deletions library/Aws/ProvidedHook/Director/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +48,8 @@ public function fetchData()
return $client->getEc2Instances();
case 'rdsinstance':
return $client->getRdsInstances();
case 'route53records':
return $client->getRoute53Records();
}
}

Expand Down Expand Up @@ -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',
];
}
}

Expand Down

0 comments on commit 5b8818d

Please sign in to comment.