Sha256: 97e255d22c5ef6639c320b04963328a1bb1fee4f3826a1a146a594ad6fcacb3c

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

module Cloudster
  #==CloudFront resource
  class CloudFront

    # Initialize CloudFront
    #
    # ==== Notes
    # options parameter must include values for :name
    #
    # ==== Examples
    #   cloud_front = Cloudster::CloudFront.new(:name => 'CloudFront')
    #
    # ==== Parameters
    # * options<~Hash> -
    #     * :name: String containing the name of CloudFront resource
    def initialize(options = {})
      require_options(options, [:name])
      @name = options[:name]
    end

    # Merges the required CloudFormation template for adding an CloudFront to an s3 instance
    #
    #
    # ==== Examples
    #   cloud_front = Cloudster::CloudFront.new(:name => 'CloudFrontDistribution')
    #   s3 = Cloudster::S3.new(
    #    :name => 'S3Resource',
    #    :access_control => 'PublicRead'
    #   )
    #
    #   cloud_front.add_to s3
    #
    # ==== Parameters
    # * instance of s3
    def add_to(s3)
      s3_template = s3.template
      @instance_name = s3.name
      cloud_front_template = template
      s3.template.deep_merge(cloud_front_template)
    end

    private
      def template
        return "Resources" => {
          @name => {
              "Type" => "AWS::CloudFront::Distribution",
              "Properties" => {
                "DistributionConfig" => {
                  "S3Origin" => {
                    "DNSName"=> {"Fn::GetAtt" => [@instance_name, "DomainName"]},
                  },
                  "Enabled" => "true"
                }
              }
          }
        }

      end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cloudster-2.19.2 lib/cloudster/cloud_front.rb
cloudster-2.19.1 lib/cloudster/cloud_front.rb
cloudster-2.19.0 lib/cloudster/cloud_front.rb
cloudster-2.18.0 lib/cloudster/cloud_front.rb
cloudster-2.17.0 lib/cloudster/cloud_front.rb