-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
110 additions
and
56 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?php | ||
namespace Platformsh\Cli\Command\User; | ||
|
||
use Platformsh\Cli\Util\ActivityUtil; | ||
use Platformsh\Client\Model\Activity; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
@@ -16,7 +18,8 @@ protected function configure() | |
->setName('user:add') | ||
->setDescription('Add a user to the project') | ||
->addArgument('email', InputArgument::OPTIONAL, "The new user's email address") | ||
->addOption('role', null, InputOption::VALUE_REQUIRED, "The new user's role: 'admin' or 'viewer'"); | ||
->addOption('role', null, InputOption::VALUE_REQUIRED, "The new user's role: 'admin' or 'viewer'") | ||
->addOption('wait', null, InputOption::VALUE_NONE, 'Wait for environment(s) to be redeployed, if necessary'); | ||
$this->addProjectOption(); | ||
$this->addExample('Add Alice as a new administrator', '[email protected] --role admin'); | ||
} | ||
|
@@ -106,7 +109,26 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
} | ||
} | ||
|
||
$project->addUser($email, $projectRole); | ||
$this->stdErr->writeln("Adding the user to the project"); | ||
$user = $project->addUser($email, $projectRole); | ||
|
||
if (!empty($environmentRoles)) { | ||
$this->stdErr->writeln("Setting environment role(s)"); | ||
$activities = []; | ||
foreach ($environmentRoles as $environmentId => $role) { | ||
if (!isset($environments[$environmentId])) { | ||
$this->stdErr->writeln("<error>Environment not found: $environmentId</error>"); | ||
continue; | ||
} | ||
$result = $user->changeEnvironmentRole($environments[$environmentId], $role); | ||
if ($result instanceof Activity) { | ||
$activities[] = $result; | ||
} | ||
} | ||
if ($input->getOption('wait')) { | ||
ActivityUtil::waitMultiple($activities, $this->stdErr, 'Waiting for environment(s) to be redeployed'); | ||
} | ||
} | ||
|
||
$this->stdErr->writeln("User <info>$email</info> created"); | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<?php | ||
namespace Platformsh\Cli\Command\User; | ||
|
||
use Platformsh\Cli\Util\ActivityUtil; | ||
use Platformsh\Client\Model\Activity; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
@@ -17,7 +19,8 @@ protected function configure() | |
->addArgument('email', InputArgument::REQUIRED, "The user's email address") | ||
->addOption('role', 'r', InputOption::VALUE_REQUIRED, "A new role for the user") | ||
->addOption('level', 'l', InputOption::VALUE_REQUIRED, "The role level ('project' or 'environment')", 'project') | ||
->addOption('pipe', null, InputOption::VALUE_NONE, 'Output the role only'); | ||
->addOption('pipe', null, InputOption::VALUE_NONE, 'Output the role only') | ||
->addOption('wait', null, InputOption::VALUE_NONE, 'Wait for environment(s) to be redeployed, if necessary'); | ||
$this->addProjectOption() | ||
->addEnvironmentOption(); | ||
$this->addExample("View Alice's role on the project", '[email protected]'); | ||
|
@@ -85,8 +88,16 @@ protected function execute(InputInterface $input, OutputInterface $output) | |
$this->stdErr->writeln("User <info>$email</info> updated"); | ||
} | ||
elseif ($role && $level == 'environment') { | ||
$selectedUser->changeEnvironmentRole($this->getSelectedEnvironment(), $role); | ||
$result = $selectedUser->changeEnvironmentRole($this->getSelectedEnvironment(), $role); | ||
$this->stdErr->writeln("User <info>$email</info> updated"); | ||
if ($input->getOption('wait') && $result instanceof Activity) { | ||
ActivityUtil::waitAndLog( | ||
$result, | ||
$this->stdErr, | ||
'Environment redeployed successfully', | ||
'Failed to redeploy environment' | ||
); | ||
} | ||
} | ||
|
||
if ($input->getOption('pipe')) { | ||
|
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,31 @@ | ||
<?php | ||
|
||
namespace Platformsh\Cli\Exception; | ||
|
||
use GuzzleHttp\Message\RequestInterface; | ||
use GuzzleHttp\Message\ResponseInterface; | ||
use Platformsh\Client\Exception\ApiResponseException; | ||
|
||
class HttpException extends \RuntimeException | ||
{ | ||
protected $message = 'An API error occurred.'; | ||
|
||
/** | ||
* @param string $message | ||
* @param RequestInterface $request | ||
* @param ResponseInterface $response | ||
*/ | ||
public function __construct($message = null, RequestInterface $request = null, ResponseInterface $response = null) | ||
{ | ||
$message = $message ?: $this->message; | ||
if ($request !== null && $response !== null) { | ||
$details = "[url] " . $request->getUrl(); | ||
$details .= " [status code] " . $response->getStatusCode(); | ||
$details .= " [reason phrase] " . $response->getReasonPhrase(); | ||
$details .= ApiResponseException::getErrorDetails($response); | ||
$message .= "\nDetails:\n " . wordwrap($details); | ||
} | ||
|
||
parent::__construct($message, $this->code); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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