/**
  * Return an appropriate signature object for a a client based on a description
  *
  * @param ServiceDescription $description Description that holds a signature option
  * @param Collection         $config      Configuration options
  *
  * @return SignatureInterface
  * @throws InvalidArgumentException
  */
 protected function getSignature(ServiceDescription $description, Collection $config)
 {
     if (!($signature = $config->get(Options::SIGNATURE))) {
         switch ($description->getData('signatureVersion')) {
             case 'v2':
                 $signature = new SignatureV2();
                 break;
             case 'v3':
                 $signature = new SignatureV3();
                 break;
             case 'v3https':
                 $signature = new SignatureV3Https();
                 break;
             case 'v4':
                 $signature = new SignatureV4();
                 break;
             default:
                 throw new InvalidArgumentException('Service description does not specify a valid signatureVersion');
         }
     }
     // Allow a custom service name or region value to be provided
     if ($signature instanceof EndpointSignatureInterface) {
         // Determine the service name to use when signing
         if (!($service = $config->get(Options::SIGNATURE_SERVICE))) {
             if (!($service = $description->getData('signingName'))) {
                 $service = $description->getData('endpointPrefix');
             }
         }
         $signature->setServiceName($service);
         // Determine the region to use when signing requests
         if (!($region = $config->get(Options::SIGNATURE_REGION))) {
             $region = $config->get(Options::REGION);
         }
         $signature->setRegionName($region);
     }
     return $signature;
 }
Exemple #2
0
 /**
  * Return an appropriate signature object for a a client based on a description
  *
  * @param ServiceDescription $description Description that holds a signature option
  * @param Collection         $config      Configuration options
  *
  * @throws InvalidArgumentException
  */
 protected function addSignature(ServiceDescription $description, Collection $config)
 {
     if (!($signature = $config->get(Options::SIGNATURE))) {
         if (!$description->getData('signatureVersion')) {
             throw new InvalidArgumentException('The service description does not specify a signatureVersion');
         }
         switch ($description->getData('signatureVersion')) {
             case 'v2':
                 $signature = new SignatureV2();
                 break;
             case 'v3':
                 $signature = new SignatureV3();
                 break;
             case 'v3https':
                 $signature = new SignatureV3Https();
                 break;
             case 'v4':
                 $signature = new SignatureV4();
                 break;
         }
     }
     // Allow a custom service name or region value to be provided
     if ($signature instanceof EndpointSignatureInterface) {
         $signature->setServiceName($config->get(Options::SIGNATURE_SERVICE) ?: $description->getData('signingName'));
         $signature->setRegionName($config->get(Options::SIGNATURE_REGION));
     }
     $config->set(Options::SIGNATURE, $signature);
 }