Skip to content
This repository has been archived by the owner on Sep 5, 2020. It is now read-only.

run local commands in credentials gatherer #751

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Expand Up @@ -128,14 +128,15 @@ protected function getConnectionNode($node, Fluent $connection)
->prototype('array')
->children()
->scalarNode('host')->defaultValue($connection->host)->end()
->scalarNode('port')->defaultValue($connection->port)->end()
->scalarNode('username')->defaultValue($connection->username)->end()
->scalarNode('password')->defaultValue($connection->password)->end()
->scalarNode('key')->defaultValue($connection->key)->end()
->scalarNode('keyphrase')->defaultValue($connection->keyphrase)->end()
->scalarNode('agent')->defaultTrue()->end()
->scalarNode('root_directory')
->info("The root directory where your applications will be deployed.\nThis path needs to start at the root, ie. start with a /")
->defaultValue($connection['root'])
->defaultValue($connection->root_directory)
->end()
->arrayNode('roles')
->info('The roles this server has, set to null if you do not use roles on your project')
Expand Down
27 changes: 24 additions & 3 deletions src/Rocketeer/Services/Connections/ConnectionsHandler.php
Expand Up @@ -179,9 +179,16 @@ public function isValidConnection($connection)
*/
public function getActiveConnections()
{
return $this->getConnections()->filter(function (ConnectionInterface $connection) {
$connections = $this->getConnections()->filter(function (ConnectionInterface $connection) {
return $this->isConnectionActive($connection);
});
// activate default connection if nothing was selected
if ($connections->count() == 0) {
$connections = $this->getConnections()->filter(function (ConnectionInterface $connection) {
return $this->isConnectionDefault($connection);
});
}
return $connections;
}

/**
Expand Down Expand Up @@ -212,6 +219,11 @@ public function setActiveConnections($connections)

return $connection;
});
// $this->available = $this->available->filter(function (ConnectionInterface $connection){
// if ($connection->isActive()) {
// return $connection;
// }
// });
}

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -371,14 +383,23 @@ public function setStage($stage)
* @return bool
*/
protected function isConnectionActive(ConnectionInterface $connection)
{
return $connection->isActive();
}

/**
* @param ConnectionInterface $connection
*
* @return bool
*/
protected function isConnectionDefault(ConnectionInterface $connection)
{
$connectionKey = $connection->getConnectionKey();
$defaults = $this->getDefaultConnectionsHandles();

return
in_array($connectionKey->toHandle(), $defaults, true) ||
in_array($connectionKey->name, $defaults, true) ||
$connection->isActive();
in_array($connectionKey->name, $defaults, true);
}

/**
Expand Down
Expand Up @@ -50,6 +50,8 @@ public function getCredentials()
*/
public function getRepositoryCredentials()
{
$this->rocketeer->setLocal(true);

$endpoint = $this->vcs->runLocally('currentEndpoint');
$user = $this->bash->runLocally('whoami');

Expand Down
Expand Up @@ -16,6 +16,7 @@
* Represents a connection's identity and its credential.
*
* @property string $host
* @property string $port
* @property string $username
* @property string $password
* @property string $key
Expand Down
2 changes: 2 additions & 0 deletions src/Rocketeer/Services/Connections/Shell/Modules/Binaries.php
Expand Up @@ -92,6 +92,8 @@ public function which($binary, $fallback = null, $prompt = true)
$locations[] = $fallback;
}

$locations = array_diff($locations, array(null));

// Add command prompt if possible
if ($this->hasCommand() && $prompt) {
$prompt = 'Binary "'.$binary.'" could not be found, please enter the path to it';
Expand Down
Expand Up @@ -34,6 +34,7 @@ public function getAdapter(ConnectionKey $connectionKey)

return new $adapter([
'host' => $connectionKey->host,
'port' => $connectionKey->port,
'username' => $connectionKey->username,
'password' => $connectionKey->password,
'privateKey' => $connectionKey->key,
Expand Down
21 changes: 17 additions & 4 deletions src/Rocketeer/Services/Releases/ReleasesManager.php
Expand Up @@ -109,18 +109,18 @@ public function getNonCurrentReleases()
/**
* Get an array of deprecated releases.
*
* @param int|null $treshold
* @param int|null $threshold
*
* @return int[]
*/
public function getDeprecatedReleases($treshold = null)
public function getDeprecatedReleases($threshold = null)
{
$releases = $this->getReleases();
$treshold = $treshold ?: $this->config->get('remote.keep_releases');
$threshold = $threshold ?: $this->config->get('remote.keep_releases');

// Get first X valid releases
$keep = $this->getValidReleases();
$keep = array_slice($keep, 0, $treshold);
$keep = array_slice($keep, 0, $threshold);

// Compute diff
$deprecated = array_diff($releases, $keep);
Expand All @@ -136,6 +136,19 @@ public function getDeprecatedReleases($treshold = null)
*/
public function getValidReleases()
{
$threshold = $this->config->get('remote.keep_releases');
if ($threshold) {
$keepRelease = 0;
foreach ($this->state as &$state) {
$state = true;
$keepRelease++;
if ($keepRelease >= $threshold) {
break;
}
}
unset($state);
}

$valid = array_filter($this->state);
$valid = array_keys($valid);

Expand Down