Example #1
0
 public function refresh()
 {
     $response = \Terminus_Command::request($this->realm, $this->object->getId(), "workflows/" . $this->id, 'GET');
     $this->status = $response['data'];
     $this->id = $response['data']->id;
     $this->result = $this->status->result;
 }
Example #2
0
 private function loadProducts()
 {
     $key = join("-", array($this->type, $this->category, $this->framework));
     $response = \Terminus_Command::request("products", "public", false, "GET");
     $products = array();
     $keys_to_show = array('longname', 'framework', 'type', 'category');
     // we'll use this to sort the list later
     $sort = array();
     foreach ((array) $response['data'] as $id => $details) {
         if (!empty($this->type) and $details->attributes->type != $this->type) {
             continue;
         }
         if (!empty($this->category) and $details->attributes->category != $this->category) {
             continue;
         }
         if (!empty($this->framework) and $details->attributes->framework != $this->framework) {
             continue;
         }
         $sort[] = $details->attributes->shortname;
         $row = array();
         $row['id'] = $id;
         foreach ($keys_to_show as $key) {
             $row[$key] = @$details->attributes->{$key};
         }
         array_push($products, $row);
     }
     array_multisort($sort, SORT_ASC, SORT_REGULAR, $products);
     $this->products = $products;
     return $products;
 }
Example #3
0
 public function getSites()
 {
     $path = 'memberships/sites';
     $method = 'GET';
     $response = \Terminus_Command::request('organizations', $this->id, $path, $method);
     return $response['data'];
 }
Example #4
0
 public function run()
 {
     $params = array('type' => 'deploy', 'params' => array('annotation' => $this->annotation, 'clear_cache' => $this->cc, 'updatedb' => $this->updatedb));
     $options = array('body' => json_encode($params), 'headers' => array('Content-type' => 'application/json'));
     $path = sprintf("environments/%s/workflows/deploy", $this->env->name);
     $response = \Terminus_Command::request('sites', $this->env->site->getId(), $path, 'POST', $options);
     return $response['data'];
 }
Example #5
0
 public function sites($organization = null)
 {
     if ($organization) {
         $path = sprintf("organizations/%s/memberships/sites", $organization);
     } else {
         $path = "sites";
     }
     $method = 'GET';
     $response = \Terminus_Command::request('users', $this->id, $path, $method);
     return $response['data'];
 }
Example #6
0
 public function refresh()
 {
     $response = \Terminus_Command::request('sites', $this->site->getId(), "workflows/" . $this->id, 'GET');
     // we have to do this because the api sometimes returns an object and sometimes a collections
     if (!\Terminus\utils\result_is_multiobj($response['data'])) {
         $response['data'] = array($response['data']);
     }
     $this->status = $response['data'][0];
     $this->id = $response['data'][0]->id;
     $this->result = $response['data'][0]->result;
 }
 /**
  * Send the workflow to the api
  */
 public function start()
 {
     $data = array();
     $path = sprintf('environments/%s/workflows', $this->object->name);
     if ('POST' == $this->getMethod()) {
         $data['body'] = json_encode(array('type' => $this->type, 'params' => $this->params));
         $data['headers'] = array('Content-type' => 'application/json');
     } else {
         $path = "{$path}?type=" . $this->type;
     }
     $response = \Terminus_Command::request($this->realm, $this->object->site->getId(), $path, $this->getMethod(), $data);
     if (is_object($response['data'])) {
         $this->status = $response['data'];
         $this->id = $this->status->id;
         $this->result = $this->status->result;
     }
     return $this;
 }
Example #8
0
 /**
  * Delete a site from pantheon
  *
  * ## OPTIONS
  * --site=<site>
  * : Id of the site you want to delete
  *
  * [--all]
  * : Just kidding ... we won't let you do that.
  *
  * [--force]
  * : to skip the confirmations
  *
  */
 function delete($args, $assoc_args)
 {
     $site_to_delete = SiteFactory::instance(@$assoc_args['site']);
     if (!$site_to_delete) {
         foreach (SiteFactory::instance() as $id => $site) {
             $site->id = $id;
             $sites[] = $site;
             $menu[] = $site->information->name;
         }
         $index = Terminus::menu($menu, null, "Select a site to delete");
         $site_to_delete = $sites[$index];
     }
     if (!isset($assoc_args['force']) and !Terminus::get_config('yes')) {
         // if the force option isn't used we'll ask you some annoying questions
         Terminus::confirm(sprintf("Are you sure you want to delete %s?", $site_to_delete->information->name));
         Terminus::confirm("Are you really sure?");
     }
     Terminus::line(sprintf("Deleting %s ...", $site_to_delete->information->name));
     $response = \Terminus_Command::request('sites', $site_to_delete->id, '', 'DELETE');
     Terminus::success("Deleted %s!", $site_to_delete->information->name);
 }
Example #9
0
 private function envExists($site_id, $env)
 {
     $response = \Terminus_Command::request('sites', $site_id, 'code-tips', 'GET');
     $envs = (array) $response['data'];
     return array_key_exists($env, $envs);
 }
Example #10
0
 /**
  * Get memberships for a site
  */
 function memberships($type = 'organizations')
 {
     $path = sprintf('memberships/%s', $type);
     $method = 'GET';
     $response = \Terminus_Command::request('sites', $this->getId(), $path, $method);
     return $response['data'];
 }
Example #11
0
 /**
  * creates a new environment
  *
  */
 public function create($env_name)
 {
     $path = sprintf('environments/%s', $env_name);
     $OPTIONS = array('headers' => array('Content-type' => 'application/json'));
     $response = \Terminus_Command::request('sites', $site_id, $path, 'POST', $OPTIONS);
     return $response['data'];
 }
Example #12
0
 /**
  * Execute the login based on email,password
  *
  * @param $email string (required)
  * @param $password string (required)
  * @package Terminus
  * @version 0.04-alpha
  * @return string
  */
 private function doLogin($email, $password)
 {
     if (Terminus::is_test()) {
         $data = array('user_uuid' => '77629472-3050-457c-8c3d-32b2cabf992b', 'session' => '77629472-3050-457c-8c3d-32b2cabf992b:7dc42f40-65f8-11e4-b314-bc764e100eb1:ZHR0TgtQYsKcOOwMOd0tk', 'session_expire_time' => '1417727066', 'email' => '*****@*****.**');
         return $data;
     }
     $options = array('body' => json_encode(array('email' => $email, 'password' => $password)), 'headers' => array('Content-type' => 'application/json'));
     $response = Terminus_Command::request('login', '', '', 'POST', $options);
     if (!$response or '200' != @$response['info']['http_code']) {
         \Terminus::error("[auth_error]: unsuccessful login");
     }
     // Prepare credentials for storage.
     $data = array('user_uuid' => $response['data']->user_id, 'session' => $response['data']->session, 'session_expire_time' => $response['data']->expires_at, 'email' => $email);
     // creates a session instance
     Session::instance()->setData($data);
     return $data;
 }
Example #13
0
 /**
  * Execute the login based on an existing session token
  *
  * @param $session_token string (required)
  * @return array
  */
 private function doLoginFromSessionToken($session_token)
 {
     $options = array('headers' => array('Content-type' => 'application/json'), 'cookies' => array('X-Pantheon-Session' => $session_token));
     # Temporarily disable the cache for this GET call
     Terminus::set_config('nocache', TRUE);
     $response = Terminus_Command::request('user', '', '', 'GET', $options);
     Terminus::set_config('nocache', FALSE);
     if (!$response or '200' != @$response['info']['http_code']) {
         \Terminus::error("[auth_error]: session token not valid");
     }
     // Prepare credentials for storage.
     $data = array('user_uuid' => $response['data']->id, 'session' => $session_token, 'session_expire_time' => 0, 'email' => $response['data']->email);
     // creates a session instance
     Session::instance()->setData($data);
     return $data;
 }
Example #14
0
 /**
  * Delete a site from pantheon
  *
  * ## OPTIONS
  * [--site=<site>]
  * : ID of the site you want to delete
  *
  * [--force]
  * : to skip the confirmations
  */
 function delete($args, $assoc_args)
 {
     $sitename = Input::sitename($assoc_args);
     $site_id = $this->sitesCache->findID($sitename);
     $site_to_delete = new Site($site_id);
     if (!isset($assoc_args['force']) and !Terminus::get_config('yes')) {
         // if the force option isn't used we'll ask you some annoying questions
         Terminus::confirm(sprintf("Are you sure you want to delete %s?", $site_to_delete->information->name));
         Terminus::confirm("Are you really sure?");
     }
     Terminus::line(sprintf("Deleting %s ...", $site_to_delete->information->name));
     $response = \Terminus_Command::request('sites', $site_to_delete->id, '', 'DELETE');
     $this->sitesCache->remove($sitename);
     Terminus::success("Deleted %s!", $sitename);
 }