CloudFrontClient.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace Aws\CloudFront;
  3. use Aws\AwsClient;
  4. /**
  5. * This client is used to interact with the **Amazon CloudFront** service.
  6. *
  7. * @method \Aws\Result createCloudFrontOriginAccessIdentity(array $args = [])
  8. * @method \GuzzleHttp\Promise\Promise createCloudFrontOriginAccessIdentityAsync(array $args = [])
  9. * @method \Aws\Result createDistribution(array $args = [])
  10. * @method \GuzzleHttp\Promise\Promise createDistributionAsync(array $args = [])
  11. * @method \Aws\Result createInvalidation(array $args = [])
  12. * @method \GuzzleHttp\Promise\Promise createInvalidationAsync(array $args = [])
  13. * @method \Aws\Result createStreamingDistribution(array $args = [])
  14. * @method \GuzzleHttp\Promise\Promise createStreamingDistributionAsync(array $args = [])
  15. * @method \Aws\Result deleteCloudFrontOriginAccessIdentity(array $args = [])
  16. * @method \GuzzleHttp\Promise\Promise deleteCloudFrontOriginAccessIdentityAsync(array $args = [])
  17. * @method \Aws\Result deleteDistribution(array $args = [])
  18. * @method \GuzzleHttp\Promise\Promise deleteDistributionAsync(array $args = [])
  19. * @method \Aws\Result deleteStreamingDistribution(array $args = [])
  20. * @method \GuzzleHttp\Promise\Promise deleteStreamingDistributionAsync(array $args = [])
  21. * @method \Aws\Result getCloudFrontOriginAccessIdentity(array $args = [])
  22. * @method \GuzzleHttp\Promise\Promise getCloudFrontOriginAccessIdentityAsync(array $args = [])
  23. * @method \Aws\Result getCloudFrontOriginAccessIdentityConfig(array $args = [])
  24. * @method \GuzzleHttp\Promise\Promise getCloudFrontOriginAccessIdentityConfigAsync(array $args = [])
  25. * @method \Aws\Result getDistribution(array $args = [])
  26. * @method \GuzzleHttp\Promise\Promise getDistributionAsync(array $args = [])
  27. * @method \Aws\Result getDistributionConfig(array $args = [])
  28. * @method \GuzzleHttp\Promise\Promise getDistributionConfigAsync(array $args = [])
  29. * @method \Aws\Result getInvalidation(array $args = [])
  30. * @method \GuzzleHttp\Promise\Promise getInvalidationAsync(array $args = [])
  31. * @method \Aws\Result getStreamingDistribution(array $args = [])
  32. * @method \GuzzleHttp\Promise\Promise getStreamingDistributionAsync(array $args = [])
  33. * @method \Aws\Result getStreamingDistributionConfig(array $args = [])
  34. * @method \GuzzleHttp\Promise\Promise getStreamingDistributionConfigAsync(array $args = [])
  35. * @method \Aws\Result listCloudFrontOriginAccessIdentities(array $args = [])
  36. * @method \GuzzleHttp\Promise\Promise listCloudFrontOriginAccessIdentitiesAsync(array $args = [])
  37. * @method \Aws\Result listDistributions(array $args = [])
  38. * @method \GuzzleHttp\Promise\Promise listDistributionsAsync(array $args = [])
  39. * @method \Aws\Result listDistributionsByWebACLId(array $args = [])
  40. * @method \GuzzleHttp\Promise\Promise listDistributionsByWebACLIdAsync(array $args = [])
  41. * @method \Aws\Result listInvalidations(array $args = [])
  42. * @method \GuzzleHttp\Promise\Promise listInvalidationsAsync(array $args = [])
  43. * @method \Aws\Result listStreamingDistributions(array $args = [])
  44. * @method \GuzzleHttp\Promise\Promise listStreamingDistributionsAsync(array $args = [])
  45. * @method \Aws\Result updateCloudFrontOriginAccessIdentity(array $args = [])
  46. * @method \GuzzleHttp\Promise\Promise updateCloudFrontOriginAccessIdentityAsync(array $args = [])
  47. * @method \Aws\Result updateDistribution(array $args = [])
  48. * @method \GuzzleHttp\Promise\Promise updateDistributionAsync(array $args = [])
  49. * @method \Aws\Result updateStreamingDistribution(array $args = [])
  50. * @method \GuzzleHttp\Promise\Promise updateStreamingDistributionAsync(array $args = [])
  51. * @method \Aws\Result createDistributionWithTags(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  52. * @method \GuzzleHttp\Promise\Promise createDistributionWithTagsAsync(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  53. * @method \Aws\Result createStreamingDistributionWithTags(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  54. * @method \GuzzleHttp\Promise\Promise createStreamingDistributionWithTagsAsync(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  55. * @method \Aws\Result listTagsForResource(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  56. * @method \GuzzleHttp\Promise\Promise listTagsForResourceAsync(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  57. * @method \Aws\Result tagResource(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  58. * @method \GuzzleHttp\Promise\Promise tagResourceAsync(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  59. * @method \Aws\Result untagResource(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  60. * @method \GuzzleHttp\Promise\Promise untagResourceAsync(array $args = []) (supported in versions 2016-08-01, 2016-08-20, 2016-09-07, 2016-09-29, 2016-11-25, 2017-03-25)
  61. */
  62. class CloudFrontClient extends AwsClient
  63. {
  64. /**
  65. * Create a signed Amazon CloudFront URL.
  66. *
  67. * This method accepts an array of configuration options:
  68. *
  69. * - url: (string) URL of the resource being signed (can include query
  70. * string and wildcards). For example: rtmp://s5c39gqb8ow64r.cloudfront.net/videos/mp3_name.mp3
  71. * http://d111111abcdef8.cloudfront.net/images/horizon.jpg?size=large&license=yes
  72. * - policy: (string) JSON policy. Use this option when creating a signed
  73. * URL for a custom policy.
  74. * - expires: (int) UTC Unix timestamp used when signing with a canned
  75. * policy. Not required when passing a custom 'policy' option.
  76. * - key_pair_id: (string) The ID of the key pair used to sign CloudFront
  77. * URLs for private distributions.
  78. * - private_key: (string) The filepath ot the private key used to sign
  79. * CloudFront URLs for private distributions.
  80. *
  81. * @param array $options Array of configuration options used when signing
  82. *
  83. * @return string Signed URL with authentication parameters
  84. * @throws \InvalidArgumentException if url, key_pair_id, or private_key
  85. * were not specified.
  86. * @link http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/WorkingWithStreamingDistributions.html
  87. */
  88. public function getSignedUrl(array $options)
  89. {
  90. foreach (['url', 'key_pair_id', 'private_key'] as $required) {
  91. if (!isset($options[$required])) {
  92. throw new \InvalidArgumentException("$required is required");
  93. }
  94. }
  95. $urlSigner = new UrlSigner(
  96. $options['key_pair_id'],
  97. $options['private_key']
  98. );
  99. return $urlSigner->getSignedUrl(
  100. $options['url'],
  101. isset($options['expires']) ? $options['expires'] : null,
  102. isset($options['policy']) ? $options['policy'] : null
  103. );
  104. }
  105. /**
  106. * Create a signed Amazon CloudFront cookie.
  107. *
  108. * This method accepts an array of configuration options:
  109. *
  110. * - url: (string) URL of the resource being signed (can include query
  111. * string and wildcards). For example: http://d111111abcdef8.cloudfront.net/images/horizon.jpg?size=large&license=yes
  112. * - policy: (string) JSON policy. Use this option when creating a signed
  113. * URL for a custom policy.
  114. * - expires: (int) UTC Unix timestamp used when signing with a canned
  115. * policy. Not required when passing a custom 'policy' option.
  116. * - key_pair_id: (string) The ID of the key pair used to sign CloudFront
  117. * URLs for private distributions.
  118. * - private_key: (string) The filepath ot the private key used to sign
  119. * CloudFront URLs for private distributions.
  120. *
  121. * @param array $options Array of configuration options used when signing
  122. *
  123. * @return array Key => value pairs of signed cookies to set
  124. * @throws \InvalidArgumentException if url, key_pair_id, or private_key
  125. * were not specified.
  126. * @link http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/WorkingWithStreamingDistributions.html
  127. */
  128. public function getSignedCookie(array $options)
  129. {
  130. foreach (['key_pair_id', 'private_key'] as $required) {
  131. if (!isset($options[$required])) {
  132. throw new \InvalidArgumentException("$required is required");
  133. }
  134. }
  135. $cookieSigner = new CookieSigner(
  136. $options['key_pair_id'],
  137. $options['private_key']
  138. );
  139. return $cookieSigner->getSignedCookie(
  140. isset($options['url']) ? $options['url'] : null,
  141. isset($options['expires']) ? $options['expires'] : null,
  142. isset($options['policy']) ? $options['policy'] : null
  143. );
  144. }
  145. }