public function onInit(InitEvent $event)
 {
     $command = $event->getCommand();
     $errors = [];
     $operation = $this->description->getOperation($command->getName());
     foreach ($operation->getParams() as $name => $schema) {
         $value = $command[$name];
         if (!$this->validator->validate($schema, $value)) {
             $errors = array_merge($errors, $this->validator->getErrors());
         } elseif ($value !== $command[$name]) {
             // Update the config value if it changed and no validation
             // errors were encountered
             $command[$name] = $value;
         }
     }
     if ($params = $operation->getAdditionalParameters()) {
         foreach ($command->toArray() as $name => $value) {
             // It's only additional if it isn't defined in the schema
             if (!$operation->hasParam($name)) {
                 // Always set the name so that error messages are useful
                 $params->setName($name);
                 if (!$this->validator->validate($params, $value)) {
                     $errors = array_merge($errors, $this->validator->getErrors());
                 } elseif ($value !== $command[$name]) {
                     $command[$name] = $value;
                 }
             }
         }
     }
     if ($errors) {
         throw new CommandException('Validation errors: ' . implode("\n", $errors), $event->getTransaction());
     }
 }
 /**
  * Automatically set global configuration if provided
  *
  * @param InitEvent $event
  */
 public function onInit(InitEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     // For touristic object methods only
     if (in_array($operation->getName(), ['searchObject', 'searchObjectIdentifier', 'searchAgenda', 'searchAgendaIdentifier', 'searchDetailedAgendaIdentifier', 'searchDetailedAgenda'])) {
         $data = is_array($command['query']) ? $command['query'] : Utils::jsonDecode($command['query'], true);
         if (!empty($this->config['responseFields']) && !isset($data['responseFields'])) {
             $data['responseFields'] = $this->config['responseFields'];
         }
         if (!empty($this->config['locales']) && !isset($data['locales'])) {
             $data['locales'] = $this->config['locales'];
         }
         if (!empty($this->config['count']) && !isset($data['count'])) {
             $data['count'] = $this->config['count'];
         }
         $command['query'] = json_encode($data);
     } else {
         if ($operation->hasParam('locales') && !isset($command['locales'])) {
             $command['locales'] = implode(',', $this->config['locales']);
         }
         if ($operation->hasParam('responseFields') && !isset($command['responseFields'])) {
             $command['responseFields'] = implode(',', $this->config['responseFields']);
         }
     }
 }
 public function onInit(InitEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->api->getOperation($command->getName());
     $fn = $this->validator;
     $fn($command->getName(), $operation->getInput(), $command->toArray());
 }
 public function onInit(InitEvent $event)
 {
     $command = $event->getCommand();
     $command['cid'] = $this->cid;
     $command['apiKey'] = $this->apiKey;
     if (!empty($this->secret)) {
         $command['sig'] = $this->getSignature();
     }
 }
Пример #5
0
 public function onInit(InitEvent $event)
 {
     $c = $event->getCommand();
     if ($c->hasParam('Id')) {
         $c['Id'] = $this->cleanId($c['Id']);
     } elseif ($c->hasParam('HostedZoneId')) {
         $c['HostedZoneId'] = $this->cleanId($c['HostedZoneId']);
     }
 }
Пример #6
0
 public function authorize(InitEvent $event)
 {
     $command = $event->getCommand();
     if (false === $command->hasParam('Authorization')) {
         $command['Authorization'] = 'Token ' . $this->token;
     }
     if (false === $command->hasParam('X-Secret')) {
         $command['X-Secret'] = $this->secret;
     }
 }
Пример #7
0
 public function onInit(InitEvent $event)
 {
     $c = $event->getCommand();
     $operation = $this->api->getOperation($c->getName());
     $source = $c[$this->sourceParameter];
     if ($source !== null && $operation->getInput()->hasMember($this->bodyParameter)) {
         $c[$this->bodyParameter] = new LazyOpenStream($source, 'r');
         unset($c[$this->sourceParameter]);
     }
 }
 public function onInit(InitEvent $event)
 {
     $cmd = $event->getCommand();
     if ($cmd->getName() == 'CopySnapshot') {
         /** @var AwsClientInterface $client */
         $client = $event->getClient();
         $cmd['PresignedUrl'] = $this->createPresignedUrl($client, $cmd);
         $cmd['DestinationRegion'] = $client->getRegion();
     }
 }
Пример #9
0
 public function onInit(InitEvent $e)
 {
     $command = $e->getCommand();
     // Allows only HTTPS connections when using SSE-C
     if ($command['SSECustomerKey'] || $command['CopySourceSSECustomerKey']) {
         $this->validateScheme($e->getClient());
     }
     // Prepare the normal SSE-CPK headers
     if ($command['SSECustomerKey']) {
         $this->prepareSseParams($command);
     }
     // If it's a copy operation, prepare the SSE-CPK headers for the source.
     if ($command['CopySourceSSECustomerKey']) {
         $this->prepareSseParams($command, true);
     }
 }
 /**
  * Automatically set apiKey & projetId query parameters when needed
  *
  * @param InitEvent $event
  */
 public function onInit(InitEvent $event)
 {
     $command = $event->getCommand();
     $operation = $this->description->getOperation($command->getName());
     if ($operation->hasParam('apiKey') && !isset($command['apiKey'])) {
         $command['apiKey'] = $this->config['apiKey'];
     }
     if ($operation->hasParam('projetId') && !isset($command['projetId'])) {
         $command['projetId'] = $this->config['projectId'];
     }
     // Search operations use the authentication inside a query string JSON!
     if (in_array($operation->getName(), ['searchObject', 'searchObjectIdentifier', 'searchAgenda', 'searchAgendaIdentifier', 'searchDetailedAgendaIdentifier', 'searchDetailedAgenda', 'getReferenceCity', 'getReferenceElement', 'getReferenceInternalCriteria', 'getReferenceSelection'])) {
         $data = is_array($command['query']) ? $command['query'] : Utils::jsonDecode($command['query'], true);
         if (!isset($data['apiKey']) && !isset($data['projetId'])) {
             $data['apiKey'] = $this->config['apiKey'];
             $data['projetId'] = $this->config['projectId'];
             $command['query'] = json_encode($data);
         }
     }
 }