Exemplo n.º 1
0
 public function testGetConfig()
 {
     $format = Terminus::getConfig('format');
     $this->assertEquals($format, 'normal');
     $config = Terminus::getConfig();
     $this->assertInternalType('array', $config);
 }
Exemplo n.º 2
0
 /**
  * @expectedException \Terminus\Exceptions\TerminusException
  * @expectedExceptionMessage Unknown config option "{key}".
  */
 public function testGetConfig()
 {
     $format = Terminus::getConfig('format');
     $this->assertTrue(in_array($format, ['normal', 'json', 'silent', 'bash']));
     $config = Terminus::getConfig();
     $this->assertInternalType('array', $config);
     $invalid = Terminus::getConfig('invalid');
 }
Exemplo n.º 3
0
 /**
  * Invoke `drush` commands on a Pantheon development site
  *
  * <commands>...
  * : The Drush commands you intend to run.
  *
  * [--<flag>=<value>]
  * : Additional Drush flag(s) to pass in to the command.
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon.
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 public function __invoke($args, $assoc_args)
 {
     $command = implode($args, ' ');
     $this->checkCommand($command);
     $sites = new Sites();
     $assoc_args['site'] = Input::sitename($assoc_args);
     $site = $sites->get($assoc_args['site']);
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     $assoc_args['env'] = $environment = Input::env($assoc_args);
     $server = $this->getAppserverInfo(array('site' => $site->get('id'), 'environment' => $environment));
     # Sanitize assoc args so we don't try to pass our own flags.
     # TODO: DRY this out?
     if (isset($assoc_args['site'])) {
         unset($assoc_args['site']);
     }
     if (isset($assoc_args['env'])) {
         unset($assoc_args['env']);
     }
     # Create user-friendly output
     $flags = '';
     foreach ($assoc_args as $k => $v) {
         if (isset($v) && (string) $v != '') {
             $flags .= "--{$k}={$v} ";
         } else {
             $flags .= "--{$k} ";
         }
     }
     if (in_array(Terminus::getConfig('format'), array('bash', 'json', 'silent'))) {
         $assoc_args['pipe'] = 1;
     }
     $this->log()->info("Running drush {cmd} {flags} on {site}-{env}", array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
     $result = $this->sendCommand($server, 'drush', $args, $assoc_args);
     if (Terminus::getConfig('format') != 'normal') {
         $this->output()->outputRecordList($result);
     }
 }
Exemplo n.º 4
0
 /**
  * Invoke `drush` commands on a Pantheon development site
  *
  * <commands>...
  * : The Drush commands you intend to run.
  *
  * [--<flag>=<value>]
  * : Additional Drush flag(s) to pass in to the command.
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon.
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 function __invoke($args, $assoc_args)
 {
     $environment = Input::env($assoc_args);
     $sites = new Sites();
     $site = $sites->get(Input::sitename($assoc_args));
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     $server = array('user' => "{$environment}.{$site->get('id')}", 'host' => "appserver.{$environment}.{$site->get('id')}.drush.in", 'port' => '2222');
     if (strpos(TERMINUS_HOST, 'onebox') !== FALSE) {
         $server['user'] = "******";
         $server['host'] = TERMINUS_HOST;
     }
     # Sanitize assoc args so we don't try to pass our own flags.
     # TODO: DRY this out?
     unset($assoc_args['site']);
     if (isset($assoc_args['env'])) {
         unset($assoc_args['env']);
     }
     # Create user-friendly output
     $command = implode($args, ' ');
     $flags = '';
     foreach ($assoc_args as $k => $v) {
         if (isset($v) && (string) $v != '') {
             $flags .= "--{$k}={$v} ";
         } else {
             $flags .= "--{$k} ";
         }
     }
     if (in_array(\Terminus::getConfig('format'), array('bash', 'json', 'silent'))) {
         $assoc_args['pipe'] = 1;
     }
     $this->log()->info("Running drush {cmd} {flags} on {site}-{env}", array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
     $result = $this->sendCommand($server, 'drush', $args, $assoc_args);
     if (Terminus::getConfig('format') != 'normal') {
         $this->output()->outputRecordList($result);
     }
 }
Exemplo n.º 5
0
Arquivo: wp.php Projeto: RobLoach/cli
 /**
  * Invoke `wp` commands on a Pantheon development site
  *
  * <commands>...
  * : The WP-CLI commands you intend to run.
  *
  * [--<flag>=<value>]
  * : Additional WP-CLI flag(s) to pass in to the command.
  *
  * [--site=<site>]
  * : The name (DNS shortname) of your site on Pantheon.
  *
  * [--env=<environment>]
  * : Your Pantheon environment. Default: dev
  *
  */
 function __invoke($args, $assoc_args)
 {
     $command = implode($args, ' ');
     $this->checkCommand($command);
     $sites = new Sites();
     $site = $sites->get(Input::sitename($assoc_args));
     $environment = Input::env($assoc_args);
     if (!$site) {
         $this->failure('Command could not be completed. Unknown site specified.');
     }
     # see https://github.com/pantheon-systems/titan-mt/blob/master/dashboardng/app/workshops/site/models/environment.coffee
     $server = array('user' => "{$environment}.{$site->get('id')}", 'host' => "appserver.{$environment}.{$site->get('id')}.drush.in", 'port' => '2222');
     if (strpos(TERMINUS_HOST, 'onebox') !== FALSE) {
         $server['user'] = "******";
         $server['host'] = TERMINUS_HOST;
     }
     # Sanitize assoc args so we don't try to pass our own flags.
     # TODO: DRY this out?
     unset($assoc_args['site']);
     if (isset($assoc_args['env'])) {
         unset($assoc_args['env']);
     }
     # Create user-friendly output
     $flags = '';
     foreach ($assoc_args as $k => $v) {
         if (isset($v) && (string) $v != '') {
             $flags .= "--{$k}=" . escapeshellarg($v) . ' ';
         } else {
             $flags .= "--{$k} ";
         }
     }
     $this->log()->info("Running wp {cmd} {flags} on {site}-{env}", array('cmd' => $command, 'flags' => $flags, 'site' => $site->get('name'), 'env' => $environment));
     $result = $this->sendCommand($server, 'wp', $args, $assoc_args);
     if (Terminus::getConfig('format') != 'normal') {
         $this->output()->outputRecordList($result);
     }
 }
Exemplo n.º 6
0
 /**
  * Hostname operations
  *
  * ## OPTIONS
  *
  * <list|add|remove>
  * : OPTIONS are list, add, delete
  *
  * [--site=<site>]
  * : Site to use
  *
  * --env=<env>
  * : environment to use
  *
  * [--hostname=<hostname>]
  * : hostname to add
  *
  */
 public function hostnames($args, $assoc_args)
 {
     $action = array_shift($args);
     $site = $this->sites->get(Input::sitename($assoc_args));
     $env = $site->environments->get(Input::env($assoc_args, 'env'));
     switch ($action) {
         case 'list':
             $hostnames = $env->getHostnames();
             $data = $hostnames;
             if (Terminus::getConfig('format') != 'json') {
                 //If were not just dumping the JSON, then we should reformat the data.
                 $data = array();
                 foreach ($hostnames as $hostname => $details) {
                     $data[] = array_merge(array('domain' => $hostname), (array) $details);
                 }
             }
             $this->output()->outputRecordList($data);
             break;
         case 'add':
             if (!isset($assoc_args['hostname'])) {
                 $this->failure('Must specify hostname with --hostname');
             }
             $data = $env->addHostname($assoc_args['hostname']);
             $this->log()->debug(json_encode($data));
             $this->log()->info('Added {hostname} to {site}-{env}', array('hostname' => $assoc_args['hostname'], 'site' => $site->get('name'), 'env' => $env->get('id')));
             break;
         case 'remove':
             if (!isset($assoc_args['hostname'])) {
                 $this->failure('Must specify hostname with --hostname');
             }
             $data = $env->deleteHostname($assoc_args['hostname']);
             $this->log()->info('Deleted {hostname} from {site}-{env}', array('hostname' => $assoc_args['hostname'], 'site' => $site->get('name'), 'env' => $env->get('id')));
             break;
     }
     return $data;
 }
Exemplo n.º 7
0
 private static function render_subcommands($command)
 {
     $subcommands = array();
     foreach ($command->getSubcommands() as $subcommand) {
         $subcommands[$subcommand->getName()] = $subcommand->getShortdesc();
     }
     if (Terminus::getConfig('format') == 'json') {
         return $subcommands;
     }
     $max_len = self::get_max_len(array_keys($subcommands));
     $lines = array();
     foreach ($subcommands as $name => $desc) {
         $lines[] = str_pad($name, $max_len) . "\t\t\t" . $desc;
     }
     return $lines;
 }
Exemplo n.º 8
0
 /**
  * Make a request to the Pantheon API
  *
  * @param [string] $realm   Permissions realm for data request (e.g. user,
  *   site organization, etc. Can also be "public" to simply pull read-only
  *   data that is not privileged.
  * @param [string] $uuid    The UUID of the item in the realm to access
  * @param [string] $path    API path (URL)
  * @param [string] $method  HTTP method to use
  * @param [mixed]  $options A native PHP data structure (e.g. int, string,
  *   array, or stdClass) to be sent along with the request
  * @return [array] $data
  */
 public static function request($realm, $uuid, $path = false, $method = 'GET', $options = null)
 {
     if (!in_array($realm, array('login', 'user', 'public'))) {
         Auth::loggedIn();
     }
     try {
         $cache = Terminus::getCache();
         if (!in_array($realm, array('login', 'user'))) {
             $options['cookies'] = array('X-Pantheon-Session' => Session::getValue('session'));
             $options['verify'] = false;
         }
         $url = Endpoint::get(array('realm' => $realm, 'uuid' => $uuid, 'path' => $path));
         if (Terminus::getConfig('debug')) {
             Terminus::log('debug', 'Request URL: ' . $url);
         }
         $resp = Request::send($url, $method, $options);
         $json = $resp->getBody(true);
         $data = array('info' => $resp->getInfo(), 'headers' => $resp->getRawHeaders(), 'json' => $json, 'data' => json_decode($json), 'status_code' => $resp->getStatusCode());
         return $data;
     } catch (Guzzle\Http\Exception\BadResponseException $e) {
         $response = $e->getResponse();
         throw new TerminusException($response->getBody(true));
     } catch (Guzzle\Http\Exception\HttpException $e) {
         $request = $e->getRequest();
         $sanitized_request = TerminusCommand::stripSensitiveData((string) $request, TerminusCommand::$blacklist);
         throw new TerminusException('API Request Error. {msg} - Request: {req}', array('req' => $sanitized_request, 'msg' => $e->getMessage()));
     } catch (Exception $e) {
         throw new TerminusException('API Request Error: {msg}', array('msg' => $e->getMessage()));
     }
 }