Skip to content

Commit

Permalink
Converts more commands to use 2.0 and adds org conversion function.
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 21, 2020
1 parent 200cf5d commit 21ede83
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 29 deletions.
27 changes: 27 additions & 0 deletions src/Commands/AcquiaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use AcquiaCloudApi\Connector\Connector;
use AcquiaCloudApi\Endpoints\Applications;
use AcquiaCloudApi\Endpoints\Environments;
use AcquiaCloudApi\Endpoints\Organizations;
use AcquiaCloudApi\Endpoints\Notifications;
use AcquiaCloudApi\Endpoints\Databases;
use AcquiaCloudApi\Endpoints\DatabaseBackups;
Expand Down Expand Up @@ -136,6 +137,12 @@ public function validateUuidHook(CommandData $commandData)
$commandData->input()->setArgument('environmentTo', $environmentTo);
}
}
// Convert Organization name to UUID.
if ($commandData->input()->hasArgument('organization')) {
$organizationName = $commandData->input()->getArgument('organization');
$organization = $this->getOrganizationFromOrganizationName($organizationName);
$commandData->input()->setArgument('organization', $organization);
}
}

/**
Expand All @@ -158,6 +165,26 @@ protected function getEnvironmentFromEnvironmentName($uuid, $environment)
throw new Exception('Unable to find ID for environment');
}

/**
* @param string $uuid
* @param string $organization
* @return OrganizationResponse
* @throws Exception
*/
protected function getOrganizationFromOrganizationName($organizationName)
{
$org = new Organizations($this->cloudapi);
$organizations = $org->getAll($organizationName);

foreach ($organizations as $organization) {
if ($organizationName === $organization->name) {
return $organization;
}
}

throw new Exception('Unable to find ID for environment');
}

/**
* @param string $name
* @return mixed
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/CodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AcquiaCloudApi\Response\BranchResponse;
use Symfony\Component\Console\Helper\Table;
use AcquiaCloudApi\Endpoints\Code;

/**
* Class CodeCommand
Expand All @@ -26,7 +27,8 @@ public function code($uuid, $match = null)
if (null !== $match) {
$this->cloudapi->addQuery('filter', "name=@*${match}*");
}
$branches = $this->cloudapi->code($uuid);
$codeAdapter = new Code($this->cloudapi);
$branches = $codeAdapter->getAll($uuid);
$this->cloudapi->clearQuery();
$output = $this->output();
Expand Down
20 changes: 12 additions & 8 deletions src/Commands/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public function crons($uuid, $environment)
*/
public function cronAdd($uuid, $environment, $commandString, $frequency, $label)
{
$this->cloudapi->createCron($environment->uuid, $commandString, $frequency, $label);
$this->waitForTask($uuid, 'CronCreated');
$cronAdapter = new Crons($this->cloudapi);
$response = $cronAdapter->create($environment->uuid, $commandString, $frequency, $label);
$this->waitForNotification($response);
}

/**
Expand All @@ -80,8 +81,9 @@ public function cronDelete($uuid, $environment, $cronId)
if ($this->confirm("Are you sure you want to delete the cron task?")) {
$label = $environment->label;
$this->say("Deleting cron task ${cronId} from ${label}");
$this->cloudapi->deleteCron($environment->uuid, $cronId);
$this->waitForTask($uuid, 'CronDeleted');
$cronAdapter = new Crons($this->cloudapi);
$response = $cronAdapter->delete($environment->uuid, $cronId);
$this->waitForNotification($response);
}
}

Expand All @@ -96,8 +98,9 @@ public function cronDelete($uuid, $environment, $cronId)
*/
public function cronEnable($uuid, $environment, $cronId)
{
$this->cloudapi->enableCron($environment->uuid, $cronId);
$this->waitForTask($uuid, 'CronEnabled');
$cronAdapter = new Crons($this->cloudapi);
$response = $cronAdapter->enable($environment->uuid, $cronId);
$this->waitForNotification($response);
}

/**
Expand All @@ -112,8 +115,9 @@ public function cronEnable($uuid, $environment, $cronId)
public function cronDisable($uuid, $environment, $cronId)
{
if ($this->confirm("Are you sure you want to disable the cron task?")) {
$this->cloudapi->disableCron($environment->uuid, $cronId);
$this->waitForTask($uuid, 'CronDisabled');
$cronAdapter = new Crons($this->cloudapi);
$response = $cronAdapter->disable($environment->uuid, $cronId);
$this->waitForNotification($response);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/Commands/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ public function acquiaDbBackupRestore($uuid, $environment, $backupId)
*
* @param string $uuid
* @param EnvironmentResponse $environment
* @param string $dbName
* @param int $backupId
*
* @command db:backup:link
*/
public function acquiaDbBackupLink($uuid, $environment, $backupId)
public function acquiaDbBackupLink($uuid, $environment, $dbName, $backupId)
{
$environmentUuid = $environment->uuid;
$this->say(Connector::BASE_URI .
"/environments/${environmentUuid}/database-backups/${backupId}/actions/download");
"/environments/${environmentUuid}/databases/${dbName}/backups/${backupId}/actions/download");
}
}
3 changes: 2 additions & 1 deletion src/Commands/DrushAliasesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class DrushAliasesCommand extends AcquiaCommand
*/
public function downloadDrushAliases()
{
$aliases = $this->cloudapi->drushAliases();
$account = new Account($this->cloudapi);
$aliases = $account->getDrushAliases();
$tmpFile = tempnam(sys_get_temp_dir(), 'AcquiaDrushAliases') . '.tar.gz';
if (file_put_contents($tmpFile, $aliases, LOCK_EX)) {
$this->say("Acquia Cloud Drush Aliases downloaded to ${tmpFile}");
Expand Down
11 changes: 6 additions & 5 deletions src/Commands/EnvironmentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ class EnvironmentsCommand extends AcquiaCommand
public function acquiaEnvironmentInfo($uuid, $env = null)
{

// if (null !== $env) {
// $this->cloudapi->addQuery('filter', "name=${env}");
// }
if (null !== $env) {
$this->cloudapi->addQuery('filter', "name=${env}");
}

$environmentAdapter = new Environments($this->cloudapi);
$environments = $environmentAdapter->getAll($uuid);

// $this->cloudapi->clearQuery();
$this->cloudapi->clearQuery();

foreach ($environments as $e) {
$this->renderEnvironmentInfo($e);
Expand Down Expand Up @@ -147,6 +147,7 @@ protected function renderEnvironmentInfo(EnvironmentResponse $environment)
public function acquiaEnvironmentRename($uuid, $environment, $name)
{
$this->say('Renaming ' . $environment->label . " to ${name}");
$this->cloudapi->renameEnvironment($environment->uuid, $name);
$environmentAdapter = new Environments($this->cloudapi);
$environments = $environmentAdapter->rename($environment->uuid, $name);
}
}
4 changes: 3 additions & 1 deletion src/Commands/OrganizationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use AcquiaCloudApi\Response\OrganizationResponse;
use AcquiaCloudApi\Response\TeamResponse;
use Symfony\Component\Console\Helper\Table;
use AcquiaCloudApi\Endpoints\Organizations;

/**
* Class OrganizationsCommand
Expand All @@ -23,7 +24,8 @@ class OrganizationsCommand extends AcquiaCommand
*/
public function showOrganizations()
{
$organizations = $this->cloudapi->organizations();
$organizationsAdapter = new Organizations($this->cloudapi);
$organizations = $organizationsAdapter->getAll();

$table = new Table($this->output());
$table->setHeaders(['UUID', 'Organization', 'Owner', 'Subs', 'Admins', 'Users', 'Teams', 'Roles']);
Expand Down
4 changes: 3 additions & 1 deletion src/Commands/SshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace AcquiaCli\Commands;

use AcquiaCloudApi\Response\EnvironmentResponse;
use AcquiaCloudApi\Endpoints\Environments;

/**
* Class SshCommand
Expand All @@ -26,7 +27,8 @@ public function acquiaSshInfo($uuid, $env = null)
$this->cloudapi->addQuery('filter', "name=${env}");
}

$environments = $this->cloudapi->environments($uuid);
$environmentAdapter = new Environments($this->cloudapi);
$environments = $environmentAdapter->getAll($uuid);

$this->cloudapi->clearQuery();

Expand Down
35 changes: 25 additions & 10 deletions src/Commands/TeamsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace AcquiaCli\Commands;

use AcquiaCloudApi\Response\OrganizationResponse;
use AcquiaCloudApi\Response\PermissionResponse;
use AcquiaCloudApi\Response\RoleResponse;
use Symfony\Component\Console\Helper\Table;
use AcquiaCloudApi\Endpoints\Teams;
use AcquiaCloudApi\Endpoints\Permissions;
use AcquiaCloudApi\Endpoints\Roles;

/**
* Class TeamsCommand
Expand All @@ -24,7 +28,8 @@ class TeamsCommand extends AcquiaCommand
public function teamCreate($organizationUuid, $name)
{
$this->say('Creating new team.');
$this->cloudapi->createTeam($organizationUuid, $name);
$teamsAdapter = new Teams($this->cloudapi);
$teamsAdapter->create($organizationUuid, $name);
}

/**
Expand All @@ -40,7 +45,8 @@ public function teamInvite($teamUuid, $email, $roles)
{
$rolesArray = explode(',', $roles);
$this->say("Inviting ${email} to team.");
$this->cloudapi->createTeamInvite($teamUuid, $email, $rolesArray);
$teamsAdapter = new Teams($this->cloudapi);
$teamsAdapter->invite($teamUuid, $email, $rolesArray);
}

/**
Expand All @@ -65,7 +71,8 @@ public function teamAddApplication($uuid, $teamUuid)
*/
public function showPermissions()
{
$permissions = $this->cloudapi->permissions();
$permissionsAdapter = new Permissions($this->cloudapi);
$permissions = $permissionsAdapter->get();

$table = new Table($this->output());
$table->setHeaders(['Name', 'Label']);
Expand Down Expand Up @@ -99,7 +106,8 @@ public function addRole($organizationUuid, $name, $permissions, $description = n
{
$permissionsArray = explode(',', $permissions);
$this->say("Creating new role (${name}) and adding it to organisation.");
$this->cloudapi->createRole($organizationUuid, $name, $permissionsArray, $description);
$rolesAdapter = new Roles($this->cloudapi);
$rolesAdapter->create($organizationUuid, $name, $permissionsArray, $description);
}

/**
Expand All @@ -113,7 +121,8 @@ public function deleteRole($roleUuid)
{
if ($this->confirm('Are you sure you want to remove this role?')) {
$this->say('Deleting role');
$this->cloudapi->deleteRole($roleUuid);
$rolesAdapter = new Roles($this->cloudapi);
$rolesAdapter->delete($roleUuid);
}
}

Expand All @@ -130,21 +139,27 @@ public function roleUpdatePermissions($roleUuid, $permissions)
{
$permissionsArray = explode(',', $permissions);
$this->say('Updating role permissions');
$this->cloudapi->updateRole($roleUuid, $permissionsArray);
$rolesAdapter = new Roles($this->cloudapi);
$rolesAdapter->update($roleUuid, $permissions);
}

/**
* Shows all roles within an organization.
*
* @param string $organizationUuid
* @param OrganizationResponse $organization
*
* @command role:list
*/
public function showRoles($organizationUuid)
public function showRoles($organization)
{

$roles = $this->cloudapi->organizationRoles($organizationUuid);
$permissions = $this->cloudapi->permissions();
var_dump($organization);
$organizationUuid = $organization->uuid;
$rolesAdapter = new Roles($this->cloudapi);
$roles = $rolesAdapter->getAll($organizationUuid);

$permissionsAdapter = new Permissions($this->cloudapi);
$permissions = $permissionsAdapter->get();

$roleList = array_map(function ($role) {
$this->say($role->name . ': ' . $role->uuid);
Expand Down

0 comments on commit 21ede83

Please sign in to comment.