Skip to content

Commit

Permalink
Alters container to include cloudapi
Browse files Browse the repository at this point in the history
  • Loading branch information
typhonius committed Mar 21, 2020
1 parent 8c0f008 commit c10e264
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 55 deletions.
2 changes: 2 additions & 0 deletions src/AcquiaCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function __construct(Config $config, InputInterface $input = null, Output

// Create and configure container.
$container = Robo::createDefaultContainer($input, $output, $application, $config);
$container->add('cloudApi', \AcquiaCli\CloudApi::class)
->withArgument('config');

$discovery = new CommandFileDiscovery();
$discovery->setSearchPattern('*Command.php');
Expand Down
47 changes: 47 additions & 0 deletions src/CloudApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace AcquiaCli;

use AcquiaCloudApi\Connector\Client;
use AcquiaCloudApi\Connector\Connector;

/**
* Class CloudApi
* @package AcquiaCli
*/
final class CloudApi
{

private $cloudapi;

public function __construct($config)
{

$extraConfig = $config->get('extraconfig');
$acquia = $config->get('acquia');

if (getenv('ACQUIACLI_KEY') && getenv('ACQUIACLI_SECRET')) {
$acquia['key'] = getenv('ACQUIACLI_KEY');
$acquia['secret'] = getenv('ACQUIACLI_SECRET');
}

$connector = new Connector([
'key' => $acquia['key'],
'secret' => $acquia['secret'],
]);
/** @var \AcquiaCloudApi\Connector\Client $cloudapi */
$cloudapi = Client::factory($connector);

$this->setCloudApi($cloudapi);
}

public function getCloudApi()
{
return $this->cloudapi;
}

public function setCloudApi($cloudapi)
{
$this->cloudapi = $cloudapi;
}
}
2 changes: 1 addition & 1 deletion src/Commands/AccountCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct()
{
parent::__construct();

$this->accountAdapter = new Account($this->cloudapi);
$this->accountAdapter = new Account($this->getCloudApi());
}

/**
Expand Down
57 changes: 25 additions & 32 deletions src/Commands/AcquiaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ abstract class AcquiaCommand extends Tasks
// @TODO https://github.com/boedah/robo-drush/issues/18
//use \Boedah\Robo\Task\Drush\loadTasks;

/** @var \AcquiaCloudApi\Connector\Client $cloudapi */
protected $cloudapi;

/** Additional configuration. */
protected $extraConfig;

Expand All @@ -57,32 +54,28 @@ abstract class AcquiaCommand extends Tasks
*/
public function __construct()
{
$extraConfig = Robo::config()->get('extraconfig');
$this->extraConfig = $extraConfig;

$acquia = Robo::config()->get('acquia');
$config = Robo::config();
$this->extraConfig = $config->get('extraconfig');

// Allows for environment variables for the key and secret
// to override configuration values.
if (getenv('ACQUIACLI_KEY') && getenv('ACQUIACLI_SECRET')) {
$acquia['key'] = getenv('ACQUIACLI_KEY');
$acquia['secret'] = getenv('ACQUIACLI_SECRET');
}
$this->setTableStyles();
}

$connector = new Connector([
'key' => $acquia['key'],
'secret' => $acquia['secret'],
]);
/** @var \AcquiaCloudApi\Connector\Client $cloudapi */
$cloudapi = Client::factory($connector);
public function getCloudApi()
{
$cloudapi = Robo::service('cloudApi')->getCloudApi();
return $cloudapi;
}

$this->setCloudApi($cloudapi);
$this->setTableStyles();
public function getEnvironments()
{
$environments = Robo::service('cloudApi')->getEnvironments();
return $environments;
}

public function setCloudApi($cloudapi)
public function getApplications()
{
$this->cloudapi = $cloudapi;
$applications = Robo::service('cloudApi')->getApplications();
return $applications;
}

/**
Expand Down Expand Up @@ -165,7 +158,7 @@ public function validateUuidHook(CommandData $commandData)
*/
protected function getEnvironmentFromEnvironmentName($uuid, $environment)
{
$environmentsAdapter = new Environments($this->cloudapi);
$environmentsAdapter = $this->getEnvironments();
$environments = $environmentsAdapter->getAll($uuid);

foreach ($environments as $e) {
Expand All @@ -184,7 +177,7 @@ protected function getEnvironmentFromEnvironmentName($uuid, $environment)
*/
protected function getOrganizationFromOrganizationName($organizationName)
{
$org = new Organizations($this->cloudapi);
$org = new Organizations($this->getCloudApi());
$organizations = $org->getAll();

foreach ($organizations as $organization) {
Expand All @@ -203,7 +196,7 @@ protected function getOrganizationFromOrganizationName($organizationName)
*/
protected function getUuidFromHostingName($name)
{
$app = new Applications($this->cloudapi);
$app = $this->getApplications();
$applications = $app->getAll();

foreach ($applications as $application) {
Expand Down Expand Up @@ -245,7 +238,7 @@ protected function waitForNotification($response)
$progress->setMessage('Looking up notification');
$progress->start();

$notificationAdapter = new Notifications($this->cloudapi);
$notificationAdapter = new Notifications($this->getCloudApi());

while (true) {
$progress->advance($sleep);
Expand Down Expand Up @@ -295,7 +288,7 @@ protected function waitForNotification($response)
*/
protected function backupAndMoveDbs($uuid, $environmentFrom, $environmentTo)
{
$dbAdapter = new Databases($this->cloudapi);
$dbAdapter = new Databases($this->getCloudApi());
$databases = $dbAdapter->getAll($uuid);
foreach ($databases as $database) {
$this->backupDb($uuid, $environmentTo, $database);
Expand All @@ -310,7 +303,7 @@ protected function backupAndMoveDbs($uuid, $environmentFrom, $environmentTo)
)
);

$databaseAdapter = new Databases($this->cloudapi);
$databaseAdapter = new Databases($this->getCloudApi());
$response = $databaseAdapter->copy($environmentFrom->uuid, $database->name, $environmentTo->uuid);
$this->waitForNotification($response);
}
Expand All @@ -322,7 +315,7 @@ protected function backupAndMoveDbs($uuid, $environmentFrom, $environmentTo)
*/
protected function backupAllEnvironmentDbs($uuid, EnvironmentResponse $environment)
{
$dbAdapter = new Databases($this->cloudapi);
$dbAdapter = new Databases($this->getCloudApi());
$databases = $dbAdapter->getAll($uuid);
foreach ($databases as $database) {
$this->backupDb($uuid, $environment, $database);
Expand All @@ -338,7 +331,7 @@ protected function backupDb($uuid, EnvironmentResponse $environment, DatabaseRes
{
// Run database backups.
$this->say(sprintf('Backing up DB (%s) on %s', $database->name, $environment->label));
$dbAdapter = new DatabaseBackups($this->cloudapi);
$dbAdapter = new DatabaseBackups($this->getCloudApi());
$response = $dbAdapter->create($environment->uuid, $database->name);
$this->waitForNotification($response);
}
Expand All @@ -350,7 +343,7 @@ protected function backupDb($uuid, EnvironmentResponse $environment, DatabaseRes
*/
protected function copyFiles($uuid, $environmentFrom, $environmentTo)
{
$environmentsAdapter = new Environments($this->cloudapi);
$environmentsAdapter = $this->getEnvironments();
$this->say(sprintf('Copying files from %s to %s', $environmentFrom->label, $environmentTo->label));
$response = $environmentsAdapter->copyFiles($environmentFrom->uuid, $environmentTo->uuid);
$this->waitForNotification($response);
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/ApplicationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public function __construct()
{
parent::__construct();

$this->applicationsAdapter = new Applications($this->cloudapi);
$this->environmentsAdapter = new Environments($this->cloudapi);
$this->databasesAdapter = new Databases($this->cloudapi);
$this->applicationsAdapter = new Applications($this->getCloudApi());
$this->environmentsAdapter = new Environments($this->getCloudApi());
$this->databasesAdapter = new Databases($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/CodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct()
{
parent::__construct();

$this->codeAdapter = new Code($this->cloudapi);
$this->codeAdapter = new Code($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/CronCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct()
{
parent::__construct();

$this->cronAdapter = new Crons($this->cloudapi);
$this->cronAdapter = new Crons($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DbBackupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct()
{
parent::__construct();

$this->databaseBackupsAdapter = new DatabaseBackups($this->cloudapi);
$this->databaseBackupsAdapter = new DatabaseBackups($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DbCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct()
{
parent::__construct();

$this->databaseAdapter = new Databases($this->cloudapi);
$this->databaseAdapter = new Databases($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/DomainCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct()
{
parent::__construct();

$this->domainAdapter = new Domains($this->cloudapi);
$this->domainAdapter = new Domains($this->getCloudApi());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/EnvironmentsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function __construct()
{
parent::__construct();

$this->environmentsAdapter = new Environments($this->cloudapi);
$this->serversAdapter = new Servers($this->cloudapi);
$this->environmentsAdapter = new Environments($this->getCloudApi());
$this->serversAdapter = new Servers($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/InsightsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
{
parent::__construct();

$this->insightsAdapter = new Insights($this->cloudapi);
$this->insightsAdapter = new Insights($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/LogsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct()
{
parent::__construct();

$this->logsAdapter = new Logs($this->cloudapi);
$this->logsAdapter = new Logs($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/NotificationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __construct()
{
parent::__construct();

$this->notificationsAdapter = new Notifications($this->cloudapi);
$this->notificationsAdapter = new Notifications($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/OrganizationsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct()
{
parent::__construct();

$this->organizationsAdapter = new Organizations($this->cloudapi);
$this->organizationsAdapter = new Organizations($this->getCloudApi());
}

/**
Expand Down
21 changes: 17 additions & 4 deletions src/Commands/SshCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,26 @@ class SshCommand extends EnvironmentsCommand
public function sshInfo($uuid, $env = null)
{

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

$environments = $this->environmentsAdapter->getAll($uuid);

$this->cloudapi->clearQuery();
// $a = new \stdClass;
// $a->name = 'foo';
// $a->sshUrl = 'hello';

// $b = new \stdClass;
// $b->name = 'foo';
// $b->sshUrl = 'hello';

// $environments = [
// 1 => $a,
// 2 => $b
// ];
// $this->cloudapi->clearQuery();
var_dump($environments);

foreach ($environments as $e) {
/** @var $e EnvironmentResponse */
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/TeamsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function __construct()
{
parent::__construct();

$this->teamsAdapter = new Teams($this->cloudapi);
$this->rolesAdapter = new Roles($this->cloudapi);
$this->permissionsAdapter = new Permissions($this->cloudapi);
$this->teamsAdapter = new Teams($this->getCloudApi());
$this->rolesAdapter = new Roles($this->getCloudApi());
$this->permissionsAdapter = new Permissions($this->getCloudApi());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/VariablesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct()
{
parent::__construct();

$this->variablesAdapter = new Variables($this->cloudapi);
$this->variablesAdapter = new Variables($this->getCloudApi());
}

/**
Expand Down

0 comments on commit c10e264

Please sign in to comment.