public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     foreach ($this->buffered as $param) {
         $this->visitWithValue($command[$param->getName()], $param, $operation);
     }
     $this->buffered = [];
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $additional->setName($key);
                 $this->visitWithValue($value, $additional, $operation);
             }
         }
         $additional->setName(null);
     }
     // If data was found that needs to be serialized, then do so
     $xml = null;
     if ($this->writer) {
         $xml = $this->finishDocument($this->writer);
     } elseif ($operation->getData('xmlAllowEmpty')) {
         // Check if XML should always be sent for the command
         $writer = $this->createRootElement($operation);
         $xml = $this->finishDocument($writer);
     }
     if ($xml) {
         $request->setBody(Stream::factory($xml));
         // Don't overwrite the Content-Type if one is set
         if ($this->contentType && !$request->hasHeader('Content-Type')) {
             $request->setHeader('Content-Type', $this->contentType);
         }
     }
     $this->writer = null;
 }
 public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $request->setHeader($key, $additional->filter($value));
             }
         }
     }
 }
 private function createPresignedUrl(AwsClientInterface $client, CommandInterface $cmd)
 {
     $newCmd = $client->getCommand('CopySnapshot', $cmd->toArray());
     $newCmd->getEmitter()->detach($this);
     // Serialize a request for the CopySnapshot operation.
     $request = $client->initTransaction($newCmd)->request;
     // Create the new endpoint for the target endpoint.
     $endpoint = EndpointProvider::resolve($this->endpointProvider, ['region' => $cmd['SourceRegion'], 'service' => 'ec2'])['endpoint'];
     // Set the request to hit the target endpoint.
     $request->setHost(Url::fromString($endpoint)->getHost());
     // Create a presigned URL for our generated request.
     $signer = new SignatureV4('ec2', $cmd['SourceRegion']);
     return $signer->createPresignedUrl(SignatureV4::convertPostToGet($request), $client->getCredentials(), '+1 hour');
 }
 public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         $body = $request->getBody();
         if (!$body instanceof PostBodyInterface) {
             throw new \RuntimeException('Must be a POST body interface');
         }
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $body->setField($key, $this->prepareValue($value, $additional));
             }
         }
     }
 }
 public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
 {
     $data = $this->jsonData;
     $this->jsonData = null;
     // Add additional parameters to the JSON document
     $additional = $operation->getAdditionalParameters();
     if ($additional && $additional->getLocation() == $this->locationName) {
         foreach ($command->toArray() as $key => $value) {
             if (!$operation->hasParam($key)) {
                 $data[$key] = $this->prepareValue($value, $additional);
             }
         }
     }
     // Don't overwrite the Content-Type if one is set
     if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
         $request->setHeader('Content-Type', $this->jsonContentType);
     }
     $request->setBody(Stream::factory(json_encode($data)));
 }
예제 #6
0
 /**
  * @param CommandInterface $command
  *
  * @return RequestInterface
  */
 public function commandToRequestTransformer(CommandInterface $command)
 {
     $name = $command->getName();
     if (!isset($this->api[$name])) {
         throw new CommandException('Command not found', $command);
     }
     $action = $this->api[$name];
     $prefix = '';
     if (isset($action['public']) && $command->hasParam('public')) {
         $prefix = '/public';
     }
     $prefixes = ['system' => '/systems/{system}', 'issuer' => '/issuers/{issuer}', 'program' => '/programs/{program}'];
     if (isset($action['admin_contexts'])) {
         $prefix .= implode('', array_intersect_key($prefixes, array_flip($action['admin_contexts']), array_merge($command->toArray(), $this->adminContext)));
     }
     $path = GuzzleHttp\uri_template($prefix . $action['path'], array_merge($command->toArray(), $this->adminContext));
     $headers = [];
     $body = null;
     if ($command->hasParam('body')) {
         $headers = ['Content-Type' => 'application/json'];
         $body = GuzzleHttp\json_encode($command['body']);
     }
     if ($command->hasParam('query')) {
         $path .= '?' . Psr7\build_query($command['query']);
     }
     return new Psr7\Request($action['method'], $path, $headers, $body);
 }