Example #1
0
 function call($httpMethod, $service_name, $service_method, $params = array())
 {
     if (!$this->client->getBearer()) {
         $options = ['form_params' => ['grant_type' => 'client_credentials', 'client_id' => $this->client->getClientId(), 'client_secret' => $this->client->getClientSecret()], 'http_errors' => false];
         $response = $this->http_client->request('POST', $this->end_point_oauth, $options);
         if ($response->getStatusCode() != 200) {
             throw new Exception('Can\'t fetch access token');
         }
         $json = json_decode($response->getBody());
         $this->client->setBearer($json->access_token, $json->expires_in);
     }
     $path = self::getPath($service_name, $service_method);
     $first_get = false;
     foreach ($params as $name => $value) {
         $search = '{' . $name . '}';
         if (stripos($path, $search)) {
             $path = str_ireplace($search, $value, $path);
         } else {
             if (mb_strtoupper($httpMethod) == 'GET') {
                 $path .= (!$first_get ? '?' : '&') . $name . '=' . $value;
                 $first_get = true;
             }
         }
     }
     return $this->http_client->request($httpMethod, $this->end_point . $path, ['headers' => $this->getHeaders()]);
 }
Example #2
0
 /**
  * @group restore
  */
 public function testCloneBeforeDateBaculaToTmp()
 {
     print "\n" . __METHOD__ . ' ';
     $this->_rootLogin();
     // запоминаем данные в сессии
     $this->restoreNamespace->typeRestore = 'restore_recent';
     $this->restoreNamespace->JobId = null;
     $this->restoreNamespace->ClientNameFrom = 'local.fd';
     $this->restoreNamespace->FileSet = 'fileset.test.1';
     $this->restoreNamespace->DateBefore = date("Y-m-d H:i:s", time());
     // поиск ClientId
     $client = new Client();
     $this->restoreNamespace->ClientIdFrom = $client->getClientId($this->restoreNamespace->ClientNameFrom);
     // поиск JobId
     $job = new Job();
     $date_before = " AND Job.StartTime<'" . $this->restoreNamespace->DateBefore . "'";
     $ajobs = $job->getJobBeforeDate($date_before, $this->restoreNamespace->ClientIdFrom, $this->restoreNamespace->FileSet);
     $this->assertTrue(isset($ajobs), __FUNCTION__ . " No Full backup found");
     // запоминаем данные о jobids в сессии
     $this->restoreNamespace->JobHash = md5($ajobs['hash']);
     $this->restoreNamespace->aJobId = $ajobs['ajob_all'];
     $this->assertTrue($ajobs['ajob_all'][0] == 2 && $ajobs['ajob_all'][1] == 8 && $ajobs['ajob_all'][2] == 15 && sizeof($ajobs['ajob_all']) == 3, __FUNCTION__ . " 'Id=2  Full, Id=8  Diff, Id = 15 Inc' expected");
     $sjobids = implode(",", $this->restoreNamespace->aJobId);
     // собственно клонирование
     $this->WbTmpTableRecent = new WbTmpTable($this->restoreNamespace->JobHash, $this->ttl_restore_session);
     $this->WbTmpTableRecent->cloneRecentBaculaToTmp($sjobids);
     // проверяем кол-во файлов и т.д.
     $res = $this->WbTmpTableRecent->getCountFile();
     $this->assertTrue($res == 1211, __FUNCTION__ . " failed (count files = {$res})");
     // удаление временных таблиц
     $this->WbTmpTableRecent->deleteAllTmpTables();
     // проверяем удаление
     $this->assertFalse($this->WbTmpTableRecent->isAllTmpTablesExists(), __FUNCTION__ . " temporary tables not deleted");
 }
 public function testSetClientId()
 {
     $client = new Client(array('client_id' => self::CLIENT_ID, 'client_secret' => self::CLIENT_SECRET));
     $client->setClientId('dummy');
     $this->assertEquals($client->getClientId(), 'dummy', 'Expect the Client ID to be dummy.');
 }
Example #4
0
 /**
  *  with Bacula ACLs
  */
 function selectBackupsBeforeDateAction()
 {
     // session expired ?
     if (!isset($this->restoreNamespace->isSessionExist)) {
         echo $this->renderScript('restorejob/msg02session.phtml');
         return;
     }
     Zend_Loader::loadClass('Client');
     Zend_Loader::loadClass('Job');
     // поиск ClientId
     $client = new Client();
     $this->restoreNamespace->ClientIdFrom = $client->getClientId($this->restoreNamespace->ClientNameFrom);
     if (!empty($this->restoreNamespace->DateBefore)) {
         $date_before = " AND Job.StartTime<='" . $this->restoreNamespace->DateBefore . "'";
     } else {
         $date_before = '';
     }
     $job = new Job();
     $ajobs = $job->getJobBeforeDate($date_before, $this->restoreNamespace->ClientIdFrom, $this->restoreNamespace->FileSet);
     // with Bacula ACLs
     if (!$ajobs) {
         // сообщение, что не найден Full backup: No Full backup before 2009-05-20 15:19:49 found.
         $this->view->msg = sprintf($this->view->translate->_("No Full backup before %s found."), $this->restoreNamespace->DateBefore);
         echo $this->renderScript('msg-note.phtml');
         return;
     }
     /* запоминаем данные о jobids в сессии */
     $this->restoreNamespace->JobHash = md5($ajobs['hash']);
     $this->restoreNamespace->aJobId = $ajobs['ajob_all'];
     $this->view->ajob_full = $ajobs['ajob_full'];
     $this->view->ajob_diff = $ajobs['ajob_diff'];
     $this->view->ajob_inc = $ajobs['ajob_inc'];
     $this->view->ajob_all = $ajobs['ajob_all'];
     $this->view->title = $this->view->translate->_("You have selected the following JobIds");
     $this->view->beginrecent = 1;
     $this->render();
 }