File: get_streaming_distribution.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (69 lines) | stat: -rw-r--r-- 2,810 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Fog
  module AWS
    class CDN
      class Real
        require 'fog/aws/parsers/cdn/streaming_distribution'

        # Get information about a streaming distribution from CloudFront.
        #
        # @param distribution_id [String] Id of distribution.
        #
        # @return [Excon::Response]
        #   * body [Hash]:
        #     * S3Origin [Hash]:
        #       * DNSName [String] - Origin to associate with distribution, ie 'mybucket.s3.amazonaws.com'.
        #       * OriginAccessIdentity [String] - Optional: Used when serving private content.
        #     * Id [String] - Id of distribution.
        #     * LastModifiedTime [String] - Timestamp of last modification of distribution.
        #     * Status [String] - Status of distribution.
        #     * StreamingDistributionConfig [Array]:
        #       * CallerReference [String] - Used to prevent replay, defaults to Time.now.to_i.to_s.
        #       * CNAME [Array] - Array of associated cnames.
        #       * Comment [String] - Comment associated with distribution.
        #       * Enabled [Boolean] - Whether or not distribution is enabled.
        #       * InProgressInvalidationBatches [Integer] - Number of invalidation batches in progress.
        #       * Logging [Hash]:
        #         * Bucket [String] - Bucket logs are stored in.
        #         * Prefix [String] - Prefix logs are stored with.
        #       * Origin [String] - S3 origin bucket.
        #       * TrustedSigners [Array] - Trusted signers.
        #
        # @see http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/GetStreamingDistribution.html

        def get_streaming_distribution(distribution_id)
          request({
            :expects    => 200,
            :idempotent => true,
            :method     => 'GET',
            :parser     => Fog::Parsers::AWS::CDN::StreamingDistribution.new,
            :path       => "/streaming-distribution/#{distribution_id}"
          })
        end
      end

      class Mock
        def get_streaming_distribution(distribution_id)
          response = Excon::Response.new

          distribution = self.data[:streaming_distributions][distribution_id]
          unless distribution
            Fog::AWS::CDN::Mock.error(:no_such_streaming_distribution)
          end

          if distribution['Status'] == 'InProgress' && (Time.now - Time.parse(distribution['LastModifiedTime']) >= Fog::Mock.delay * 2)
            distribution['Status'] = 'Deployed'
          end

          etag = Fog::AWS::CDN::Mock.generic_id
          response.status = 200
          response.body = distribution.reject { |k,v| k == 'ETag' }

          response.headers['ETag'] = etag
          distribution['ETag'] = etag

          response
        end
      end
    end
  end
end