public static function table($table) { require_once __DIR__ . "/aws.phar"; $aws = Aws\Common\Aws::factory(array('key' => Config::get('dynamodb::config.key'), 'secret' => Config::get('dynamodb::config.secret'), 'region' => Config::get('dynamodb::config.region'))); self::$client = $aws->get('dynamodb'); return new DynamoDB($table); }
/** * Deploy the version of the given $versionLabel of the application * * @param string $versionLabel Identifier of the version that is going to be used * * @return boolean Success */ public function deployVersion($versionLabel) { $ebs = $this->aws->get('ElasticBeanstalk'); $this->output->writeln("Deploying version <info>{$versionLabel}</info> to <info>" . $this->app . " " . $this->env . "</info>..."); $env = $ebs->updateEnvironment(["ApplicationName" => $this->app, "EnvironmentName" => $this->env, "VersionLabel" => $versionLabel]); if ($env->get('VersionLabel') == $versionLabel) { return true; } return false; }
/** * Create an AWS IAM user for S3 Uploads to user * * @subcommand create-iam-user * @synopsis --admin-key=<key> --admin-secret=<secret> [--username=<username>] [--format=<format>] */ public function create_iam_user($args, $args_assoc) { $args_assoc = wp_parse_args($args_assoc, array('format' => 'table')); if (empty($args_assoc['username'])) { $username = '******' . sanitize_title(home_url()); } else { $username = $args_assoc['username']; } try { $iam = Aws\Common\Aws::factory(array('key' => $args_assoc['admin-key'], 'secret' => $args_assoc['admin-secret']))->get('iam'); $iam->createUser(array('UserName' => $username)); $credentials = $iam->createAccessKey(array('UserName' => $username)); $credentials = $credentials['AccessKey']; $iam->putUserPolicy(array('UserName' => $username, 'PolicyName' => $username . '-policy', 'PolicyDocument' => $this->get_iam_policy())); } catch (Exception $e) { WP_CLI::error($e->getMessage()); } WP_CLI\Utils\format_items($args_assoc['format'], array((object) $credentials), array('AccessKeyId', 'SecretAccessKey')); }
/** * @return Aws\S3\S3Client */ public function s3() { require_once dirname(dirname(__FILE__)) . '/lib/aws-sdk/aws-autoloader.php'; require_once dirname(__FILE__) . '/class-s3-uploads-stream-wrapper.php'; if (!empty($this->s3)) { return $this->s3; } $params = array(); if ($this->key && $this->secret) { $params['key'] = $this->key; $params['secret'] = $this->secret; } if ($this->region) { $params['signature'] = 'v4'; $params['region'] = $this->region; } if (defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT')) { $proxy_auth = ''; $proxy_address = WP_PROXY_HOST . ':' . WP_PROXY_PORT; if (defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD')) { $proxy_auth = WP_PROXY_USERNAME . ':' . WP_PROXY_PASSWORD . '@'; } $params['request.options']['proxy'] = $proxy_auth . $proxy_address; } $params = apply_filters('s3_uploads_s3_client_params', $params); $this->s3 = Aws\Common\Aws::factory($params)->get('s3'); return $this->s3; }
function _sign($plugin, $options) { if (!file_exists($plugin)) $this->fail($plugin.': Cannot find file'); elseif (!file_exists("phar://$plugin/MANIFEST.php")) $this->fail($plugin.': Should be a plugin PHAR file'); $info = (include "phar://$plugin/MANIFEST.php"); $phar = new Phar($plugin); if (!function_exists('openssl_get_privatekey')) $this->fail('OpenSSL extension required for signing'); $private = openssl_get_privatekey( file_get_contents($options['pkey'])); if (!$private) $this->fail('Unable to read private key'); $signature = $phar->getSignature(); $seal = ''; openssl_sign($signature['hash'], $seal, $private, OPENSSL_ALGO_SHA1); if (!$seal) $this->fail('Unable to generate verify signature'); $this->stdout->write(sprintf("Signature: %s\n", strtolower($signature['hash']))); $seal = sprintf('"v=1; i=%s; s=%s; V=%s;"', $info['Id'], base64_encode($seal), $info['Version']); if ($options['dns']) { if (!is_file(INCLUDE_DIR . 'aws.phar')) $this->fail('Unable to include AWS phar file. Download to INCLUDE_DIR'); require_once INCLUDE_DIR . 'aws.phar'; $aws = Aws\Common\Aws::factory(array()); $client = $aws->get('Route53'); try { $resp = $client->changeResourceRecordSets(array( 'HostedZoneId' => $options['dns'], 'ChangeBatch' => array( 'Changes' => array( array( 'Action' => 'CREATE', 'ResourceRecordSet' => array( 'Name' => "{$signature['hash']}.updates.osticket.com.", 'Type' => 'TXT', 'TTL' => 172800, 'ResourceRecords' => array( array( 'Value' => $seal, ), ), ), ), ), ), )); $this->stdout->write(sprintf('%s: %s', $resp['ChangeInfo']['Comment'], $resp['ChangeInfo']['Status'])); } catch (Exception $ex) { $this->stdout->write("Seal: $seal\n"); $this->fail('!! AWS Update Failed: '.$ex->getMessage()); } } else { $this->stdout->write("Seal: $seal\n"); } }
// Allow command line overrides if (get_cfg_var('CONFIG')) { $_SERVER['CONFIG'] = get_cfg_var('CONFIG'); } // Set the service configuration file if it was not provided from the CLI if (!isset($_SERVER['CONFIG'])) { $serviceConfig = $_SERVER['CONFIG'] = dirname(__DIR__) . '/test_services.json'; $_SERVER['CONFIG'] = $serviceConfig; if (!file_exists($serviceConfig)) { copy($serviceConfig . '.dist', $serviceConfig); } } if (!is_readable($_SERVER['CONFIG'])) { die("Unable to read service configuration from '{$_SERVER['CONFIG']}'\n"); } // If the global prefix is hostname, then use the crc32() of gethostname() if (!isset($_SERVER['PREFIX']) || $_SERVER['PREFIX'] == 'hostname') { $_SERVER['PREFIX'] = crc32(gethostname()); } // Instantiate the service builder $aws = Aws\Common\Aws::factory($_SERVER['CONFIG']); // Turn on wire logging if configured $aws->getEventDispatcher()->addListener('service_builder.create_client', function (\Guzzle\Common\Event $event) { if (isset($_SERVER['WIRE_LOGGING']) && $_SERVER['WIRE_LOGGING']) { $event['client']->addSubscriber(Guzzle\Plugin\Log\LogPlugin::getDebugPlugin()); } }); // Configure the tests to use the instantiated AWS service builder Guzzle\Tests\GuzzleTestCase::setServiceBuilder($aws); // Emit deprecation warnings Guzzle\Common\Version::$emitWarnings = true;
if (get_cfg_var('CONFIG')) { $_SERVER['CONFIG'] = get_cfg_var('CONFIG'); } // Set the service configuration file if it was not provided from the CLI if (!isset($_SERVER['CONFIG'])) { $serviceConfig = dirname(__DIR__) . '/test_services.json'; if (file_exists($serviceConfig)) { $_SERVER['CONFIG'] = $serviceConfig; } } // If the global prefix is hostname, then use the crc32() of gethostname() if (!isset($_SERVER['PREFIX']) || $_SERVER['PREFIX'] == 'hostname') { $_SERVER['PREFIX'] = crc32(gethostname()); } // Instantiate the service builder $aws = Aws\Common\Aws::factory(isset($_SERVER['CONFIG']) ? $_SERVER['CONFIG'] : 'test_services.dist.json'); // Turn on wire logging if configured $aws->getEventDispatcher()->addListener('service_builder.create_client', function (\Guzzle\Common\Event $event) { if (isset($_SERVER['WIRE_LOGGING']) && $_SERVER['WIRE_LOGGING']) { $event['client']->addSubscriber(Guzzle\Plugin\Log\LogPlugin::getDebugPlugin()); } }); // Configure the tests to use the instantiated AWS service builder Guzzle\Tests\GuzzleTestCase::setServiceBuilder($aws); // Emit deprecation warnings Guzzle\Common\Version::$emitWarnings = true; function can_mock_internal_classes() { switch (substr(PHP_VERSION, 0, 3)) { case '5.3.': return true;
/** * @return Aws\S3\S3Client */ public function s3() { if (!empty($this->s3)) { return $this->s3; } $params = array(); if ($this->key && $this->secret) { $params['key'] = $this->key; $params['secret'] = $this->secret; } if ($this->region) { $params['signature'] = 'v4'; $params['region'] = $this->region; } if (defined('WP_PROXY_HOST') && defined('WP_PROXY_PORT')) { $proxy_auth = ''; $proxy_address = WP_PROXY_HOST . ':' . WP_PROXY_PORT; if (defined('WP_PROXY_USERNAME') && defined('WP_PROXY_PASSWORD')) { $proxy_auth = WP_PROXY_USERNAME . ':' . WP_PROXY_PASSWORD . '@'; } $params['request.options']['proxy'] = $proxy_auth . $proxy_address; } $params = apply_filters('s3_uploads_s3_client_params', $params); $this->s3 = Aws\Common\Aws::factory($params)->get('s3'); return $this->s3; }
/** * Create an AWS IAM user for S3 Uploads to user * * @subcommand create-iam-user * @synopsis --admin-key=<key> --admin-secret=<secret> [--username=<username>] */ public function create_iam_user($args, $args_assoc) { require_once dirname(__FILE__) . '/aws-sdk/aws-autoloader.php'; if (empty($args_assoc['username'])) { $username = '******' . sanitize_title(home_url()); } else { $username = $args_assoc['username']; } try { $iam = Aws\Common\Aws::factory(array('key' => $args_assoc['admin-key'], 'secret' => $args_assoc['admin-secret']))->get('iam'); $iam->createUser(array('UserName' => $username)); $credentials = $iam->createAccessKey(array('UserName' => $username)); $credentials = $credentials['AccessKey']; $iam->putUserPolicy(array('UserName' => $username, 'PolicyName' => $username . '-policy', 'PolicyDocument' => $this->get_iam_policy())); } catch (Exception $e) { WP_CLI::error($e->getMessage()); } WP_CLI::success(sprintf('Created new IAM user %s. The Access Credentials are displayed below', $username)); WP_CLI\Utils\format_items('table', array((object) $credentials), array('AccessKeyId', 'SecretAccessKey')); }
/** * @return Aws\S3\S3Client */ public function s3() { require_once dirname(dirname(__FILE__)) . '/lib/aws-sdk/aws-autoloader.php'; require_once dirname(__FILE__) . '/class-s3-uploads-stream-wrapper.php'; if (!empty($this->s3)) { return $this->s3; } $params = array('key' => $this->key, 'secret' => $this->secret); if ($this->region) { $params['signature'] = 'v4'; $params['region'] = $this->region; } $this->s3 = Aws\Common\Aws::factory($params)->get('s3'); return $this->s3; }
} // Include the phar files if testing against the phars if (get_cfg_var('aws_phar')) { require dirname(__DIR__) . '/build/' . get_cfg_var('aws_phar'); } // Include the composer autoloader $loader = (require dirname(__DIR__) . '/vendor/autoload.php'); $loader->add('Aws\\Test', __DIR__); // Register services with the GuzzleTestCase Guzzle\Tests\GuzzleTestCase::setMockBasePath(__DIR__ . '/mock'); // Allow command line overrides if (get_cfg_var('CONFIG')) { $_SERVER['CONFIG'] = get_cfg_var('CONFIG'); } // Set the service configuration file if it was not provided from the CLI if (!isset($_SERVER['CONFIG'])) { $serviceConfig = $_SERVER['CONFIG'] = dirname(__DIR__) . '/test_services.json'; $_SERVER['CONFIG'] = $serviceConfig; if (!file_exists($serviceConfig)) { die("test_services.json does not exist.\n" . "Please run phing test-init or copy test_services.json.dist to test_services.json\n\n"); } } if (!is_readable($_SERVER['CONFIG'])) { die("Unable to read service configuration from '{$_SERVER['CONFIG']}'\n"); } // If the global prefix is hostname, then use the crc32() of gethostname() if (!isset($_SERVER['PREFIX']) || $_SERVER['PREFIX'] == 'hostname') { $_SERVER['PREFIX'] = crc32(gethostname()); } Guzzle\Tests\GuzzleTestCase::setServiceBuilder(Aws\Common\Aws::factory($_SERVER['CONFIG']));
function newServiceBuilder() { $user = creat_user(); return Aws\Common\Aws::factory($_SERVER['CONFIG'], array('key' => $user['key_id'], 'secret' => $user['key_secret'], 'curl.options' => array('CURLOPT_PROXY' => 'localhost:' . cs_port()))); }
/** * @return Aws\S3\S3Client */ public function s3() { require_once dirname(dirname(__FILE__)) . '/lib/aws-sdk/aws-autoloader.php'; require_once dirname(__FILE__) . '/class-s3-uploads-stream-wrapper.php'; if (!empty($this->s3)) { return $this->s3; } $params = array(); if ($this->key && $this->secret) { $params['key'] = $this->key; $params['secret'] = $this->secret; } if ($this->region) { $params['signature'] = 'v4'; $params['region'] = $this->region; } $params = apply_filters('s3_uploads_s3_client_params', $params); $this->s3 = Aws\Common\Aws::factory($params)->get('s3'); return $this->s3; }