/**
  * {@inheritdoc}
  */
 public function execute($command, $workingDirectory = null, array $environmentVariables = null)
 {
     $previousWorkingDirectory = null;
     if ($workingDirectory !== null) {
         $previousWorkingDirectory = $this->connectionAdapter->getWorkingDirectory();
         $this->connectionAdapter->changeWorkingDirectory($workingDirectory);
     }
     $environment = '';
     if (isset($environmentVariables)) {
         foreach ($environmentVariables as $environmentVariableName => $environmentVariableValue) {
             $environment .= sprintf('%s=%s ', $environmentVariableName, $environmentVariableValue);
         }
     }
     $this->lastProcessExecutionResult = $this->connectionAdapter->executeCommand($environment . $command);
     if ($previousWorkingDirectory !== null) {
         $this->connectionAdapter->changeWorkingDirectory($previousWorkingDirectory);
     }
     return $this->lastProcessExecutionResult;
 }
Esempio n. 2
0
 /**
  * Update the file permissions per configured path.
  *
  * @param ConnectionAdapterInterface $connection
  * @param string                     $releasePath
  * @param string                     $path
  * @param string                     $pathSettings
  *
  * @return bool
  */
 private function updateFilePermissions(ConnectionAdapterInterface $connection, $releasePath, $path, $pathSettings)
 {
     $path = $releasePath . '/' . $path;
     if (isset($pathSettings['permissions']) === false) {
         return false;
     }
     $permissions = FilePermissionCalculator::fromStringRepresentation(str_pad($pathSettings['permissions'], 10, '-'))->getMode();
     $recursive = false;
     if (isset($pathSettings['recursive'])) {
         $recursive = $pathSettings['recursive'];
     }
     return $connection->changePermissions($path, $permissions, $recursive);
 }
 /**
  * Returns the generated YAML content based on the existing configuration file, distribution configuration file and the configuration configured with this task.
  *
  * @param ConnectionAdapterInterface $connection
  * @param string                     $stage
  * @param string                     $configurationFile
  * @param string                     $configurationDistributionFile
  *
  * @return string
  */
 private function getYamlConfiguration(ConnectionAdapterInterface $connection, $stage, $configurationFile, $configurationDistributionFile)
 {
     $configuration = array();
     if ($connection->isFile($configurationFile)) {
         $configuration = Yaml::parse($connection->getContents($configurationFile));
     }
     $distributionConfiguration = array();
     if ($connection->isFile($configurationDistributionFile)) {
         $distributionConfiguration = Yaml::parse($connection->getContents($configurationDistributionFile));
     }
     $stageSpecificConfiguration = array();
     if (isset($this->stageSpecificConfigurations[$stage])) {
         $stageSpecificConfiguration = $this->stageSpecificConfigurations[$stage];
     }
     $configuration = array_replace_recursive($distributionConfiguration, $configuration, $this->configuration, $stageSpecificConfiguration);
     foreach ($this->generateValueForParameters as $generateValueForParameter) {
         $this->findKeyAndGenerateValue($configuration, explode('.', $generateValueForParameter));
     }
     $configuration = $this->addEnvironmentVariables($configuration);
     return Yaml::dump($configuration);
 }
 /**
  * Adds an SSH key to the initialized SSH agent.
  *
  * @param Workspace                  $workspace
  * @param ConnectionAdapterInterface $connection
  * @param string                     $key
  * @param string                     $eventName
  * @param EventDispatcherInterface   $eventDispatcher
  */
 private function addKeyToSSHAgent(Workspace $workspace, ConnectionAdapterInterface $connection, $key, $eventName, EventDispatcherInterface $eventDispatcher)
 {
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Adding key to SSH agent...', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));
     $keyFile = $workspace->getHost()->getPath() . '/tmp.key';
     if ($connection->createFile($keyFile, 0700) && $connection->putContents($keyFile, $key)) {
         $result = $connection->executeCommand('ssh-add', array($keyFile));
         if ($result->isSuccessful()) {
             $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Added key to SSH agent.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
         }
         $connection->delete($keyFile);
         if ($result->isSuccessful()) {
             return;
         }
     }
     $eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Failed adding key to SSH agent.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_FAILED, 'output.resetLine' => true)));
 }