Beispiel #1
0
 public function getSites()
 {
     $path = 'memberships/sites';
     $method = 'GET';
     $response = \TerminusCommand::request('organizations', $this->id, $path, $method);
     return $response['data'];
 }
Beispiel #2
0
 /**
  * Requests API data and populates $this->aliases
  *
  * @return [void]
  */
 private function setAliases()
 {
     $path = 'drush_aliases';
     $method = 'GET';
     $response = \TerminusCommand::request('users', $this->id, $path, $method);
     $this->aliases = $response['data']->drush_aliases;
 }
Beispiel #3
0
 private function loadUpstreams()
 {
     $key = join("-", array($this->type, $this->category, $this->framework));
     $response = \TerminusCommand::request("products", "public", false, "GET");
     $upstreams = 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($upstreams, $row);
     }
     array_multisort($sort, SORT_ASC, SORT_REGULAR, $upstreams);
     $this->upstreams = $upstreams;
     return $upstreams;
 }
Beispiel #4
0
 public function sites($organization = null)
 {
     if ($organization) {
         $path = sprintf("organizations/%s/memberships/sites", $organization);
     } else {
         $path = "sites";
     }
     $method = 'GET';
     $response = \TerminusCommand::request('users', $this->id, $path, $method);
     return $response['data'];
 }
Beispiel #5
0
 /**
  * Execute the login based on an existing session token
  *
  * @param [string] $token Session token to initiate login with
  * @return [boolean] True if login succeeded
  */
 public function logInViaSessionToken($token)
 {
     $options = array('headers' => array('Content-type' => 'application/json'), 'cookies' => array('X-Pantheon-Session' => $token));
     $this->logger->info('Validating session token');
     $response = TerminusCommand::request('user', '', '', 'GET', $options);
     if (!$response || !isset($response['status_code']) || $response['status_code'] != '200') {
         throw new TerminusException('The session token {token} is not valid.', array('token' => $token), 1);
     }
     $this->logger->info('Logged in as {uuid}.', array('uuid' => $response['data']->id));
     $session = array('user_uuid' => $response['data']->id, 'session' => $token, 'session_expire_time' => 0);
     Session::instance()->setData($session);
     return true;
 }
Beispiel #6
0
 /**
  * Requests API data and populates $this->profile
  *
  * @return [void]
  */
 private function setProfile()
 {
     $path = 'profile';
     $method = 'GET';
     $response = \TerminusCommand::request('users', $this->id, $path, $method);
     $this->profile = $response['data'];
 }
Beispiel #7
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
     $response = TerminusCommand::request('user', '', '', 'GET', $options);
     if (!$response or '200' != @$response['info']['http_code']) {
         $this->failure('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;
 }
Beispiel #8
0
 /**
  * Start a work flow
  *
  * @param [Workflow] $workflow String work flow "slot"
  * @return [array] $response['data']
  */
 public function workflow($workflow)
 {
     $path = sprintf("environments/%s/workflows", $this->get('id'));
     $data = array('type' => $workflow, 'environment' => $this->get('id'));
     $options = array('body' => json_encode($data), 'headers' => array('Content-type' => 'application/json'));
     $response = \TerminusCommand::request('sites', $this->site->get('id'), $path, 'POST', $options);
     return $response['data'];
 }
Beispiel #9
0
 /**
  * Just the code branches
  *
  * @return [stdClass] $data['data']
  */
 public function tips()
 {
     $path = 'code-tips';
     $data = \TerminusCommand::request('sites', $this->get('id'), $path, 'GET');
     return $data['data'];
 }
Beispiel #10
0
 private function envExists($site_id, $env)
 {
     $response = \TerminusCommand::request('sites', $site_id, 'environments', 'GET');
     $envs = (array) $response['data'];
     return array_key_exists($env, $envs);
 }
Beispiel #11
0
 /**
  * Get memberships for a site
  */
 public function memberships($type = 'organizations')
 {
     $path = sprintf('memberships/%s', $type);
     $method = 'GET';
     $response = \TerminusCommand::request('sites', $this->getId(), $path, $method);
     return $response['data'];
 }
Beispiel #12
0
 /**
  * Start a work flow
  *
  * @param [Workflow] $workflow String work flow "slot"
  * @return [array] $response['data']
  */
 public function workflow($workflow)
 {
     $path = sprintf("environments/%s/workflows", $this->get('id'));
     $body = array('type' => $workflow, 'environment' => $this->get('id'));
     $options = compact('body');
     $response = \TerminusCommand::request('sites', $this->site->get('id'), $path, 'POST', $options);
     return $response['data'];
 }
Beispiel #13
0
 /**
  * Load site info
  *
  * @param [string] $key Set to retrieve a specific attribute as named
  * @return [array] $info
  */
 public function info($key = null)
 {
     $path = sprintf('environments/%s', $this->get('id'));
     $result = \TerminusCommand::request('sites', $this->site->get('id'), $path, 'GET');
     $connection_mode = null;
     if (isset($result['data']->on_server_development)) {
         $connection_mode = 'git';
         if ((bool) $result['data']->on_server_development) {
             $connection_mode = 'sftp';
         }
     }
     $info = array('id' => $this->get('id'), 'connection_mode' => $connection_mode, 'php_version' => $this->site->info('php_version'));
     if ($key) {
         if (isset($info[$key])) {
             return $info[$key];
         } else {
             throw new TerminusException('There is no such field.', array(), -1);
         }
     } else {
         return $info;
     }
 }