/** * Requests API data and returns aliases * * @return string */ private function getAliases() { $request = new Request(); $user = new User(); $path = 'drush_aliases'; $method = 'GET'; $response = $request->request('users', Session::getValue('user_id'), $path, $method); eval(str_replace('<?php', '', $response['data']->drush_aliases)); $formatted_aliases = substr($response['data']->drush_aliases, 0, -1); $sites_object = new Sites(); $sites = $sites_object->all(); foreach ($sites as $site) { $environments = $site->environments->all(); foreach ($environments as $environment) { $key = $site->get('name') . '.' . $environment->get('id'); if (isset($aliases[$key])) { break; } try { $formatted_aliases .= PHP_EOL . " \$aliases['{$key}'] = "; $formatted_aliases .= $this->constructAlias($environment); } catch (TerminusException $e) { continue; } } } $formatted_aliases .= PHP_EOL; return $formatted_aliases; }
/** * Execute the login via email/password * * @param string $email Email address associated with a Pantheon account * @param string $password Password for the account * @return bool True if login succeeded * @throws TerminusException */ public function logInViaUsernameAndPassword($email, $password) { if (!Terminus\Utils\isValidEmail($email)) { throw new TerminusException('{email} is not a valid email address.', compact('email'), 1); } $options = array('form_params' => array('email' => $email, 'password' => $password)); $response = $this->request->request('login', '', '', 'POST', $options); if ($response['status_code'] != '200') { throw new TerminusException('Login unsuccessful for {email}', compact('email'), 1); } $this->logger->info('Logged in as {uuid}.', array('uuid' => $response['data']->user_id)); $this->setInstanceData($response['data']); return true; }