Browse Source

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

pull/1/head
Andrés Montañez 8 years ago
parent
commit
92d63f3814
  1. 11
      src/Mage/Runtime/Runtime.php
  2. 2
      src/Mage/Task/BuiltIn/Deploy/RsyncTask.php
  3. 2
      src/Mage/Task/BuiltIn/Deploy/TarGz/CopyTask.php
  4. 10
      src/Mage/Tests/Runtime/RuntimeTest.php

11
src/Mage/Runtime/Runtime.php

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

2
src/Mage/Task/BuiltIn/Deploy/RsyncTask.php

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

2
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); 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(); $host = $this->runtime->getWorkingHost();
$sshConfig = $sshConfig = $this->runtime->getSSHConfig(); $sshConfig = $sshConfig = $this->runtime->getSSHConfig();
$hostPath = rtrim($this->runtime->getEnvironmentConfig('host_path'), '/'); $hostPath = rtrim($this->runtime->getEnvironmentConfig('host_path'), '/');

10
src/Mage/Tests/Runtime/RuntimeTest.php

@ -154,4 +154,14 @@ class RuntimeTest extends TestCase
$process = $runtime->runLocalCommand('false'); $process = $runtime->runLocalCommand('false');
$this->assertFalse($process->isSuccessful()); $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());
}
} }

Loading…
Cancel
Save