/** * @covers Aws\CloudTrail\CloudTrailClient::factory */ public function testFactoryInitializesClient() { $client = CloudTrailClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-west-2')); $this->assertInstanceOf('Aws\\Common\\Signature\\SignatureV4', $client->getSignature()); $this->assertInstanceOf('Aws\\Common\\Credentials\\Credentials', $client->getCredentials()); $this->assertEquals('https://cloudtrail.us-west-2.amazonaws.com', $client->getBaseUrl()); }
/** * @covers Aws\CloudTrail\LogFileIterator::forTrail */ public function testFactoryErrorsOnUnknownBucket() { $this->setExpectedException('InvalidArgumentException'); $s3Client = $this->getMockS3Client(); $cloudTrailClient = CloudTrailClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-west-2')); $cloudTrailClient->addSubscriber(new MockPlugin(array(new Response(200, null, '{"trailList":[]}')))); $files = LogFileIterator::forTrail($s3Client, $cloudTrailClient); }
/** * @covers Aws\CloudTrail\LogRecordIterator::forTrail */ public function testFactoryCanCreateForTrail() { $s3Client = $s3Client = S3Client::factory(array('key' => 'foo', 'secret' => 'bar')); $cloudTrailClient = CloudTrailClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-west-2')); $json = '{"trailList":[{"IncludeGlobalServiceEvents":true,"Name":"Default","S3BucketName":"log-bucket"}]}'; $cloudTrailClient->addSubscriber(new MockPlugin(array(new Response(200, null, $json)))); $records = LogRecordIterator::forTrail($s3Client, $cloudTrailClient); $this->assertInstanceOf('Aws\\CloudTrail\\LogRecordIterator', $records); }
/** * Contructs a LogRecordIterator. This factory method is used if the name of the S3 bucket containing your logs is * not known. This factory method uses a CloudTrail client and the trail name (or "Default") to find the * information about the trail necessary for constructing the LogRecordIterator * * @param S3Client $s3Client * @param CloudTrailClient $cloudTrailClient * @param array $options * * @return LogRecordIterator * @throws \Aws\Common\Exception\InvalidArgumentException * @see LogRecordIterator::__contruct */ public static function forTrail(S3Client $s3Client, CloudTrailClient $cloudTrailClient, array $options = array()) { $trailName = isset($options[self::TRAIL_NAME]) ? $options[self::TRAIL_NAME] : self::DEFAULT_TRAIL_NAME; $s3BucketName = null; // Use the CloudTrail client to get information about the trail, including the bucket name try { $result = $cloudTrailClient->describeTrails(array('trailNameList' => array($trailName))); $s3BucketName = $result->getPath('trailList/0/S3BucketName'); $options[self::KEY_PREFIX] = $result->getPath('trailList/0/S3KeyPrefix'); } catch (CloudTrailException $e) { // There was an error describing the trail } // If the bucket name is still unknown, then throw an exception if (!$s3BucketName) { $prev = isset($e) ? $e : null; throw new InvalidArgumentException('The bucket name could not be determined from the trail.', 0, $prev); } return new self($s3Client, $s3BucketName, $options); }