function poc_error($reason = 'Uknown failure', $extended = FALSE) { // Make creative use of the error reporting API $data = array('file' => 'GitHub Integration', 'line' => 'Error', 'type' => 'error', 'message' => $reason); $params = http_build_query($data); $result = pantheon_curl('https://api.live.getpantheon.com/sites/self/environments/self/events?' . $params, NULL, 8443, 'POST'); error_log("GitHub Integration failed - {$reason}"); // Dump additional debug info into the error log if ($extended) { error_log(print_r($extended, 1)); } die("GitHub Integration failed - {$reason}"); }
/** * Gets the New Relic API Key so that further requests can be made. * * Also gets New Relic's name for the given environment. */ function get_nr_connection_info($env = 'dev') { $output = array(); $req = pantheon_curl('https://api.live.getpantheon.com/sites/self/bindings?type=newrelic', null, 8443); $meta = json_decode($req['body'], true); foreach ($meta as $data) { if ($data['environment'] === $env) { if (empty($data['api_key'])) { echo "Failed to get API Key\n"; return; } $output['api_key'] = $data['api_key']; if (empty($data['app_name'])) { echo "Failed to get app name\n"; return; } $output['app_name'] = $data['app_name']; } } return $output; }
<?php // TODO: this header should not be required... header('Content-Type: text/plain; charset=UTF-8'); // Fetch metadata $req = pantheon_curl('https://api.live.getpantheon.com/sites/self/bindings?type=newrelic', NULL, 8443); $meta = json_decode($req['body'], true); // Get the right binding for the current ENV. // TODO: scope down the pantheon_curl() more. // It should be possible to just fetch the one for the current env. $nr = FALSE; foreach ($meta as $data) { if ($data['environment'] === PANTHEON_ENVIRONMENT) { $nr = $data; break; } } // Find out what tag we are on $deploy_tag = `git describe --tags`; // Get the annotation $annotation = `git tag -l -n99 {$deploy_tag}`; // Use New Relic's own example curl for ease of use. if ($nr) { $curl = 'curl -H "x-api-key:' . $data['api_key'] . '"'; $curl .= ' -d "deployment[application_id]=' . $data['app_name'] . '"'; $curl .= ' -d "deployment[description]=This deploy log was sent using Quicksilver"'; $curl .= ' -d "deployment[revision]=' . $deploy_tag . '"'; $curl .= ' -d "deployment[changelog]=' . $annotation . '"'; $curl .= ' -d "deployment[user]=' . $_POST['user_email'] . '"'; $curl .= ' https://api.newrelic.com/deployments.xml'; // The below can be helpful debugging.
private function fetch_site_data() { // Function internal to Pantheon infrastructure $pem_file = apply_filters('pantheon_hud_pem_file', null); if (function_exists('pantheon_curl')) { $bits = parse_url(self::$endpoint_url); $response = pantheon_curl(sprintf('%s://%s%s', $bits['scheme'], $bits['host'], $bits['path']), null, $bits['port']); $body = !empty($response['body']) ? $response['body'] : ''; return json_decode($body, true); // for those developing locally who know what they're doing } else { if ($pem_file || defined('PANTHEON_HUD_PHPUNIT_RUNNING') && PANTHEON_HUD_PHPUNIT_RUNNING) { $require_curl = function () { return array('curl'); }; add_filter('http_api_transports', $require_curl); $client_cert = function ($handle) use($pem_file) { curl_setopt($handle, CURLOPT_SSLCERT, $pem_file); }; add_action('http_api_curl', $client_cert); $response = wp_remote_get(self::$endpoint_url, array('sslverify' => false)); remove_action('http_api_curl', $client_cert); remove_filter('http_api_transports', $require_curl); if (200 !== wp_remote_retrieve_response_code($response)) { return null; } $body = wp_remote_retrieve_body($response); return json_decode($body, true); } } return array(); }
*/ setcookie('NO_CACHE', '1'); if (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') { header("Location: index.html#/diagram/live"); die; } /** * Showcase of Pantheon's abilities. */ header('Content-type: application/json'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past $curl_result = pantheon_curl('https://api.live.getpantheon.com/sites/self/bindings', NULL, 8443); $attr_result = pantheon_curl('https://api.live.getpantheon.com/sites/self', NULL, 8443); //print $attr_result['body']; //var_dump($curl_result); $json_array = json_decode($curl_result['body'], true); //print json_encode($json_array, JSON_PRETTY_PRINT); //die; $output = new stdClass(); $output->servers = array(); // Hard code edge servers. $edge = new stdClass(); $edge->id = 'AAAAAAAA'; $edge->type = 'edgeserver'; $edge->endpoint = 'edge1'; $edge->slave_of = NULL; $output->servers[] = $edge; if (!isset($_GET['env'])) {