Exemple #1
0
 /**
  * @param string $configPath
  */
 public function loadData($configPath)
 {
     $data = $this->parser->parse($this->loader->load($configPath));
     if (!is_array($data)) {
         throw new \RuntimeException('Error parsing config file');
     }
     $this->data = $data;
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $playbookFile = $input->getOption('playbook');
     $playbook = $this->fileLoader->load($playbookFile);
     $this->variablesPlacer->setVars(Registry::get('container')['argv_parser']->all());
     $this->variablesPlacer->setText($playbook);
     $playbook = $this->variablesPlacer->place();
     $url = sprintf('http://%s:%d/playbook/run/', $input->getOption('host'), $input->getOption('port'));
     $response = $this->curlRequest->getCurlResult($url, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['playbook' => urlencode($playbook), 'filename' => $playbookFile], CURLOPT_TIMEOUT_MS => 100000]);
     echo $response['body'];
 }
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->logPath = $input->getOption('log');
     $cronInfoUrl = sprintf('http://%s:%d/info/cron/', $input->getOption('host'), $input->getOption('port'));
     $response = json_decode($this->curlRequest->getCurlResult($cronInfoUrl, [CURLOPT_TIMEOUT_MS => 100000])['body'], true);
     if (!is_array($response)) {
         $this->log('Core connection failed, exiting');
         throw new \RuntimeException('Error connecting to core server');
     }
     foreach ($response as $cronItem) {
         $this->cronExpression->setExpression(Ar::get($cronItem, 'time'));
         if ($this->cronExpression->isDue()) {
             $this->log('Executing: ' . Ar::get($cronItem, 'type'));
             switch (Ar::get($cronItem, 'type')) {
                 case 'playbook':
                     $url = sprintf('http://%s:%d/playbook/run/', $input->getOption('host'), $input->getOption('port'));
                     $playbookFile = Ar::get($cronItem, 'playbook');
                     $playbook = $this->fileLoader->load($playbookFile);
                     $this->curlRequest->getCurlResult($url, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['playbook' => urlencode($playbook), 'filename' => $playbookFile], CURLOPT_TIMEOUT_MS => 100000]);
                     $this->log('Executed playbook: ' . $playbookFile);
                     break;
                 case 'command':
                     $url = sprintf('http://%s:%d/command/run/', $input->getOption('host'), $input->getOption('port'));
                     $command = Ar::get($cronItem, 'command');
                     if (null === $command) {
                         break;
                     }
                     $this->curlRequest->getCurlResult($url, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['command' => urlencode($command)], CURLOPT_TIMEOUT_MS => 100000]);
                     $this->log('Executed command: ' . $command);
                     break;
                 case 'curl':
                     break;
             }
         }
     }
 }
 /**
  * @test
  */
 public function shouldThrowExceptionOnNonExistentFile()
 {
     $this->setExpectedException('\\Exception', 'File file.txt is not accessible');
     $loader = new FileLoader();
     $loader->load('file.txt');
 }