PageRenderTime 68ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/core/model/aws/services/cloudfront.class.php

http://github.com/modxcms/revolution
PHP | 1420 lines | 699 code | 196 blank | 525 comment | 124 complexity | 0497fda4407cf0043d0e6aafe8c56268 MD5 | raw file
Possible License(s): GPL-2.0, Apache-2.0, BSD-3-Clause, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. * Copyright 2010-2011 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. /*%******************************************************************************************%*/
  17. // EXCEPTIONS
  18. /**
  19. * Default CloudFront Exception.
  20. */
  21. class CloudFront_Exception extends Exception {}
  22. /*%******************************************************************************************%*/
  23. // MAIN CLASS
  24. /**
  25. * Amazon CloudFront is a web service for content delivery. It makes it easier for you to distribute content
  26. * to end users quickly, with low latency and high data transfer speeds.
  27. *
  28. * CloudFront delivers your content through a worldwide network of edge locations. End users are routed to
  29. * the nearest edge location, so content is delivered with the best possible performance. CloudFront works
  30. * seamlessly with the Amazon Simple Storage Service, which durably stores the original, definitive versions
  31. * of your files.
  32. *
  33. * @version 2011.03.11
  34. * @license See the included NOTICE.md file for more information.
  35. * @copyright See the included NOTICE.md file for more information.
  36. * @link http://aws.amazon.com/cloudfront/ Amazon CloudFront
  37. * @link http://aws.amazon.com/documentation/cloudfront/ Amazon CloudFront documentation
  38. */
  39. class AmazonCloudFront extends CFRuntime
  40. {
  41. /**
  42. * Specify the default queue URL.
  43. */
  44. const DEFAULT_URL = 'cloudfront.amazonaws.com';
  45. /**
  46. * The InProgress state.
  47. */
  48. const STATE_INPROGRESS = 'InProgress';
  49. /**
  50. * The Deployed state.
  51. */
  52. const STATE_DEPLOYED = 'Deployed';
  53. /**
  54. * The base content to use for generating the DistributionConfig XML.
  55. */
  56. var $base_xml;
  57. /**
  58. * The CloudFront distribution domain to use.
  59. */
  60. var $domain;
  61. /**
  62. * The RSA key pair ID to use.
  63. */
  64. var $key_pair_id;
  65. /**
  66. * The RSA private key resource locator.
  67. */
  68. var $private_key;
  69. /*%******************************************************************************************%*/
  70. // CONSTRUCTOR
  71. /**
  72. * Constructs a new instance of this class.
  73. *
  74. * @param string $key (Optional) Your Amazon API Key. If blank, it will look for the <AWS_KEY> constant.
  75. * @param string $secret_key (Optional) Your Amazon API Secret Key. If blank, it will look for the <AWS_SECRET_KEY> constant.
  76. * @return boolean A value of <code>false</code> if no valid values are set, otherwise <code>true</code>.
  77. */
  78. public function __construct($key = null, $secret_key = null)
  79. {
  80. $this->api_version = '2010-11-01';
  81. $this->hostname = self::DEFAULT_URL;
  82. $this->base_xml = '<?xml version="1.0" encoding="UTF-8"?><%s xmlns="http://cloudfront.amazonaws.com/doc/' . $this->api_version . '/"></%1$s>';
  83. if (!$key && !defined('AWS_KEY'))
  84. {
  85. throw new CloudFront_Exception('No account key was passed into the constructor, nor was it set in the AWS_KEY constant.');
  86. }
  87. if (!$secret_key && !defined('AWS_SECRET_KEY'))
  88. {
  89. throw new CloudFront_Exception('No account secret was passed into the constructor, nor was it set in the AWS_SECRET_KEY constant.');
  90. }
  91. // Set a default key pair ID
  92. if (defined('AWS_CLOUDFRONT_KEYPAIR_ID'))
  93. {
  94. $this->key_pair_id = AWS_CLOUDFRONT_KEYPAIR_ID;
  95. }
  96. // Set a default private key
  97. if (defined('AWS_CLOUDFRONT_PRIVATE_KEY_PEM'))
  98. {
  99. $this->private_key = AWS_CLOUDFRONT_PRIVATE_KEY_PEM;
  100. }
  101. return parent::__construct($key, $secret_key);
  102. }
  103. /*%******************************************************************************************%*/
  104. // AUTHENTICATION
  105. /**
  106. * Authenticates a connection to Amazon CloudFront. This method should not be used directly unless
  107. * you're writing custom methods for this class.
  108. *
  109. * @param string $method (Required) The HTTP method to use to connect. Accepts <code>GET</code>, <code>POST</code>, <code>PUT</code>, <code>DELETE</code>, and <code>HEAD</code>.
  110. * @param string $path (Optional) The endpoint path to make requests to.
  111. * @param array $opt (Optional) An associative array of parameters for authenticating. See the individual methods for allowed keys.
  112. * @param string $xml (Optional) The XML body content to send along in the request.
  113. * @param string $etag (Optional) The ETag value to pass along with the If-Match HTTP header.
  114. * @param integer $redirects (Do Not Use) Used internally by this function on occasions when Amazon S3 returns a redirect code and it needs to call itself recursively.
  115. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  116. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/RESTAuthentication.html Authentication
  117. */
  118. public function authenticate($method = 'GET', $path = null, $opt = null, $xml = null, $etag = null, $redirects = 0)
  119. {
  120. if (!$opt) $opt = array();
  121. $querystring = null;
  122. $method_arguments = func_get_args();
  123. // Use the caching flow to determine if we need to do a round-trip to the server.
  124. if ($this->use_cache_flow)
  125. {
  126. // Generate an identifier specific to this particular set of arguments.
  127. $cache_id = $this->key . '_' . get_class($this) . '_' . $method . sha1($path) . '_' . sha1(serialize($method_arguments));
  128. // Instantiate the appropriate caching object.
  129. $this->cache_object = new $this->cache_class($cache_id, $this->cache_location, $this->cache_expires, $this->cache_compress);
  130. if ($this->delete_cache)
  131. {
  132. $this->use_cache_flow = false;
  133. $this->delete_cache = false;
  134. return $this->cache_object->delete();
  135. }
  136. // Invoke the cache callback function to determine whether to pull data from the cache or make a fresh request.
  137. $data = $this->cache_object->response_manager(array($this, 'cache_callback'), $method_arguments);
  138. // Parse the XML body
  139. $data = $this->parse_callback($data);
  140. // End!
  141. return $data;
  142. }
  143. // Generate query string
  144. if (isset($opt['query_string']) && count($opt['query_string']))
  145. {
  146. $querystring = '?' . $this->util->to_query_string($opt['query_string']);
  147. }
  148. // Gather information to pass along to other classes.
  149. $helpers = array(
  150. 'utilities' => $this->utilities_class,
  151. 'request' => $this->request_class,
  152. 'response' => $this->response_class,
  153. );
  154. // Compose the endpoint URL.
  155. $request_url = 'https://' . $this->hostname . '/' . $this->api_version;
  156. $request_url .= ($path) ? $path : '';
  157. $request_url .= ($querystring) ? $querystring : '';
  158. // Compose the request.
  159. $request = new $this->request_class($request_url, $this->proxy, $helpers);
  160. // Update RequestCore settings
  161. $request->request_class = $this->request_class;
  162. $request->response_class = $this->response_class;
  163. // Pass along registered stream callbacks
  164. if ($this->registered_streaming_read_callback)
  165. {
  166. $request->register_streaming_read_callback($this->registered_streaming_read_callback);
  167. }
  168. if ($this->registered_streaming_write_callback)
  169. {
  170. $request->register_streaming_write_callback($this->registered_streaming_write_callback);
  171. }
  172. // Generate required headers.
  173. $request->set_method($method);
  174. $canonical_date = gmdate($this->util->konst($this->util, 'DATE_FORMAT_RFC2616'));
  175. $request->add_header('x-amz-date', $canonical_date);
  176. $signature = base64_encode(hash_hmac('sha1', $canonical_date, $this->secret_key, true));
  177. $request->add_header('Authorization', 'AWS ' . $this->key . ':' . $signature);
  178. // Add configuration XML if we have it.
  179. if ($xml)
  180. {
  181. $request->add_header('Content-Length', strlen($xml));
  182. $request->add_header('Content-Type', 'application/xml');
  183. $request->set_body($xml);
  184. }
  185. // Set If-Match: ETag header if we have one.
  186. if ($etag)
  187. {
  188. $request->add_header('If-Match', $etag);
  189. }
  190. $curlopts = array();
  191. // Set custom CURLOPT settings
  192. if (isset($opt['curlopts']))
  193. {
  194. $curlopts = $opt['curlopts'];
  195. unset($opt['curlopts']);
  196. }
  197. // Debug mode
  198. if ($this->debug_mode)
  199. {
  200. $curlopts[CURLOPT_VERBOSE] = true;
  201. }
  202. if (count($curlopts))
  203. {
  204. $request->set_curlopts($curlopts);
  205. }
  206. // Manage the (newer) batch request API or the (older) returnCurlHandle setting.
  207. if ($this->use_batch_flow)
  208. {
  209. $handle = $request->prep_request();
  210. $this->batch_object->add($handle);
  211. $this->use_batch_flow = false;
  212. return $handle;
  213. }
  214. elseif (isset($opt['returnCurlHandle']) && $opt['returnCurlHandle'] == (bool) true)
  215. {
  216. return $request->prep_request();
  217. }
  218. // Send!
  219. $request->send_request();
  220. // Prepare the response.
  221. $headers = $request->get_response_header();
  222. if ($xml) $headers['x-aws-body'] = $xml;
  223. $data = new $this->response_class($headers, $this->parse_callback($request->get_response_body()), $request->get_response_code());
  224. // Was it Amazon's fault the request failed? Retry the request until we reach $max_retries.
  225. if ((integer) $request->get_response_code() === 500 || (integer) $request->get_response_code() === 503)
  226. {
  227. if ($redirects <= $this->max_retries)
  228. {
  229. // Exponential backoff
  230. $delay = (integer) (pow(4, $redirects) * 100000);
  231. usleep($delay);
  232. $data = $this->authenticate($method, $path, $opt, $xml, $etag, ++$redirects);
  233. }
  234. }
  235. return $data;
  236. }
  237. /**
  238. * When caching is enabled, this method fires the request to the server, and the response is cached.
  239. * Accepts identical parameters as <authenticate()>. You should never call this method directly—it is
  240. * used internally by the caching system.
  241. *
  242. * @param string $method (Required) The HTTP method to use to connect. Accepts <code>GET</code>, <code>POST</code>, <code>PUT</code>, <code>DELETE</code>, and <code>HEAD</code>.
  243. * @param string $path (Optional) The endpoint path to make requests to.
  244. * @param array $opt (Optional) An associative array of parameters for authenticating. See the individual methods for allowed keys.
  245. * @param string $xml (Optional) The XML body content to send along in the request.
  246. * @param string $etag (Optional) The ETag value to pass along with the If-Match HTTP header.
  247. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  248. */
  249. public function cache_callback($method = 'GET', $path = null, $opt = null, $xml = null, $etag = null)
  250. {
  251. // Disable the cache flow since it's already been handled.
  252. $this->use_cache_flow = false;
  253. // Make the request
  254. $response = $this->authenticate($method, $path, $opt, $xml, $etag);
  255. if (isset($response->body) && ($response->body instanceof SimpleXMLElement))
  256. {
  257. $response->body = $response->body->asXML();
  258. }
  259. return $response;
  260. }
  261. /*%******************************************************************************************%*/
  262. // SETTERS
  263. /**
  264. * Set the key ID of the RSA key pair being used.
  265. *
  266. * @param string $key_pair_id (Required) The ID of the RSA key pair being used.
  267. * @return $this A reference to the current instance.
  268. */
  269. public function set_keypair_id($key_pair_id)
  270. {
  271. $this->key_pair_id = $key_pair_id;
  272. return $this;
  273. }
  274. /**
  275. * Set the private key resource locator being used.
  276. *
  277. * @param string $private_key (Optional) The contents of the RSA private key used to sign requests.
  278. * @return $this A reference to the current instance.
  279. */
  280. public function set_private_key($private_key)
  281. {
  282. $this->private_key = $private_key;
  283. return $this;
  284. }
  285. /**
  286. * Overrides the <CFRuntime::disable_ssl()> method from the base class. SSL is required for CloudFront.
  287. *
  288. * @return void
  289. */
  290. public function disable_ssl()
  291. {
  292. throw new CloudFront_Exception('SSL/HTTPS is REQUIRED for Amazon CloudFront and cannot be disabled.');
  293. }
  294. /*%******************************************************************************************%*/
  295. // GENERATE CONFIG XML
  296. /**
  297. * Generates the distribution configuration XML used with <create_distribution()> and
  298. * <set_distribution_config()>.
  299. *
  300. * @param string $origin (Required) The source to use for the Amazon CloudFront distribution. Use an Amazon S3 bucket name, or a fully-qualified non-S3 domain name prefixed with <code>http://</code> or <code>https://</code>.
  301. * @param string $caller_reference (Required) A unique identifier for the request. A timestamp-appended string is recommended.
  302. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  303. * <li><code>CNAME</code> - <code>string|array</code> - Optional - A DNS CNAME to use to map to the Amazon CloudFront distribution. If setting more than one, use an indexed array. Supports 1-10 CNAMEs.</li>
  304. * <li><code>Comment</code> - <code>string</code> - Optional - A comment to apply to the distribution. Cannot exceed 128 characters.</li>
  305. * <li><code>DefaultRootObject</code> - <code>string</code> - Optional - The file to load when someone accesses the root of your Amazon CloudFront domain (e.g., <code>index.html</code>).</li>
  306. * <li><code>Enabled</code> - <code>string</code> - Optional - A value of <code>true</code> enables the distribution. A value of <code>false</code> disables it. The default value is <code>true</code>.</li>
  307. * <li><code>Logging</code> - <code>array</code> - Optional - An array that contains two keys: <code>Bucket</code>, specifying where logs are written to, and <code>Prefix</code>, specifying a prefix to append to log file names.</li>
  308. * <li><code>OriginAccessIdentity</code> - <code>string</code> - Optional - The origin access identity (OAI) associated with this distribution. Use the Identity ID from the OAI, not the <code>CanonicalId</code>. Requires an S3 origin.</li>
  309. * <li><code>OriginProtocolPolicy</code> - <code>string</code> - Optional - The origin protocol policy to apply to your origin. If you specify <code>http-only</code>, CloudFront will use HTTP only to access the origin. If you specify <code>match-viewer</code>, CloudFront will fetch from your origin using HTTP or HTTPS, based on the protocol of the viewer request. It has a default value of <code>match-viewer</code>. [Allowed values: <code>http-only</code>, <code>match-viewer</code>]</li>
  310. * <li><code>Streaming</code> - <code>boolean</code> - Optional - Whether or not this should be for a streaming distribution. A value of <code>true</code> will create a streaming distribution. A value of <code>false</code> will create a standard distribution. The default value is <code>false</code>.</li>
  311. * <li><code>TrustedSigners</code> - <code>array</code> - Optional - An array of AWS account numbers for users who are trusted signers. Explicity add the value <code>Self</code> to the array to add your own account as a trusted signer.</li></ul>
  312. * @return string An XML document to be used as the distribution configuration.
  313. */
  314. public function generate_config_xml($origin, $caller_reference, $opt = null)
  315. {
  316. // Default, empty XML
  317. $xml = simplexml_load_string(sprintf($this->base_xml, (
  318. (isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'StreamingDistributionConfig' : 'DistributionConfig')
  319. ));
  320. if (substr($origin, 0, 7) === 'http://' || substr($origin, 0, 8) === 'https://')
  321. {
  322. // Custom Origin
  323. $custom_origin = $xml->addChild('CustomOrigin');
  324. $custom_origin->addChild('DNSName', str_replace(array('http://', 'https://'), '', $origin));
  325. if (isset($opt['OriginProtocolPolicy']))
  326. {
  327. $custom_origin->addChild('OriginProtocolPolicy', $opt['OriginProtocolPolicy']);
  328. }
  329. else
  330. {
  331. $custom_origin->addChild('OriginProtocolPolicy', 'match-viewer');
  332. }
  333. }
  334. else
  335. {
  336. // S3 Origin
  337. $s3_origin = $xml->addChild('S3Origin');
  338. $s3_origin->addChild('DNSName', $origin . ((stripos($origin, '.s3.amazonaws.com') === false) ? '.s3.amazonaws.com' : ''));
  339. // Origin Access Identity
  340. if (isset($opt['OriginAccessIdentity']))
  341. {
  342. $s3_origin->addChild('OriginAccessIdentity', 'origin-access-identity/cloudfront/' . $opt['OriginAccessIdentity']);
  343. }
  344. }
  345. // CallerReference
  346. $xml->addChild('CallerReference', $caller_reference);
  347. // CNAME
  348. if (isset($opt['CNAME']))
  349. {
  350. if (is_array($opt['CNAME']))
  351. {
  352. foreach ($opt['CNAME'] as $cname)
  353. {
  354. $xml->addChild('CNAME', $cname);
  355. }
  356. }
  357. else
  358. {
  359. $xml->addChild('CNAME', $opt['CNAME']);
  360. }
  361. }
  362. // Comment
  363. if (isset($opt['Comment']))
  364. {
  365. $xml->addChild('Comment', $opt['Comment']);
  366. }
  367. // Enabled
  368. if (isset($opt['Enabled']))
  369. {
  370. $xml->addChild('Enabled', $opt['Enabled'] ? 'true' : 'false');
  371. }
  372. else
  373. {
  374. $xml->addChild('Enabled', 'true');
  375. }
  376. // Logging
  377. if (isset($opt['Logging']))
  378. {
  379. if (is_array($opt['Logging']))
  380. {
  381. $logging = $xml->addChild('Logging');
  382. $bucket_name = $opt['Logging']['Bucket'];
  383. // Origin
  384. $logging->addChild('Bucket', $bucket_name . (
  385. (stripos($bucket_name, '.s3.amazonaws.com') === false) ? '.s3.amazonaws.com' : ''
  386. ));
  387. $logging->addChild('Prefix', $opt['Logging']['Prefix']);
  388. }
  389. }
  390. // Required Protocols
  391. if (isset($opt['RequiredProtocols']))
  392. {
  393. $required_protocols = $xml->addChild('RequiredProtocols');
  394. $required_protocols->addChild('Protocol', $opt['RequiredProtocols']);
  395. }
  396. // Trusted Signers
  397. if (isset($opt['TrustedSigners']))
  398. {
  399. $trusted_signers = $xml->addChild('TrustedSigners');
  400. // Not an array? Convert to one.
  401. if (!is_array($opt['TrustedSigners']))
  402. {
  403. $opt['TrustedSigners'] = array($opt['TrustedSigners']);
  404. }
  405. // Handle 'Self' vs. everything else
  406. foreach ($opt['TrustedSigners'] as $signer)
  407. {
  408. if (strtolower($signer) === 'self')
  409. {
  410. $trusted_signers->addChild('Self');
  411. }
  412. else
  413. {
  414. $trusted_signers->addChild('AwsAccountNumber', $signer);
  415. }
  416. }
  417. }
  418. // DefaultRootObject
  419. if (isset($opt['DefaultRootObject']))
  420. {
  421. $xml->addChild('DefaultRootObject', $opt['DefaultRootObject']);
  422. }
  423. return $xml->asXML();
  424. }
  425. /**
  426. * Updates an existing configuration XML document.
  427. *
  428. * @param CFSimpleXML|CFResponse|string $xml (Required) The source configuration XML to make updates to. Can be the <CFSimpleXML> body of a <get_distribution_config()> response, the entire <CFResponse> of a <get_distribution_config()> response, or a string of XML generated by <generate_config_xml()> or <update_config_xml()>.
  429. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  430. * <li><code>CNAME</code> - <code>string|array</code> - Optional - The value or values to add to the existing list of CNAME values. If setting more than one, use an indexed array. Supports up to 10 CNAMEs.</li>
  431. * <li><code>Comment</code> - <code>string</code> - Optional - A comment to apply to the distribution. Cannot exceed 128 characters.</li>
  432. * <li><code>DefaultRootObject</code> - <code>string</code> - Optional - The file to load when someone accesses the root of your Amazon CloudFront domain (e.g., <code>index.html</code>).</li>
  433. * <li><code>Enabled</code> - <code>string</code> - Optional - A value of <code>true</code> enables the distribution. A value of <code>false</code> disables it. The default value is <code>true</code>.</li>
  434. * <li><code>Logging</code> - <code>array</code> - Optional - An array that contains two keys: <code>Bucket</code>, specifying where logs are written to, and <code>Prefix</code>, specifying a prefix to append to log file names.</li>
  435. * <li><code>OriginAccessIdentity</code> - <code>string</code> - Optional - The origin access identity (OAI) associated with this distribution. Use the Identity ID from the OAI, not the <code>CanonicalId</code>.</li>
  436. * <li><code>TrustedSigners</code> - <code>array</code> - Optional - An array of AWS account numbers for users who are trusted signers. Explicity add the value <code>Self</code> to the array to add your own account as a trusted signer.</li></ul>
  437. * @return string XML document.
  438. */
  439. public function update_config_xml($xml, $opt = null)
  440. {
  441. // If we receive a full CFResponse object, only use the body.
  442. if ($xml instanceof CFResponse)
  443. {
  444. $xml = $xml->body;
  445. }
  446. // If we received a string of XML, convert it into a CFSimpleXML object.
  447. if (is_string($xml))
  448. {
  449. $xml = simplexml_load_string($xml, $this->parser_class);
  450. }
  451. // Default, empty XML
  452. $update = simplexml_load_string(sprintf($this->base_xml, (
  453. (isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'StreamingDistributionConfig' : 'DistributionConfig')
  454. ), $this->parser_class);
  455. // These can't change.
  456. if (isset($xml->S3Origin))
  457. {
  458. $origin = $update->addChild('S3Origin');
  459. $origin->addChild('DNSName', $xml->S3Origin->DNSName);
  460. // origin access identity
  461. if (isset($opt['OriginAccessIdentity']))
  462. {
  463. $update->addChild('OriginAccessIdentity', 'origin-access-identity/cloudfront/' . $opt['OriginAccessIdentity']);
  464. }
  465. elseif (isset($xml->OriginAccessIdentity))
  466. {
  467. $update->addChild('OriginAccessIdentity', $xml->OriginAccessIdentity);
  468. }
  469. }
  470. elseif (isset($xml->CustomOrigin))
  471. {
  472. $origin = $update->addChild('CustomOrigin');
  473. $origin->addChild('DNSName', $xml->CustomOrigin->DNSName);
  474. }
  475. $update->addChild('CallerReference', $xml->CallerReference);
  476. // Add existing CNAME values
  477. if ($xml->CNAME)
  478. {
  479. $update->addChild('CNAME', $xml->CNAME);
  480. }
  481. // Add new CNAME values
  482. if (isset($opt['CNAME']))
  483. {
  484. if (is_array($opt['CNAME']))
  485. {
  486. foreach ($opt['CNAME'] as $cname)
  487. {
  488. $update->addChild('CNAME', $cname);
  489. }
  490. }
  491. else
  492. {
  493. $update->addChild('CNAME', $opt['CNAME']);
  494. }
  495. }
  496. // Comment
  497. if (isset($opt['Comment']))
  498. {
  499. $update->addChild('Comment', $opt['Comment']);
  500. }
  501. elseif (isset($xml->Comment))
  502. {
  503. $update->addChild('Comment', $xml->Comment);
  504. }
  505. // DefaultRootObject
  506. if (isset($opt['DefaultRootObject']))
  507. {
  508. $update->addChild('DefaultRootObject', $opt['DefaultRootObject']);
  509. }
  510. elseif (isset($xml->DefaultRootObject))
  511. {
  512. $update->addChild('DefaultRootObject', $xml->DefaultRootObject);
  513. }
  514. // Enabled
  515. if (isset($opt['Enabled']))
  516. {
  517. $update->addChild('Enabled', $opt['Enabled'] ? 'true' : 'false');
  518. }
  519. elseif (isset($xml->Enabled))
  520. {
  521. $update->addChild('Enabled', $xml->Enabled);
  522. }
  523. // Logging
  524. if (isset($opt['Logging']))
  525. {
  526. if (is_array($opt['Logging']))
  527. {
  528. $logging = $update->addChild('Logging');
  529. $bucket_name = $opt['Logging']['Bucket'];
  530. // Origin
  531. $logging->addChild('Bucket', $bucket_name . ((stripos($bucket_name, '.s3.amazonaws.com') === false) ? '.s3.amazonaws.com' : ''));
  532. $logging->addChild('Prefix', $opt['Logging']['Prefix']);
  533. }
  534. }
  535. elseif (isset($xml->Logging))
  536. {
  537. $logging = $update->addChild('Logging');
  538. $logging->addChild('Bucket', $xml->Logging->Bucket);
  539. $logging->addChild('Prefix', $xml->Logging->Prefix);
  540. }
  541. // Trusted Signers
  542. if (isset($opt['TrustedSigners']))
  543. {
  544. $trusted_signers = $update->addChild('TrustedSigners');
  545. // Not an array? Convert to one.
  546. if (!is_array($opt['TrustedSigners']))
  547. {
  548. $opt['TrustedSigners'] = array($opt['TrustedSigners']);
  549. }
  550. // Handle 'Self' vs. everything else
  551. foreach ($opt['TrustedSigners'] as $signer)
  552. {
  553. if (strtolower($signer) === 'self')
  554. {
  555. $trusted_signers->addChild('Self');
  556. }
  557. else
  558. {
  559. $trusted_signers->addChild('AwsAccountNumber', $signer);
  560. }
  561. }
  562. }
  563. elseif (isset($xml->TrustedSigners) && $xml->TrustedSigners->count())
  564. {
  565. $trusted_signers = $update->addChild('TrustedSigners');
  566. // Handle 'Self' vs. everything else
  567. foreach ($xml->TrustedSigners->children() as $signer_key => $signer_value)
  568. {
  569. if (strtolower((string) $signer_key) === 'self')
  570. {
  571. $trusted_signers->addChild('Self');
  572. }
  573. else
  574. {
  575. $trusted_signers->addChild('AwsAccountNumber', (string) $signer_value);
  576. }
  577. }
  578. }
  579. // Output
  580. return $update->asXML();
  581. }
  582. /**
  583. * Removes one or more CNAMEs from a <code>DistibutionConfig</code> XML document.
  584. *
  585. * @param CFSimpleXML|CFResponse|string $xml (Required) The source DistributionConfig XML to make updates to. Can be the <CFSimpleXML> body of a <get_distribution_config()> response, the entire <CFResponse> of a <get_distribution_config()> response, or a string of XML generated by <generate_config_xml()> or <update_config_xml()>.
  586. * @param string|array $cname (Optional) The value or values to remove from the existing list of CNAME values. To add a CNAME value, see <update_config_xml()>.
  587. * @return string XML document.
  588. */
  589. public function remove_cname($xml, $cname)
  590. {
  591. // If we receive a full CFResponse object, only use the body.
  592. if ($xml instanceof CFResponse)
  593. {
  594. $xml = $xml->body;
  595. }
  596. // If we received a string of XML, convert it into a CFSimpleXML object.
  597. if (is_string($xml))
  598. {
  599. $xml = simplexml_load_string($xml);
  600. }
  601. // Let's make sure that we have CNAMEs to remove in the first place.
  602. if (isset($xml->CNAME))
  603. {
  604. // If we have an array of CNAME values...
  605. if (is_array($cname))
  606. {
  607. foreach ($cname as $cn)
  608. {
  609. for ($i = 0, $length = sizeof($xml->CNAME); $i < $length; $i++)
  610. {
  611. if ((string) $xml->CNAME[$i] == $cn)
  612. {
  613. unset($xml->CNAME[$i]);
  614. break;
  615. }
  616. }
  617. }
  618. }
  619. // If we only have one CNAME value...
  620. else
  621. {
  622. for ($i = 0, $length = sizeof($xml->CNAME); $i < $length; $i++)
  623. {
  624. if ((string) $xml->CNAME[$i] == $cname)
  625. {
  626. unset($xml->CNAME[$i]);
  627. break;
  628. }
  629. }
  630. }
  631. }
  632. return $xml->asXML();
  633. }
  634. /**
  635. * Used to generate the origin access identity (OAI) Config XML used in <create_oai()>.
  636. *
  637. * @param string $caller_reference (Required) A unique identifier for the request. A timestamp-appended string is recommended.
  638. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  639. * <li><code>Comment</code> - <code>string</code> - Optional - Replaces the existing value for "Comment". Cannot exceed 128 characters.</li></ul>
  640. * @return string An XML document to be used as the OAI configuration.
  641. */
  642. public function generate_oai_xml($caller_reference, $opt = null)
  643. {
  644. // Default, empty XML
  645. $xml = simplexml_load_string(sprintf($this->base_xml, 'CloudFrontOriginAccessIdentityConfig'));
  646. // CallerReference
  647. $xml->addChild('CallerReference', $caller_reference);
  648. // Comment
  649. if (isset($opt['Comment']))
  650. {
  651. $xml->addChild('Comment', $opt['Comment']);
  652. }
  653. return $xml->asXML();
  654. }
  655. /**
  656. * Updates the origin access identity (OAI) configureation XML used in <create_oai()>.
  657. *
  658. * @param CFSimpleXML|CFResponse|string $xml (Required) The source configuration XML to make updates to. Can be the <CFSimpleXML> body of a <get_oai_config()> response, the entire <CFResponse> of a <get_oai_config()> response, or a string of XML generated by <generate_oai_xml()> or <update_oai_xml()>.
  659. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  660. * <li><code>Comment</code> - <code>string</code> - Optional - Replaces the existing value for "Comment". Cannot exceed 128 characters.</li></ul>
  661. * @return string XML document.
  662. */
  663. public function update_oai_xml($xml, $opt = null)
  664. {
  665. // If we receive a full CFResponse object, only use the body.
  666. if ($xml instanceof CFResponse)
  667. {
  668. $xml = $xml->body;
  669. }
  670. // If we received a string of XML, convert it into a CFSimpleXML object.
  671. if (is_string($xml))
  672. {
  673. $xml = simplexml_load_string($xml, $this->parser_class);
  674. }
  675. // Update the comment, if we have one.
  676. if (isset($opt['Comment']) && isset($xml->Comment))
  677. {
  678. $xml->Comment = $opt['Comment'];
  679. }
  680. elseif (isset($opt['Comment']))
  681. {
  682. $xml->addChild('Comment', $opt['Comment']);
  683. }
  684. return $xml->asXML();
  685. }
  686. /**
  687. * Generates the Invalidation Config XML used in <create_invalidation()>.
  688. *
  689. * @param string $caller_reference (Required) A unique identifier for the request. A timestamp-appended string is recommended.
  690. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  691. * <li><code>Paths</code> - <code>string|array</code> - Optional - One or more paths to set for invalidation. Pass a string for a single value, or an indexed array for multiple values.</li></ul>
  692. * @return string An XML document to be used as the Invalidation configuration.
  693. */
  694. public function generate_invalidation_xml($caller_reference, $opt = null)
  695. {
  696. // Default, empty XML
  697. $xml = simplexml_load_string(sprintf($this->base_xml, 'InvalidationBatch'));
  698. // CallerReference
  699. $xml->addChild('CallerReference', $caller_reference);
  700. // Paths
  701. if (isset($opt['Paths']))
  702. {
  703. $paths = is_array($opt['Paths']) ? $opt['Paths'] : array($opt['Paths']);
  704. foreach ($paths as $path)
  705. {
  706. $path = str_replace('%2F', '/', rawurlencode($path));
  707. $path = (substr($path, 0, 1) === '/') ? $path : ('/' . $path);
  708. $xml->addChild('Path', $path);
  709. }
  710. }
  711. return $xml->asXML();
  712. }
  713. /*%******************************************************************************************%*/
  714. // DISTRIBUTIONS
  715. /**
  716. * Creates an Amazon CloudFront distribution. You can have up to 100 distributions in the Amazon
  717. * CloudFront system.
  718. *
  719. * For an Adobe Real-Time Messaging Protocol (RTMP) streaming distribution, set the <code>Streaming</code> option
  720. * to true.
  721. *
  722. * @param string $origin (Required) The source to use for the Amazon CloudFront distribution. Use an Amazon S3 bucket name, or a fully-qualified non-S3 domain name prefixed with <code>http://</code> or <code>https://</code>.
  723. * @param string $caller_reference (Required) A unique identifier for the request. A timestamp-appended string is recommended.
  724. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  725. * <li><code>CNAME</code> - <code>string|array</code> - Optional - A DNS CNAME to use to map to the Amazon CloudFront distribution. If setting more than one, use an indexed array. Supports 1-10 CNAMEs.</li>
  726. * <li><code>Comment</code> - <code>string</code> - Optional - A comment to apply to the distribution. Cannot exceed 128 characters.</li>
  727. * <li><code>DefaultRootObject</code> - <code>string</code> - Optional - The file to load when someone accesses the root of the Amazon CloudFront domain (e.g., <code>index.html</code>).</li>
  728. * <li><code>Enabled</code> - <code>string</code> - Optional - A value of <code>true</code> will enable the distribution. A value of <code>false</code> will disable it. The default value is <code>true</code>.</li>
  729. * <li><code>OriginAccessIdentity</code> - <code>string</code> - Optional - The origin access identity (OAI) associated with this distribution. Use the Identity ID from the OAI, not the <code>CanonicalId</code>. Requires an S3 origin.</li>
  730. * <li><code>OriginProtocolPolicy</code> - <code>string</code> - Optional - The origin protocol policy to apply to your origin. If you specify <code>http-only</code>, CloudFront will use HTTP only to access the origin. If you specify <code>match-viewer</code>, CloudFront will fetch from your origin using HTTP or HTTPS, based on the protocol of the viewer request. [Allowed values: <code>http-only</code>, <code>match-viewer</code>]. The default value is <code>match-viewer</code>. Requires a non-S3 origin.</li>
  731. * <li><code>Streaming</code> - <code>boolean</code> - Optional - Whether or not this should be for a streaming distribution. A value of <code>true</code> creates a streaming distribution. A value of <code>false</code> creates a standard distribution. The default value is <code>false</code>.</li>
  732. * <li><code>TrustedSigners</code> - <code>array</code> - Optional - An array of AWS account numbers for users who are trusted signers. Explicity add the value <code>Self</code> to the array to add your own account as a trusted signer.</li>
  733. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  734. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  735. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  736. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/CreateDistribution.html POST Distribution
  737. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/CreateStreamingDistribution.html POST Streaming Distribution
  738. */
  739. public function create_distribution($origin, $caller_reference, $opt = null)
  740. {
  741. if (!$opt) $opt = array();
  742. $xml = $this->generate_config_xml($origin, $caller_reference, $opt);
  743. $path = '/' . ((isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'streaming-distribution' : 'distribution');
  744. return $this->authenticate('POST', $path, $opt, $xml, null);
  745. }
  746. /**
  747. * Gets a list of distributions. By default, the list is returned as one result. If needed, paginate the
  748. * list by specifying values for the <code>MaxItems</code> and <code>Marker</code> parameters.
  749. *
  750. * Standard distributions are listed separately from streaming distributions. For streaming distributions,
  751. * set the <code>Streaming</code> option to true.
  752. *
  753. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  754. * <li><code>Marker</code> - <code>string</code> - Optional - Use this setting when paginating results to indicate where in your list of distributions to begin. The results include distributions in the list that occur after the marker. To get the next page of results, set the <code>Marker</code> to the value of the <code>NextMarker</code> from the current page's response (which is also the ID of the last distribution on that page).</li>
  755. * <li><code>MaxItems</code> - <code>integer</code> - Optional - The maximum number of distributions you want in the response body. Maximum of 100.</li>
  756. * <li><code>Streaming</code> - <code>boolean</code> - Optional - Whether or not this should be for a streaming distribution. A value of <code>true</code> will create a streaming distribution. A value of <code>false</code> will create a standard distribution. The default value is <code>false</code>.</li>
  757. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  758. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  759. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  760. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListDistributions.html GET Distribution List
  761. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListStreamingDistributions.html GET Streaming Distribution List
  762. */
  763. public function list_distributions($opt = null)
  764. {
  765. if (!$opt) $opt = array();
  766. $opt['query_string'] = array();
  767. // Pass these to the query string
  768. foreach (array('Marker', 'MaxItems') as $option)
  769. {
  770. if (isset($opt[$option]))
  771. {
  772. $opt['query_string'][$option] = $opt[$option];
  773. }
  774. }
  775. $path = '/' . ((isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'streaming-distribution' : 'distribution');
  776. return $this->authenticate('GET', $path, $opt, null, null);
  777. }
  778. /**
  779. * Gets distribution information for the specified distribution ID.
  780. *
  781. * Standard distributions are handled separately from streaming distributions. For streaming
  782. * distributions, set the <code>Streaming</code> option to true.
  783. *
  784. * @param string $distribution_id (Required) The distribution ID returned from <create_distribution()> or <list_distributions()>.
  785. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  786. * <li><code>Streaming</code> - <code>boolean</code> - Optional - Whether or not this should be for a streaming distribution. A value of <code>true</code> will create a streaming distribution. A value of <code>false</code> will create a standard distribution. The default value is <code>false</code>.</li>
  787. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  788. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  789. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  790. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/GetDistribution.html GET Distribution
  791. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/GetStreamingDistribution.html GET Streaming Distribution
  792. */
  793. public function get_distribution_info($distribution_id, $opt = null)
  794. {
  795. if (!$opt) $opt = array();
  796. $path = '/' . ((isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'streaming-distribution' : 'distribution');
  797. $path .= '/' . $distribution_id;
  798. return $this->authenticate('GET', $path, $opt, null, null);
  799. }
  800. /**
  801. * Deletes a disabled distribution. If distribution hasn't been disabled, Amazon CloudFront returns a
  802. * <code>DistributionNotDisabled</code> error. Use <set_distribution_config()> to disable a distribution before
  803. * attempting to delete.
  804. *
  805. * For an Adobe Real-Time Messaging Protocol (RTMP) streaming distribution, set the <code>Streaming</code> option
  806. * to be <code>true</code>.
  807. *
  808. * @param string $distribution_id (Required) The distribution ID returned from <create_distribution()> or <list_distributions()>.
  809. * @param string $etag (Required) The <code>ETag</code> header value retrieved from <get_distribution_config()>.
  810. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  811. * <li><code>Streaming</code> - <code>boolean</code> - Optional - Whether or not this should be for a streaming distribution. A value of <code>true</code> will create a streaming distribution. A value of <code>false</code> will create a standard distribution. The default value is <code>false</code>.</li>
  812. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  813. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  814. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  815. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/DeleteDistribution.html DELETE Distribution
  816. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/DeleteStreamingDistribution.html DELETE Streaming Distribution
  817. */
  818. public function delete_distribution($distribution_id, $etag, $opt = null)
  819. {
  820. if (!$opt) $opt = array();
  821. $path = '/' . ((isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'streaming-distribution' : 'distribution');
  822. $path .= '/' . $distribution_id;
  823. return $this->authenticate('DELETE', $path, $opt, null, $etag);
  824. }
  825. /**
  826. * Gets the current distribution configuration for the specified distribution ID.
  827. *
  828. * Standard distributions are handled separately from streaming distributions. For streaming
  829. * distributions, set the <code>Streaming</code> option to true.
  830. *
  831. * @param string $distribution_id (Required) The distribution ID returned from <create_distribution()> or <list_distributions()>.
  832. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  833. * <li><code>Streaming</code> - <code>boolean</code> - Optional - Whether or not this should be for a streaming distribution. A value of <code>true</code> will create a streaming distribution. A value of <code>false</code> will create a standard distribution. The default value is <code>false</code>.</li>
  834. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  835. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  836. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  837. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/GetConfig.html GET Distribution Config
  838. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/GetStreamingDistConfig.html GET Streaming Distribution Config
  839. */
  840. public function get_distribution_config($distribution_id, $opt = null)
  841. {
  842. if (!$opt) $opt = array();
  843. $path = '/' . ((isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'streaming-distribution' : 'distribution');
  844. $path .= '/' . $distribution_id . '/config';
  845. return $this->authenticate('GET', $path, $opt, null, null);
  846. }
  847. /**
  848. * Sets a new distribution configuration for the specified distribution ID.
  849. *
  850. * Standard distributions are handled separately from streaming distributions. For streaming
  851. * distributions, set the <code>Streaming</code> option to true.
  852. *
  853. * @param string $distribution_id (Required) The distribution ID returned from <create_distribution()> or <list_distributions()>.
  854. * @param string $xml (Required) The DistributionConfig XML generated by <generate_config_xml()> or <update_config_xml()>.
  855. * @param string $etag (Required) The ETag header value retrieved from <get_distribution_config()>.
  856. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  857. * <li><code>Streaming</code> - <code>boolean</code> - Optional - Whether or not this should be for a streaming distribution. A value of <code>true</code> will create a streaming distribution. A value of <code>false</code> will create a standard distribution. The default value is <code>false</code>.</li>
  858. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  859. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  860. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  861. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/PutConfig.html PUT Distribution Config
  862. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/PutStreamingDistConfig.html PUT Streaming Distribution Config
  863. */
  864. public function set_distribution_config($distribution_id, $xml, $etag, $opt = null)
  865. {
  866. if (!$opt) $opt = array();
  867. $path = '/' . ((isset($opt['Streaming']) && $opt['Streaming'] == (bool) true) ? 'streaming-distribution' : 'distribution');
  868. $path .= '/' . $distribution_id . '/config';
  869. return $this->authenticate('PUT', $path, $opt, $xml, $etag);
  870. }
  871. /*%******************************************************************************************%*/
  872. // Origin Access Identity
  873. /**
  874. * Creates a new Amazon CloudFront origin access identity (OAI). You can create up to 100 OAIs per AWS
  875. * account. For more information, see the Amazon CloudFront Developer Guide.
  876. *
  877. * @param string $caller_reference (Required) A unique identifier for the request. A timestamp-appended string is recommended.
  878. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  879. * <li><code>Comment</code> - <code>string</code> - Optional - A comment about the OAI.</li>
  880. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  881. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  882. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  883. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/CreateOAI.html POST Origin Access Identity
  884. */
  885. public function create_oai($caller_reference, $opt = null)
  886. {
  887. if (!$opt) $opt = array();
  888. $path = '/origin-access-identity/cloudfront';
  889. $xml = $this->generate_oai_xml($caller_reference, $opt);
  890. return $this->authenticate('POST', $path, $opt, $xml, null);
  891. }
  892. /**
  893. * Gets a list of origin access identity (OAI) summaries. By default, the list is returned as one result.
  894. * If needed, paginate the list by specifying values for the <code>MaxItems</code> and <code>Marker</code>
  895. * parameters.
  896. *
  897. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  898. * <li><code>Marker</code> - <code>string</code> - Optional - Use this when paginating results to indicate where in your list of distributions to begin. The results include distributions in the list that occur after the marker. To get the next page of results, set the Marker to the value of the NextMarker from the current page's response (which is also the ID of the last distribution on that page).</li>
  899. * <li><code>MaxItems</code> - <code>integer</code> - Optional - The maximum number of distributions you want in the response body. Maximum of 100.</li>
  900. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  901. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  902. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  903. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/ListOAIs.html GET Origin Access Identity List
  904. */
  905. public function list_oais($opt = null)
  906. {
  907. if (!$opt) $opt = array();
  908. $opt['query_string'] = array();
  909. // Pass these to the query string
  910. foreach (array('Marker', 'MaxItems') as $option)
  911. {
  912. if (isset($opt[$option]))
  913. {
  914. $opt['query_string'][$option] = $opt[$option];
  915. }
  916. }
  917. $path = '/origin-access-identity/cloudfront';
  918. return $this->authenticate('GET', $path, $opt, null, null);
  919. }
  920. /**
  921. * Gets information about an origin access identity (OAI).
  922. *
  923. * @param string $identity_id (Required) The Identity ID for an existing OAI.
  924. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  925. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  926. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  927. * @return CFResponse A <CFResponse> object containing a parsed HTTP response.
  928. * @link http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/GetOAI.html GET Origin Access Identity
  929. */
  930. public function get_oai($identity_id, $opt = null)
  931. {
  932. if (!$opt) $opt = array();
  933. $path = '/origin-access-identity/cloudfront/' . $identity_id;
  934. return $this->authenticate('GET', $path, $opt, null, null);
  935. }
  936. /**
  937. * Deletes an Amazon CloudFront origin access identity (OAI). To delete an OAI, the identity must first
  938. * be disassociated from all distributions (by updating each distribution's configuration to omit the
  939. * <code>OriginAccessIdentity</code> element). Wait until each distribution's state is <code>Deployed</code>
  940. * before deleting the OAI.
  941. *
  942. * @param string $identity_id (Required) An Identity ID for an existing OAI.
  943. * @param string $etag (Required) The <code>ETag</code> header value retrieved from a call to <get_oai()>.
  944. * @param array $opt (Optional) An associative array of parameters that can have the following keys: <ul>
  945. * <li><code>curlopts</code> - <code>array</code> - Optional - A set of values to pass directly into <code>curl_setopt()</code>, where the key is a pre-defined <code>CURLOPT_*</code> constant.</li>
  946. * <li><code>returnCurlHandle</code> - <code>boolean</code> - Optional - A private toggle specifying that the cURL handle be returned rather than actually completing the request. This toggle is useful for manually managed batch requests.</li></ul>
  947. * @return CFResponse …

Large files files are truncated, but you can click here to view the full file