예제 #1
0
 public function __call($method, $args)
 {
     // Overrides the parent behavior to make sure that the GetShardIterator operation works correctly
     if ($method === 'getShardIterator') {
         $params = isset($args[0]) ? $args[0] : array();
         return $this->getCommand($method, $params)->getResult();
     } else {
         return parent::__call($method, $args);
     }
 }
 public function testCanChangeRegions()
 {
     /** @var $s3 \Aws\S3\S3Client */
     $s3 = $this->getServiceBuilder()->get('s3', true);
     $scheme = $s3->getConfig(Options::SCHEME);
     // Switch to 3 different regions and validate that each switch worked
     foreach (array(Region::US_EAST_1, Region::EU_WEST_1, Region::AP_NORTHEAST_1) as $region) {
         $s3->setRegion($region);
         $endpoint = Url::factory(AbstractClient::getEndpoint($s3->getDescription(), $region, 'https'));
         $command = $s3->getCommand('ListBuckets');
         $request = $command->prepare();
         $this->assertEquals((string) $endpoint, $request->getScheme() . '://' . $request->getHost());
         $this->assertEquals((string) $endpoint, $s3->getConfig(Options::BASE_URL));
         $this->assertEquals($region, $s3->getConfig(Options::REGION));
         $this->assertEquals(200, $command->getResponse()->getStatusCode());
     }
 }
예제 #3
0
 /**
  * Update a configuration object from a service description
  *
  * @param Collection $config Config to update
  *
  * @return ServiceDescription
  * @throws InvalidArgumentException
  */
 protected function updateConfigFromDescription(Collection $config)
 {
     $description = $config->get(Options::SERVICE_DESCRIPTION);
     if (!$description instanceof ServiceDescription) {
         // Inject the version into the sprintf template if it is a string
         if (is_string($description)) {
             $description = sprintf($description, $config->get(Options::VERSION));
         }
         $description = ServiceDescription::factory($description);
         $config->set(Options::SERVICE_DESCRIPTION, $description);
     }
     if (!$config->get(Options::SERVICE)) {
         $config->set(Options::SERVICE, $description->getData('endpointPrefix'));
     }
     if ($iterators = $description->getData('iterators')) {
         $this->setIteratorsConfig($iterators);
     }
     // Ensure that the service description has regions
     if (!$description->getData('regions')) {
         throw new InvalidArgumentException('No regions found in the ' . $description->getData('serviceFullName') . ' description');
     }
     // Make sure a valid region is set
     $region = $config->get(Options::REGION);
     $global = $description->getData('globalEndpoint');
     if (!$global && !$region) {
         throw new InvalidArgumentException('A region is required when using ' . $description->getData('serviceFullName') . '. Set "region" to one of: ' . implode(', ', array_keys($description->getData('regions'))));
     } elseif ($global && (!$region || $description->getData('namespace') !== 'S3')) {
         $region = Region::US_EAST_1;
         $config->set(Options::REGION, $region);
     }
     if (!$config->get(Options::BASE_URL)) {
         // Set the base URL using the scheme and hostname of the service's region
         $config->set(Options::BASE_URL, AbstractClient::getEndpoint($description, $region, $config->get(Options::SCHEME)));
     }
     return $description;
 }
예제 #4
0
 /**
  * Update a configuration object from a service description
  *
  * @param Collection $config Config to update
  *
  * @return ServiceDescription
  * @throws InvalidArgumentException
  */
 protected function updateConfigFromDescription(Collection $config)
 {
     $description = $config->get(Options::SERVICE_DESCRIPTION);
     if (!$description instanceof ServiceDescription) {
         $description = ServiceDescription::factory($description);
         $config->set(Options::SERVICE_DESCRIPTION, $description);
     }
     if (!$config->get(Options::SERVICE)) {
         $config->set(Options::SERVICE, $description->getData('endpointPrefix'));
     }
     if ($iterators = $description->getData('iterators')) {
         $this->setIteratorsConfig($iterators);
     }
     // Ensure that the service description has regions
     if (!$description->getData('regions')) {
         throw new InvalidArgumentException('No regions found in the ' . $description->getData('serviceFullName') . ' description');
     }
     $region = $config->get(Options::REGION);
     if (!$region) {
         if (!$description->getData('globalEndpoint')) {
             throw new InvalidArgumentException('A region is required when using ' . $description->getData('serviceFullName') . '. Set "region" to one of: ' . implode(', ', array_keys($description->getData('regions'))));
         }
         $region = 'us-east-1';
         $config->set(Options::REGION, $region);
     }
     if (!$config->get(Options::BASE_URL)) {
         // Set the base URL using the scheme and hostname of the service's region
         $config->set(Options::BASE_URL, AbstractClient::getEndpoint($description, $region, $config->get(Options::SCHEME)));
     }
     return $description;
 }
예제 #5
0
파일: S3Client.php 프로젝트: noahkim/kowop
 /**
  * @param CredentialsInterface $credentials AWS credentials
  * @param S3SignatureInterface $signature   Amazon S3 Signature implementation
  * @param Collection           $config      Configuration options
  */
 public function __construct(CredentialsInterface $credentials, S3SignatureInterface $signature, Collection $config)
 {
     parent::__construct($credentials, $signature, $config);
     // Add aliases for some S3 operations
     $this->getCommandFactory()->add(new AliasFactory($this, self::$commandAliases), 'Guzzle\\Service\\Command\\Factory\\ServiceDescriptionFactory');
 }
예제 #6
0
 public function testCreatesEndpoints()
 {
     $this->assertEquals('http://test.com', AbstractClient::getEndpoint(ServiceDescription::factory(array('regions' => array('baz' => array('http' => true, 'hostname' => 'test.com')))), 'baz', 'http'));
 }