Example #1
0
 public function create($command, array $params = [], $lockName = null)
 {
     if (!$this->storageApiClient) {
         throw new \Exception('Storage API client must be set');
     }
     $tokenData = $this->storageApiClient->verifyToken();
     $job = new Job($this->configEncryptor, ['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->encryptor->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;
 }
 /**
  * @param $token
  * @return string
  */
 private function encryptToken($token)
 {
     if (empty($token)) {
         return $token;
     }
     if (preg_match(Token::TOKEN_REGEXP, $token)) {
         return $this->encryptor->encrypt($token);
     } else {
         return $token;
     }
 }
 public function testRunExternal()
 {
     $processedFiles = $this->storageApiClient->listFiles((new ListFilesOptions())->setTags(['wr-google-drive-processed']));
     foreach ($processedFiles as $f) {
         $this->storageApiClient->deleteFileTag($f['id'], 'wr-google-drive-processed');
     }
     $job = $this->processJob($this->componentName . '/run', ['external' => ['account' => ['email' => $this->email, 'accessToken' => $this->encryptor->encrypt($this->accessToken), 'refreshToken' => $this->encryptor->encrypt($this->refreshToken)], 'query' => '+tags:tde', 'targetFolder' => '0B8ceg4OWLR3ld0czTWxfd3RmQnc']]);
     $this->assertEquals('success', $job->getStatus());
     // test if external account was deleted
     $accounts = $this->configuration->getAccounts();
     /** @var Account $account */
     foreach ($accounts as $account) {
         $this->assertNotContains('external', $account->getAccountId());
     }
 }