Example #1
0
 /**
  * Attempt to load the full Drupal system.
  */
 function bootstrap_drupal_full()
 {
     drush_include_engine('drupal', 'environment');
     $this->add_logger();
     // Write correct install_profile to cache as needed. Used by _drush_find_commandfiles().
     $cid = drush_cid_install_profile();
     $install_profile = $this->get_profile();
     if ($cached_install_profile = drush_cache_get($cid)) {
         // We have a cached profile. Check it for correctness and save new value if needed.
         if ($cached_install_profile->data != $install_profile) {
             drush_cache_set($cid, $install_profile);
         }
     } else {
         // No cached entry so write to cache.
         drush_cache_set($cid, $install_profile);
     }
     _drush_log_drupal_messages();
 }
Example #2
0
 /**
  * @todo document
  */
 public function save()
 {
     drush_cache_set($this->cid(), $this->getArrayCopy(), 'lwg');
 }
Example #3
0
/**
 * Wrapper for alias file that builds out aliases
 * @param  array $aliases aliases from drush sa command
 */
function _elmsln_alises_build(&$aliases)
{
    // static cache assembled aliases as this can get tripped often
    static $pulledaliases = array();
    // check for pervasive cache if static is empty
    if (empty($pulledaliases)) {
        $cache = drush_cache_get(drush_get_cid('elmsln_remote_aliases'));
        $pulledaliases = $cache->data;
        if (empty($pulledaliases)) {
            // read off the .elmsln/elmsln-hosts manifest
            $pulledaliases = array();
            $home = getenv("HOME");
            // if somehow that isn't set..
            if (empty($home)) {
                $usr = posix_getpwuid(posix_getuid());
                $home = $user['dir'];
            }
            $file = "{$home}/.elmsln/elmsln-hosts";
            $hosts = file_get_contents($file);
            $lines = explode("\n", $hosts);
            // read each line of the config file
            foreach ($lines as $key => $line) {
                // make sure this line isn't a comment and has a=
                if (strpos($line, 'ssh') === 0) {
                    $server = array();
                    $line = str_replace('ssh ', '', $line);
                    $tmp = explode(' ', $line);
                    foreach ($tmp as $item) {
                        if (strpos($item, '@')) {
                            $tmp2 = explode('@', $item);
                            if (count($tmp2) == 2) {
                                $server['remote-user'] = $tmp2[0];
                                $server['remote-host'] = $tmp2[1];
                            }
                        } else {
                            $server['ssh-options'] .= $item . ' ';
                        }
                    }
                    // ensure we have 2 settings before doing this
                    if (count($server) == 3) {
                        // try for a nice name
                        if ($key > 0 && strpos($lines[$key - 1], '#') === 0) {
                            $aliaskey = _elmsln_alias_server_name($lines[$key - 1]);
                        } else {
                            $aliaskey = _elmsln_alias_server_name($server['remote-host']);
                        }
                        $pulledaliases[$aliaskey] = _elmsln_alias_build_aliases($aliaskey, $server);
                    }
                }
            }
            // write this back to the cache
            drush_cache_set(drush_get_cid('elmsln_remote_aliases'), $pulledaliases);
        }
    }
    //print_r($pulledaliases);
    // @todo add support for bundled stacks across deployments
    // for example: elmsln-courses-all which trips all the courses-all
    // stacks found across known hosts. This could allow for applying
    // something JUST to all courses that we are managing
    // add support for bundled and nested targets
    $aliases['elmsln-all'] = array('site-list' => array());
    // now convert these to aliases style
    foreach ($pulledaliases as $system => $onsystem) {
        $aliases[$system] = array('site-list' => array());
        array_push($aliases['elmsln-all']['site-list'], '@' . $system);
        foreach ($onsystem as $alias => $settings) {
            $alias = str_replace('elmsln.', '', $alias);
            if ($alias == 'elmsln') {
                continue;
            }
            // don't double push -all targets to larger -all target buckets
            if (!strpos($alias, '-all') && $alias != 'none') {
                array_push($aliases[$system]['site-list'], '@' . $system . '.' . $alias);
            }
            // deep load and repair parents to point into the system
            if (isset($settings['parent'])) {
                $settings['parent'] = str_replace('@', '@' . $system . '.', $settings['parent']);
                $settings['parent'] = str_replace('.elmsln', '', $settings['parent']);
            }
            // same but for site listings
            if (isset($settings['site-list'])) {
                foreach ($settings['site-list'] as $sitekey => $site) {
                    $settings['site-list'][$sitekey] = str_replace('@', '@' . $system . '.', $site);
                    $settings['site-list'][$sitekey] = str_replace('.elmsln', '', $settings['site-list'][$sitekey]);
                }
            }
            $aliases[$system . '.' . $alias] = $settings;
        }
    }
}
 /**
  * Log in to target Provider.
  *
  * @param string $email
  *   The email address of the user.
  * @param string $password
  *   The password of the user.
  *
  * @return bool
  *   Indicates success.
  */
 public function authLogin($email, $password)
 {
     $url = $this->endpoint . '/login';
     // Get the form build ID.
     try {
         $response = \Requests::post($url);
     } catch (\Requests_Exception $e) {
         return drush_set_error('SWITCHBOARD_AUTH_LOGIN_PANTHEON_ENDPOINT_UNAVAILABLE', dt('Pantheon endpoint unavailable: @error', array('@error' => $e->getMessage())));
     }
     $form_build_id = $this->authLoginGetFormBuildId($response->body);
     if (!$form_build_id) {
         return drush_set_error('SWITCHBOARD_AUTH_LOGIN_PANTHEON_LOGIN_UNAVAILABLE', dt('Pantheon login unavailable.'));
     }
     // Attempt to log in.
     try {
         $response = \Requests::post($url, array(), array('email' => $email, 'password' => $password, 'form_build_id' => $form_build_id, 'form_id' => 'atlas_login_form', 'op' => 'Login'), $this->requestsOptions(array('follow_redirects' => FALSE)));
     } catch (\Requests_Exception $e) {
         return drush_set_error('SWITCHBOARD_AUTH_LOGIN_PANTHEON_LOGIN_FAILURE', dt('Pantheon login failure: @error', array('@error' => $e->getMessage())));
     }
     $session = $this->authLoginGetSessionFromHeaders($response->headers->getValues('set-cookie'));
     if (!$session) {
         return drush_set_error('SWITCHBOARD_AUTH_LOGIN_PANTHEON_NO_SESSION', dt('Pantheon Session not found; please check your credentials and try again.'));
     }
     // Get the UUID.
     $user_uuid = array_pop(explode('/', $response->headers->offsetGet('Location')));
     if (!switchboard_validate_uuid($user_uuid)) {
         return drush_set_error('SWITCHBOARD_AUTH_LOGIN_PANTHEON_NO_UUID', dt('Pantheon User UUID not found; please check your credentials and try again.'));
     }
     drush_cache_clear_all('*', $this->drushCacheBinAuthName(), TRUE);
     drush_cache_set('user_uuid', $user_uuid, $this->drushCacheBinAuthName());
     drush_cache_set('session', $session, $this->drushCacheBinAuthName());
     drush_cache_set('email', $email, $this->drushCacheBinAuthName());
     return TRUE;
 }
Example #5
0
 /**
  * Log in to target Provider.
  *
  * @param string $email
  *   The email address of the user.
  * @param string $password
  *   The password of the user.
  *
  * @return bool
  *   Indicates success.
  */
 public function authLogin($email, $password)
 {
     drush_cache_clear_all('*', $this->drushCacheBinAuthName(), TRUE);
     drush_cache_set('email', $email, $this->drushCacheBinAuthName());
     drush_cache_set('password', $password, $this->drushCacheBinAuthName());
     return TRUE;
 }