/**
  * Add API to `consumers` and encrypt the secret
  */
 public function addAction(Request $request)
 {
     $sapiToken = $this->container->get('syrup.storage_api')->getClient()->verifyToken();
     $conn = $this->getConnection();
     $api = $this->validateApiConfig(\Keboola\Utils\jsonDecode($request->getContent()));
     $sapiUrl = $this->container->getParameter('storage_api.url');
     $api->app_secret_docker = ByAppEncryption::encrypt($api->app_secret, $api->component_id, $sapiToken['token'], false, $sapiUrl);
     $api->app_secret = $this->encryptBySelf($api->app_secret);
     try {
         $conn->insert('consumers', (array) $api);
     } catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $e) {
         throw new UserException("Consumer '{$api->component_id}' already exists!");
     }
     return new JsonResponse(['status' => 'created', 'component_id' => $api->component_id], 201, $this->defaultResponseHeaders);
 }
 public function __call($name, $arguments)
 {
     try {
         return call_user_func_array([$this->client, $name], $arguments);
     } catch (GuzzleException $e) {
         $message = $e->getMessage();
         if ($e->getResponse() && $e->getResponse()->getBody()) {
             try {
                 $response = \Keboola\Utils\jsonDecode($e->getResponse()->getBody(), true);
                 if (!empty($response['message'])) {
                     $message = $response['message'];
                 }
             } catch (\Exception $e) {
             }
         }
         throw new Exception\RequestException("OAuth API error: " . $message, $e->getCode(), $e);
     }
 }
示例#3
0
 protected function apiPost($url, $options)
 {
     return \Keboola\Utils\jsonDecode($this->client->post($url, $options), $this->returnArrays);
 }