Ejemplo n.º 1
0
 /**
  * @param string $backend
  * @return Server
  */
 public function getServer($backend)
 {
     switch ($backend) {
         case 'docker':
             return new Docker($this->registry, $this->storageApi->getClient());
         default:
             throw new UserException("Backend '{$backend}' not found. Possible typo in URL?");
     }
 }
Ejemplo n.º 2
0
 protected function initStorageApiClient()
 {
     try {
         $this->storageApiClient = $this->storageApiService->getClient();
     } catch (NoRequestException $e) {
         // Ignore when no SAPI client setup
     } catch (UserException $e) {
         // Ignore when no SAPI client setup
     } catch (SapiException $e) {
         // Ignore when SAPI client setup is wrong
     }
 }
Ejemplo n.º 3
0
 public function create($command, array $params = [], $lockName = null)
 {
     $this->storageApiClient = $this->storageApiService->getClient();
     $tokenData = $this->storageApiService->getTokenData();
     $job = new Job($this->objectEncryptor, ['id' => $this->storageApiClient->generateId(), 'runId' => $this->storageApiClient->generateRunId($this->storageApiClient->getRunId()), 'project' => ['id' => $tokenData['owner']['id'], 'name' => $tokenData['owner']['name']], 'token' => ['id' => $tokenData['id'], 'description' => $tokenData['description'], 'token' => $this->objectEncryptor->encrypt($this->storageApiClient->getTokenString())], 'component' => $this->componentName, 'command' => $command, 'params' => $params, 'process' => ['host' => gethostname(), 'pid' => getmypid()], 'nestingLevel' => 0, 'createdTime' => date('c')], null, null, null);
     if ($lockName) {
         $job->setLockName($lockName);
     }
     $componentConfiguration = $this->getComponentConfiguration();
     if (isset($componentConfiguration['flags']) && in_array('encrypt', $componentConfiguration['flags'])) {
         $job->setEncrypted(true);
     }
     return $job;
 }
Ejemplo n.º 4
0
 public function __construct($appName, StorageApiService $storageApiService, Logger $logger)
 {
     $this->appName = $appName;
     try {
         $storageApiClient = $storageApiService->getClient();
         $this->runId = $storageApiClient->getRunId();
     } catch (NoRequestException $e) {
     } catch (UserException $e) {
     }
     $this->logger = $logger;
 }
Ejemplo n.º 5
0
 public function __construct($componentName, StorageApiService $storageApiService, Uploader $s3Uploader)
 {
     $this->componentName = $componentName;
     $this->s3Uploader = $s3Uploader;
     try {
         // does not work for some commands
         $storageApiClient = $storageApiService->getClient();
         $this->tokenData = $storageApiClient->getLogData();
         $this->runId = $storageApiClient->getRunId();
     } catch (SyrupComponentException $e) {
     } catch (SapiException $e) {
     }
 }
Ejemplo n.º 6
0
 private function initHandlerAndClient()
 {
     $request = new Request();
     $request->headers->add(['x-storageapi-token' => SYRUP_SAPI_TEST_TOKEN]);
     $requestStack = new RequestStack();
     $requestStack->push($request);
     $storageApiService = new StorageApiService('https://connection.keboola.com', $requestStack);
     $client = $storageApiService->getClient();
     $client->setRunId(uniqid());
     $handler = new StorageApiHandler(SYRUP_APP_NAME, $storageApiService);
     return [$client, $handler];
 }