コード例 #1
0
ファイル: PrepareRequest.php プロジェクト: detailnet/blitline
 /**
  * @param PreparedEvent $event
  * @return array
  */
 protected function getRequestOptions(PreparedEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     $requestOptions = $operation->getData('requestOptions');
     return is_array($requestOptions) ? $requestOptions : array();
 }
コード例 #2
0
ファイル: SaveAs.php プロジェクト: briareos/aws-sdk-php
 public function onPrepared(PreparedEvent $event)
 {
     $command = $event->getCommand();
     if ($value = $command[$this->paramName]) {
         $event->getRequest()->getConfig()->set('save_to', $value);
     }
 }
コード例 #3
0
 /**
  * Update a command with the content and tree hash headers, as needed.
  *
  * @param PreparedEvent $event Event emitted.
  *
  * @throws \RuntimeException if the body is not seekable.
  */
 public function onPrepared(PreparedEvent $event)
 {
     $command = $event->getCommand();
     $name = $command->getName();
     // Determine if there is a need to calculate any hashes.
     $needsHashes = ($name === 'UploadArchive' || $name === 'UploadPart') && (!$command['checksum'] || !$command['ContentSHA256']);
     if ($needsHashes) {
         $body = $event->getRequest()->getBody();
         if (!$body->isSeekable()) {
             throw new CouldNotCreateChecksumException('sha256');
         }
         // Add a tree hash if not provided.
         if (!$command['checksum']) {
             $body = new HashingStream($body, new TreeHash(), function ($result) use($command, $event) {
                 $event->getRequest()->setHeader('x-amz-sha256-tree-hash', bin2hex($result));
             });
         }
         // Add a linear content hash if not provided.
         if (!$command['ContentSHA256']) {
             $body = new HashingStream($body, new PhpHash('sha256'), function ($result) use($command) {
                 $command['ContentSHA256'] = bin2hex($result);
             });
         }
         // Read the stream in order to calculate the hashes.
         while (!$body->eof()) {
             $body->read(1048576);
         }
         $body->seek(0);
     }
     // Set the content hash header if there is a value to set.
     if ($hash = $command['ContentSHA256']) {
         $event->getRequest()->addHeader('x-amz-content-sha256', $hash);
     }
 }
コード例 #4
0
 public function onPrepared(PreparedEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     if ($operation->getData('refresh-token-data') === true) {
         $event->getRequest()->setBody(Stream::factory(json_encode(['refreshToken' => $this->refreshToken->getRefreshToken()])));
     }
 }
コード例 #5
0
 public function setHeaders(PreparedEvent $event)
 {
     $request = $event->getRequest();
     if (!$request->hasHeader('Content-Type')) {
         $request->addHeader('Content-Type', 'application/json');
     }
     $request->addHeader('Accept', 'application/json');
 }
コード例 #6
0
ファイル: CommandWrapper.php プロジェクト: viunyk/grape
 /**
  * Add extra parameter 'calledMethod'.
  *
  * React on prepared event, before send.
  */
 public function onPrepared(PreparedEvent $event)
 {
     $command = $event->getCommand();
     $request = $event->getRequest();
     $body = (array) json_decode((string) $request->getBody());
     $body['calledMethod'] = $command->getName();
     $event->getRequest()->setBody(Stream::factory(json_encode($body)));
 }
コード例 #7
0
 public function onPrepared(PreparedEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     if ($operation->getData('access-token-auth') !== false) {
         $event->getRequest()->addHeader('Authorization', 'Bearer ' . $this->accessToken->getAccessToken());
     }
 }
 public function setCredentials(PreparedEvent $event)
 {
     $request = $event->getRequest();
     if (strtolower($event->getCommand()->getName()) !== 'getcookie') {
         $request->addHeader('SubscriptionToken', $this->credentials->getSubscriptionToken());
     } else {
         $request->removeHeader('SubscriptionToken');
     }
 }
コード例 #9
0
 public function onPrepared(PreparedEvent $event)
 {
     $command = $event->getCommand();
     if ($command->hasParam('QueueUrl')) {
         $request = $event->getRequest();
         $url = Url::fromString($request->getUrl());
         $request->setUrl($url->combine($command['QueueUrl']));
     }
 }
コード例 #10
0
ファイル: ResultMock.php プロジェクト: artoscopus/command
 /**
  * @throws \Exception if one has been queued.
  * @throws \OutOfBoundsException if the queue is empty.
  */
 public function onPrepared(PreparedEvent $event)
 {
     if (!($result = array_shift($this->queue))) {
         throw new \OutOfBoundsException('Result mock queue is empty');
     } elseif ($result instanceof \Exception) {
         throw $result;
     } else {
         $event->intercept($result);
     }
 }
コード例 #11
0
 /**
  * Event to add Segment.io Specific data to the Event Messages
  *
  * @param PreparedEvent $event The PreparedEvent
  *
  * @return bool
  */
 public function onPrepared(PreparedEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     if (!$operation->getData('batching')) {
         return false;
     }
     $parameters = json_decode($event->getRequest()->getBody()->getContents(), true);
     $this->enqueue(array_merge($parameters, ['action' => $command->getName()]));
     $event->intercept(['success' => true, 'batched' => true]);
     return true;
 }
コード例 #12
0
 public function onPrepared(PreparedEvent $event)
 {
     if ($this->userToken === null) {
         return;
     }
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     if ($operation->getData('user-token-authentication') === true) {
         $query = $event->getRequest()->getQuery();
         $query->add('user_api_token', $this->userToken->getToken());
     }
 }
コード例 #13
0
ファイル: PathListener.php プロジェクト: Nanomani/pydio-core
 /**
  * Handle the before trigger
  *
  * @param PreparedEvent event
  */
 public function onBefore(PreparedEvent $e)
 {
     $request = $e->getRequest();
     if (empty($request)) {
         return;
     }
     $path = $request->getPath();
     if (empty($path)) {
         return;
     }
     $path = rawurldecode($path);
     $path = str_replace('//', '/', $path);
     $request->setPath($path);
 }
コード例 #14
0
 public function onPrepared(PreparedEvent $event)
 {
     if ($this->apiKeyToken === null) {
         return;
     }
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     if ($operation->getData('api-key-authentication') === true) {
         $query = $event->getRequest()->getQuery();
         $query->add('api_key', $this->apiKeyToken->getApiKey());
         $query->add('developer_key', $this->apiKeyToken->getDeveloperKey());
         $query->add('client_key', $this->apiKeyToken->getClientKey());
     }
 }
コード例 #15
0
 /**
  * Add OAuth token in header when needed
  *
  * @param PreparedEvent $event
  */
 public function onPrepare(PreparedEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     // If this operation require an OAuth scope
     if ($operation->getData('scope')) {
         $token = $this->getOAuthToken($operation->getData('scope'));
         $event->getRequest()->addHeader('Authorization', sprintf('Bearer %s', $token));
     }
     // For Sso methods, client ID and secret are passed as basic auth
     if (in_array($operation->getName(), ['getSsoToken', 'refreshSsoToken'])) {
         $event->getRequest()->setHeader('Authorization', 'Basic ' . base64_encode(sprintf("%s:%s", $this->config['ssoClientId'], $this->config['ssoSecret'])));
         $event->getRequest()->setHeader('Accept', 'application/json');
     }
 }
コード例 #16
0
 public function setMd5(PreparedEvent $event)
 {
     $client = $event->getClient();
     $command = $event->getCommand();
     $body = $event->getRequest()->getBody();
     // If ContentMD5 is set or there is no body, there is nothing to do.
     if ($command['ContentMD5'] || !$body) {
         return;
     }
     // If and MD5 is required or enabled, add one.
     $optional = $client->getConfig('calculate_md5') && in_array($command->getName(), self::$canMd5);
     if (in_array($command->getName(), self::$requireMd5) || $optional) {
         // Throw exception is calculating and MD5 would result in an error.
         if (!$body->isSeekable()) {
             throw new CouldNotCreateChecksumException('md5');
         }
         // Set the Content-MD5 header.
         $event->getRequest()->setHeader('Content-MD5', base64_encode(Utils::hash($body, 'md5', true)));
     }
 }
コード例 #17
0
 /**
  * Changes how buckets are referenced in the HTTP request
  *
  * @param PreparedEvent $event Event emitted
  */
 public function setBucketStyle(PreparedEvent $event)
 {
     $command = $event->getCommand();
     $request = $event->getRequest();
     $bucket = $command['Bucket'];
     $path = $request->getPath();
     if (!$bucket || isset(self::$exclusions[$command->getName()])) {
         return;
     }
     if ($this->bucketEndpoint) {
         $path = $this->removeBucketFromPath($path, $bucket);
     } elseif (!$command['PathStyle'] && S3Client::isBucketDnsCompatible($bucket) && !($request->getScheme() == 'https' && strpos($bucket, '.'))) {
         // Switch to virtual if PathStyle is disabled, or not a DNS
         // compatible bucket name, or the scheme is https and there are no
         // dots in the hostheader (avoids SSL issues).
         $request->setHost($bucket . '.' . $request->getHost());
         $path = $this->removeBucketFromPath($path, $bucket);
     }
     // Modify the Key to make sure the key is encoded, but slashes are not.
     if ($command['Key']) {
         $path = S3Client::encodeKey(rawurldecode($path));
     }
     $request->setPath($path);
 }
コード例 #18
0
 public function onPrepared(PreparedEvent $event)
 {
     // no requests have a body but EAN/Akamai still requires this header
     $event->getRequest()->setHeader('Content-Length', '0');
 }
コード例 #19
0
 public function setCredentials(PreparedEvent $event)
 {
     $request = $event->getRequest();
     $request->addHeaders($this->credentials->toArray());
 }