-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(issue-30): use uid/gid from --user with --deploy copy
during pipelines `--deploy copy` respect a `--user <uid>[:gid]` by adding tar flags `--numeric-owner --owner=:<uid> [--group=:<gid>]` to the tar creations.
- Loading branch information
Showing
9 changed files
with
224 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* this file is part of pipelines */ | ||
|
||
namespace Ktomk\Pipelines\Runner\Opts; | ||
|
||
use Ktomk\Pipelines\Preg; | ||
|
||
/** | ||
* <name|uid>[:<group|gid>] | ||
* | ||
* from --user[=<name|uid>[:<group|gid>]] | ||
*/ | ||
final class User | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $user; | ||
|
||
/** | ||
* @param non-empty-string $user | ||
* | ||
* @return self | ||
*/ | ||
public function __construct($user) | ||
{ | ||
$this->user = $user; | ||
} | ||
|
||
/** | ||
* @return array{0: int, 1: int|null} | ||
*/ | ||
public function toUidGidArray() | ||
{ | ||
list($user, $group) = explode(':', $this->user, 2) + array(null, null); | ||
|
||
/* --user=0:0 */ | ||
if ($this->isId($user) && $this->isId($group)) { | ||
return array((int)$user, (int)$group); | ||
} | ||
|
||
/* --user=0 */ | ||
if ($this->isId($user) && null === $group) { | ||
return array((int)$user, $group); | ||
} | ||
|
||
/* --user=name[:group] */ | ||
$match = Preg::match('/^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]?$/', $user); | ||
if (0 === $match) { | ||
throw new \RuntimeException(sprintf('illegal username: %s', addcslashes($user, "\0..\40'\177..\377"))); | ||
} | ||
|
||
throw new \RuntimeException(sprintf('unable to find user %s: there is no owner and group map. use numeric user/group ids instead.', $user)); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return $this->user; | ||
} | ||
|
||
/** | ||
* @param string $subject | ||
* | ||
* @return bool | ||
*/ | ||
private function isId($subject) | ||
{ | ||
return ( | ||
$subject === (string)(int)$subject | ||
&& '-' !== $subject[0] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* this file is part of pipelines */ | ||
|
||
namespace Ktomk\Pipelines\Runner\Opts; | ||
|
||
use Ktomk\Pipelines\TestCase; | ||
|
||
/** | ||
* @covers \Ktomk\Pipelines\Runner\Opts\User | ||
*/ | ||
class UserTest extends TestCase | ||
{ | ||
public function testCreation() | ||
{ | ||
$user = new User('0'); | ||
self::assertNotNull($user); | ||
} | ||
|
||
public function testUserToString() | ||
{ | ||
$user = new User('0'); | ||
self::assertSame('0', $user->toString()); | ||
} | ||
|
||
public function testUserToUidGidOptional() | ||
{ | ||
$user = new User('0'); | ||
$actual = $user->toUidGidArray(); | ||
self::assertSame(array(0, null), $actual); | ||
} | ||
|
||
public function testUserToUidGid() | ||
{ | ||
$user = new User('0:0'); | ||
$actual = $user->toUidGidArray(); | ||
self::assertSame(array(0, 0), $actual); | ||
} | ||
|
||
public function testUserToUidLetsNotPassMinusInFront() | ||
{ | ||
$user = new User('-0'); | ||
$this->expectException('RuntimeException'); | ||
$this->expectExceptionMessage('illegal username: -0'); | ||
$user->toUidGidArray(); | ||
} | ||
|
||
public function testUserToUidGidThrowsInUsernameBecauseNoMaps() | ||
{ | ||
$user = new User('uname'); | ||
$this->expectException('RuntimeException'); | ||
$this->expectExceptionMessage('unable to find user uname: there is no owner and group map. use numeric user/group ids instead.'); | ||
$user->toUidGidArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters