From 92d63f381401fda8d2ed1ccc7f2e53f7146c4740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Tue, 3 Jan 2017 22:43:08 -0300 Subject: [PATCH] [Nostromo] If user is not defined, get current running user --- src/Mage/Runtime/Runtime.php | 11 +++++++++++ src/Mage/Task/BuiltIn/Deploy/RsyncTask.php | 2 +- src/Mage/Task/BuiltIn/Deploy/TarGz/CopyTask.php | 2 +- src/Mage/Tests/Runtime/RuntimeTest.php | 10 ++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Mage/Runtime/Runtime.php b/src/Mage/Runtime/Runtime.php index cab246d..8ec0036 100644 --- a/src/Mage/Runtime/Runtime.php +++ b/src/Mage/Runtime/Runtime.php @@ -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']; + } } diff --git a/src/Mage/Task/BuiltIn/Deploy/RsyncTask.php b/src/Mage/Task/BuiltIn/Deploy/RsyncTask.php index da5fd04..5ae69ae 100644 --- a/src/Mage/Task/BuiltIn/Deploy/RsyncTask.php +++ b/src/Mage/Task/BuiltIn/Deploy/RsyncTask.php @@ -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, '/'); diff --git a/src/Mage/Task/BuiltIn/Deploy/TarGz/CopyTask.php b/src/Mage/Task/BuiltIn/Deploy/TarGz/CopyTask.php index ba16706..03201d1 100644 --- a/src/Mage/Task/BuiltIn/Deploy/TarGz/CopyTask.php +++ b/src/Mage/Task/BuiltIn/Deploy/TarGz/CopyTask.php @@ -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'), '/'); diff --git a/src/Mage/Tests/Runtime/RuntimeTest.php b/src/Mage/Tests/Runtime/RuntimeTest.php index 020bcc4..d8c4c84 100644 --- a/src/Mage/Tests/Runtime/RuntimeTest.php +++ b/src/Mage/Tests/Runtime/RuntimeTest.php @@ -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()); + } }