[Nostromo] If user is not defined, get current running user

This commit is contained in:
Andrés Montañez 2017-01-03 22:43:08 -03:00
parent 886b7edcf6
commit 92d63f3814
4 changed files with 23 additions and 2 deletions

View file

@ -446,4 +446,15 @@ class Runtime
{
return tempnam(sys_get_temp_dir(), 'mage');
}
/**
* Get the current user
*
* @return string
*/
public function getCurrentUser()
{
$userData = posix_getpwuid(posix_geteuid());
return $userData['name'];
}
}

View file

@ -35,7 +35,7 @@ class RsyncTask extends AbstractTask
{
$flags = $this->runtime->getConfigOptions('rsync', '-avz');
$sshConfig = $this->runtime->getSSHConfig();
$user = $this->runtime->getEnvironmentConfig('user');
$user = $this->runtime->getEnvironmentConfig('user', $this->runtime->getCurrentUser());
$host = $this->runtime->getWorkingHost();
$hostPath = rtrim($this->runtime->getEnvironmentConfig('host_path'), '/');
$targetDir = rtrim($hostPath, '/');

View file

@ -37,7 +37,7 @@ class CopyTask extends AbstractTask
throw new DeploymentException('This task is only available with releases enabled', 40);
}
$user = $this->runtime->getEnvironmentConfig('user');
$user = $this->runtime->getEnvironmentConfig('user', $this->runtime->getCurrentUser());
$host = $this->runtime->getWorkingHost();
$sshConfig = $sshConfig = $this->runtime->getSSHConfig();
$hostPath = rtrim($this->runtime->getEnvironmentConfig('host_path'), '/');

View file

@ -154,4 +154,14 @@ class RuntimeTest extends TestCase
$process = $runtime->runLocalCommand('false');
$this->assertFalse($process->isSuccessful());
}
public function testCurrentUser()
{
$runtime = new Runtime();
$userData = posix_getpwuid(posix_geteuid());
$this->assertTrue(is_array($userData));
$this->assertArrayHasKey('name', $userData);
$this->assertEquals($userData['name'], $runtime->getCurrentUser());
}
}