/** * @test */ public function getFirstReturnsFirstObjectOfCollection() { $collection = new \AwsInspector\Model\Collection(); $a = new \stdClass(); $a->title = 'StackFormation'; $collection->attach($a); $b = new \stdClass(); $b->title = 'WhateverElse'; $collection->attach($b); $collection->next(); $this->assertSame($a, $collection->getFirst()); $this->assertSame('StackFormation', $collection->getFirst()->title); }
/** * @return \AwsInspector\Model\Collection */ public function findLaunchConfigurations() { $result = $this->asgClient->describeLaunchConfigurations(); $rows = $result->search('LaunchConfigurations[]'); $collection = new \AwsInspector\Model\Collection(); foreach ($rows as $row) { $collection->attach(new LaunchConfiguration($row)); } return $collection; }
/** * @param array $filters * @return \AwsInspector\Model\Collection * @throws \Exception */ public function findEbsVolumes(array $filters = []) { $ec2Client = \AwsInspector\SdkFactory::getClient('ec2'); /* @var $ec2Client \Aws\Ec2\Ec2Client */ $result = $ec2Client->describeVolumes(['Filters' => $filters]); $rows = $result->search('Volumes[]'); $collection = new \AwsInspector\Model\Collection(); foreach ($rows as $row) { $collection->attach(new Volume($row)); } return $collection; }
/** * @param array $filters * @return \AwsInspector\Model\Collection * @throws \Exception */ public function findEc2Instances(array $filters = []) { $ec2Client = \AwsInspector\SdkFactory::getClient('ec2'); /* @var $ec2Client \Aws\Ec2\Ec2Client */ $result = $ec2Client->describeInstances(['Filters' => $filters]); $rows = $result->search('Reservations[].Instances[]'); $collection = new \AwsInspector\Model\Collection(); foreach ($rows as $row) { $instance = Factory::create($row); if ($instance !== false) { $collection->attach($instance); } } return $collection; }
/** * @param $logGroupName * @param string $logStreamNameFilter * @return \AwsInspector\Model\Collection */ public function findLogStreams($logGroupName, $logStreamNameFilter = null) { if (empty($logGroupName)) { throw new \InvalidArgumentException('LogGroupName cannot be empty'); } $result = $this->cloudWatchLogsClient->describeLogStreams(['logGroupName' => $logGroupName, 'orderBy' => 'LastEventTime', 'descending' => true]); $rows = $result->search('logStreams[]'); $collection = new \AwsInspector\Model\Collection(); foreach ($rows as $row) { if (!$logStreamNameFilter || Finder::matchWildcard($logStreamNameFilter, $row['logStreamName'])) { $collection->attach(new LogStream($row)); } } return $collection; }
/** * @param array $filters * @return \AwsInspector\Model\Collection * @throws \Exception */ public function findSecurityGroups(array $filters = []) { $ec2Client = \AwsInspector\SdkFactory::getClient('ec2'); /* @var $ec2Client \Aws\Ec2\Ec2Client */ $result = $ec2Client->describeSecurityGroups(['Filters' => $filters]); $rows = $result->search('SecurityGroups[]'); $collection = new \AwsInspector\Model\Collection(); foreach ($rows as $row) { $securityGroup = new SecurityGroup($row); if ($securityGroup !== false) { $collection->attach($securityGroup); } } return $collection; }