Skip to content

Commit

Permalink
Moving pantheon.module to pantheon_api.module
Browse files Browse the repository at this point in the history
Moving ygg-config related install instructions to modulespace
Adding pantheon_login module
  • Loading branch information
Josh Koenig committed Jun 20, 2011
1 parent 61d4cb1 commit a9d14f3
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 195 deletions.
20 changes: 0 additions & 20 deletions modules/pantheon/pantheon.install

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ define('PANTHEON_SYSTEM_CERT', '/etc/pantheon/system.pem');
*
* Returns: an object of configuration
*/
function pantheon_ygg_config_get($site_uuid = 'self', $reset = FALSE) {
function pantheon_api_ygg_config_get($site_uuid = 'self', $reset = FALSE) {
static $config = array();
if (!$config[$site_uuid] && !$reset) {
$url = YGG_API ."/sites/$site_uuid/configuration";
$result = pantheon_curl($url, NULL, YGG_API_PORT);
$result = pantheon_api_curl($url, NULL, YGG_API_PORT);

// TODO: error checking?
$config[$site_uuid] = json_decode($result['body']);
}

return $config[$site_uuid];
}

Expand All @@ -41,53 +41,78 @@ function pantheon_ygg_config_get($site_uuid = 'self', $reset = FALSE) {
* $site_uuid the site to hit
*
* $path the REST url behind /sites/<site-uuid> to query
*
*
* $data an array or object that will be JSONified and PUT
*
*
*/
function pantheon_ygg_config_set($site_uuid = 'self', $data) {
function pantheon_api_ygg_config_set($site_uuid = 'self', $data) {
$url = YGG_API ."/sites/$site_uuid/configuration";
$json = json_encode($data);
$result = pantheon_curl($url, $json, YGG_API_PORT, 'PUT');
$result = pantheon_api_curl($url, $json, YGG_API_PORT, 'PUT');

return $result;
}

/**
* Post events to Ygg api.
*/
function pantheon_ygg_event_post($site_uuid = 'self', $data) {
function pantheon_api_ygg_event_post($site_uuid = 'self', $data) {
$url = YGG_API ."/sites/$site_uuid/events/";
$json = json_encode($data);
$result = pantheon_curl($url, $json, YGG_API_PORT, 'POST');
$result = pantheon_api_curl($url, $json, YGG_API_PORT, 'POST');

return $result;
}

/**
* Ygg API call to pull the services status.
*/
function pantheon_ygg_services_get($site_uuid = 'self', $reset = FALSE) {
function pantheon_api_ygg_services_get($site_uuid = 'self', $reset = FALSE) {
static $services = array();
if (!isset($services[$site_uuid]) && !$reset) {
$url = YGG_API ."/sites/$site_uuid/services";
$result = pantheon_curl($url, NULL, YGG_API_PORT);
$result = pantheon_api_curl($url, NULL, YGG_API_PORT);

// TODO: error checking?
$services[$site_uuid] = json_decode($result['body']);
}

return $services[$site_uuid];
}

/**
* Function to get an authorization token
*
* This will only allow a site to get tokens for itself, not other sites.
*/
function pantheon_api_get_authorization($token) {
$token = check_plain($token);
$poison = cache_get('pantheon-poison-'. $token);
if (is_object($poison)) {
return FALSE;
}
$result = pantheon_api_curl('sites/self/authorizations/'. $token);
if (strpos($result['headers'], 'HTTP/1.1 200') !== FALSE) {
$authorization = json_decode($result['body']);
if ($authorization->expires < time() || $authorization->headers->{'X-AuthProxy-Request-Service'} != 'drupal_login') {
return FALSE;
}
else {
return $authorization;
}
}
else {
return FALSE;
}
}

/**
* Helper function for running CURLs
*/
function pantheon_curl($url, $data = NULL, $port = 443, $datamethod = 'POST') {
function pantheon_api_curl($url, $data = NULL, $port = 443, $datamethod = 'POST') {
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
$opts = array(
CURLOPT_URL => $url,
Expand All @@ -99,25 +124,25 @@ function pantheon_curl($url, $data = NULL, $port = 443, $datamethod = 'POST') {
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
);
curl_setopt_array($ch, $opts);

// If we are posting data...
if ($data) {
if ($datamethod == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
}
else {
// This is sorta janky, but I want to re-use most of this function
// As per:
// As per:
// http://www.lornajane.net/posts/2009/PUTting-data-fields-with-PHP-cURL
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}


// grab URL and pass it to the browser
$result = curl_exec($ch);

if (curl_errno($ch) != 0) {
$error = curl_error($ch);
curl_close($ch);
Expand All @@ -126,7 +151,7 @@ function pantheon_curl($url, $data = NULL, $port = 443, $datamethod = 'POST') {
}

list($headers, $body) = explode("\r\n\r\n", $result);

$return = array(
'result' => $result,
'headers' => $headers,
Expand All @@ -137,17 +162,17 @@ function pantheon_curl($url, $data = NULL, $port = 443, $datamethod = 'POST') {

// close cURL resource, and free up system resources
curl_close($ch);

return $return;
}

/**
* Helper function to get uuid for "self" from the cert.
*/
function pantheon_get_self_uuid() {
function pantheon_api_get_self_uuid() {
$cert = file_get_contents(PANTHEON_SYSTEM_CERT);
$ssl = openssl_x509_parse($cert);
$uuid = array_shift(explode('.', $ssl['subject']['CN']));

return $uuid;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
; $Id$
name = Pantheon Platform
name = Pantheon Platform API
description = Integration with the Pantheon Platform
package = Pantheon
version = 1.0
core = 7.x
core = 7.x
php = 5.2
44 changes: 44 additions & 0 deletions modules/pantheon/pantheon_api/pantheon_api.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
// $Id$
/**
* @file pantheon.install
* TODO: Enter file description here.
*/

/**
* Implementation of hook_install().
*/
function pantheon_api_install() {
include_once('pantheon_api.inc');
pantheon_api_ygg_event_post('self', array('Drupal' => 'New Site Installed!'));
}

/**
* Implementation of hook_enable().
*/
function pantheon_api_enable() {
$config = pantheon_api_ygg_config_get();
$solr_server = array(
'server_id' => '',
'name' => '',
'scheme' => 'http',
'host' => '',
'port' => '',
'path' => '',
);

// Remove existing apachesolr servers
db_delete('apachesolr_server')->execute();

// Create solr server entries for each environment.
foreach ($config as $project => $data) {
foreach ($data->environments as $env_name => $env) {
$solr_server['server_id'] = $env->solr->apachesolr_default_server;
$solr_server['name'] = ucwords("$project $env_name");
$solr_server['path'] = $env->solr->solr_path;
$solr_server['host'] = $env->solr->solr_host;
$solr_server['port'] = $env->solr->solr_port;
db_insert('apachesolr_server')->fields($solr_server)->execute();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* TODO: implement an admin login system via YGG tokens.
*/
function pantheon_menu() {
function pantheon_api_menu() {
/*
$items['TODO: Enter path'] = array(
'title' => 'TODO: Enter menu item title',
Expand All @@ -22,14 +22,14 @@ function pantheon_menu() {
'weight' => 0,
'type' => MENU_NORMAL_ITEM, // One of MENU_NORMAL_ITEM / MENU_CALLBACK / MENU_SUGGESTED_ITEM / MENU_LOCAL_TASK / MENU_DEFAULT_LOCAL_TASK
'menu_name' => '', // Menu to place this item in.
'title callback' => '', // Function to generate the title, defaults to t().
'title arguments' => '', // Arguments to send to t() or your custom callback.
'title callback' => '', // Function to generate the title, defaults to t().
'title arguments' => '', // Arguments to send to t() or your custom callback.
);
// OPTIONAL: Fill in additional static menu items
*/
// return $items;
}

function pantheon_load_api() {
include('pantheon.api.inc');
}
function pantheon_api_load_ygg() {
include_once('pantheon_api.inc');
}
1 change: 1 addition & 0 deletions modules/pantheon/pantheon_login/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Login integration for your site and the Pantheon control panel
7 changes: 7 additions & 0 deletions modules/pantheon/pantheon_login/pantheon_login.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; $Id$
name = Pantheon Login
description = Allows users to log in as user #1 from their Pantheon Control Panel
package = Pantheon
dependencies[] = pantheon_api
core = 7.x
php = 5.2
8 changes: 8 additions & 0 deletions modules/pantheon/pantheon_login/pantheon_login.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/**
* @file
* Pantheon Login install functions.
*
* Placeholder.
*/
Loading

0 comments on commit a9d14f3

Please sign in to comment.