Ejemplo n.º 1
0
 public function testBasicOperations()
 {
     $inputBucket = 'php-integ-transcoder-test-bucket-input';
     $outputBucket = 'php-integ-transcoder-test-bucket-output';
     $roleName = 'php-integ-transcoder-test-role';
     $policyName = 'php-integ-transcoder-test-policy';
     $pipelineName = 'php-integ-transcoder-test-pipeline';
     self::log('Create input and output buckets for the Elastic Transcoder pipeline.');
     $commands = array();
     $commands[] = $this->s3->getCommand('CreateBucket', array('Bucket' => $inputBucket));
     $commands[] = $this->s3->getCommand('CreateBucket', array('Bucket' => $outputBucket));
     $this->s3->execute($commands);
     self::log('Create an IAM Role for the Elastic Transcoder pipeline.');
     $result = $this->iam->getCommand('CreateRole', array('RoleName' => $roleName, 'AssumeRolePolicyDocument' => self::DUMMY_IAM_POLICY_ASSUME_ROLE))->getResult();
     $roleArn = $result->getPath('Role/Arn');
     self::log('Put a policy on the IAM Role for the Elastic Transcoder pipeline.');
     $result = $this->iam->getCommand('PutRolePolicy', array('PolicyName' => $policyName, 'RoleName' => $roleName, 'PolicyDocument' => self::DUMMY_IAM_POLICY_ALLOW_S3))->getResult();
     self::log('Use TestRole to validate our pipeline inputs. NOTE: Ours are not valid on purpose.');
     $result = $this->transcoder->getCommand('TestRole', array('InputBucket' => $inputBucket, 'OutputBucket' => $outputBucket, 'Role' => $roleArn, 'Topics' => array()))->getResult();
     $this->assertEquals('false', $result['Success']);
     self::log('Create an Elastic Transcoder pipeline.');
     $result = $this->transcoder->getCommand('CreatePipeline', array('Name' => $pipelineName, 'InputBucket' => $inputBucket, 'OutputBucket' => $outputBucket, 'Role' => $roleArn, 'Notifications' => array_fill_keys(array('Progressing', 'Completed', 'Warning', 'Error'), '')))->getResult();
     $pipelineId = $result->getPath('Pipeline/Id');
     self::log('Make sure created Elastic Transcoder pipeline is in the list of pipelines.');
     $result = $this->transcoder->getCommand('ListPipelines')->getResult();
     $pipelineNames = $result->getPath('Pipelines/*/Name');
     $this->assertContains($pipelineName, $pipelineNames);
     self::log('Make sure ListPipelines iterator works.');
     $found = false;
     foreach ($this->transcoder->getIterator('ListPipelines') as $pipeline) {
         if ($pipeline['Name'] == $pipelineName) {
             $found = true;
             break;
         }
     }
     if (!$found) {
         $this->fail('Did not find the pipeline in the iterator results.');
     }
     self::log('Make sure created Elastic Transcoder pipeline can be read.');
     $result = $this->transcoder->getCommand('ReadPipeline', array('Id' => $pipelineId))->getResult();
     $this->assertEquals($pipelineName, $result->getPath('Pipeline/Name'));
     self::log('Delete the Elastic Transcoder pipeline.');
     $response = $this->transcoder->getCommand('DeletePipeline', array('Id' => $pipelineId))->getResponse();
     $this->assertEquals(202, $response->getStatusCode());
     self::log('Delete the policy from the IAM Role for the Elastic Transcoder pipeline.');
     $result = $this->iam->getCommand('DeleteRolePolicy', array('PolicyName' => $policyName, 'RoleName' => $roleName))->getResult();
     self::log('Delete the IAM Role for the Elastic Transcoder pipeline.');
     $result = $this->iam->getCommand('DeleteRole', array('RoleName' => $roleName))->getResult();
     self::log('Delete the input and output buckets for the Elastic Transcoder pipeline.');
     $commands = array();
     $commands[] = $this->s3->getCommand('DeleteBucket', array('Bucket' => $inputBucket));
     $commands[] = $this->s3->getCommand('DeleteBucket', array('Bucket' => $outputBucket));
     $this->s3->execute($commands);
 }
Ejemplo n.º 2
0
 /**
  * Executes a synchronous command.
  *
  * @param CommandInterface $command Command to execute.
  *
  * @return AwsS3Response
  */
 protected function executeCommand(CommandInterface $command)
 {
     try {
         $result = $this->client->execute($command);
     } catch (AwsException $e) {
         /* Return an error response. */
         return new AwsS3Response(null, $e);
     }
     return new AwsS3Response($result, null);
 }
 /**
  * Get the object acl presented as a visibility.
  *
  * @param string $path
  *
  * @return string
  */
 protected function getRawVisibility($path)
 {
     $command = $this->s3Client->getCommand('getObjectAcl', ['Bucket' => $this->bucket, 'Key' => $this->applyPathPrefix($path)]);
     $result = $this->s3Client->execute($command);
     $visibility = AdapterInterface::VISIBILITY_PRIVATE;
     foreach ($result->get('Grants') as $grant) {
         if (isset($grant['Grantee']['URI']) && $grant['Grantee']['URI'] === self::PUBLIC_GRANT_URI && $grant['Permission'] === 'READ') {
             $visibility = AdapterInterface::VISIBILITY_PUBLIC;
             break;
         }
     }
     return $visibility;
 }
Ejemplo n.º 4
0
 /**
  * @param $location
  *
  * @return bool
  */
 protected function doesDirectoryExist($location)
 {
     // Maybe this isn't an actual key, but a prefix.
     // Do a prefix listing of objects to determine.
     $command = $this->s3Client->getCommand('listObjects', ['Bucket' => $this->bucket, 'Prefix' => rtrim($location, '/') . '/', 'MaxKeys' => 1]);
     try {
         $result = $this->s3Client->execute($command);
         return $result['Contents'] || $result['CommonPrefixes'];
     } catch (S3Exception $e) {
         if ($e->getStatusCode() === 403) {
             return false;
         }
         throw $e;
     }
 }
Ejemplo n.º 5
0
 /**
  * @param string $name
  * @param string $data
  * @return mixed
  */
 public function saveFile($name, $data)
 {
     $command = $this->client->getCommand('PutObject', ['Bucket' => $this->getBucket(), 'Key' => $name, 'Body' => $data, 'ACL' => 'public-read']);
     return $this->client->execute($command);
 }