Sha256: a7a6e96c5214f4a16f2ff8e1b417e458922d6a38898cd1bac9f40ac7308894e4

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

module Jets::Cfn::Resource::S3
  class JetsBucket < Bucket
    def initialize
      @bucket_logical_id = "S3Bucket"
      @props = props
    end

    def props
      props = {
        PublicAccessBlockConfiguration: {
          BlockPublicAcls: false
          # BlockPublicPolicy: false,
          # IgnorePublicAcls: false,
          # RestrictPublicBuckets: false
        },
        OwnershipControls: {
          Rules: [{ObjectOwnership: "ObjectWriter"}]
        },
        BucketEncryption: {
          ServerSideEncryptionConfiguration: [
            ServerSideEncryptionByDefault: {
              SSEAlgorithm: "AES256"
            }
          ]
        }
      }
      # CorsConfiguration to allow assets to serve from the bucket
      props[:CorsConfiguration] = Jets.bootstrap.config.s3_bucket.cors_configuration
      props
    end

    class << self
      include Jets::AwsServices

      # Usage:
      #   Jets::Cfn::Resource::S3::JetsBucket.name
      @@name = nil
      def name
        return @@name if @@name
        return "fake-bucket" if ENV["JETS_NO_INTERNET"] || ENV["JETS_TEMPLATES"]

        resp = nil
        begin
          resp = cfn.describe_stacks(stack_name: Jets::Names.parent_stack_name)
        rescue Aws::CloudFormation::Errors::ValidationError => e
          if e.message.include?("does not exist")
            return "no-bucket-yet" # for jets build without s3 bucket yet
          else
            raise
          end
        end

        output = resp.stacks[0].outputs.find { |o| o.output_key == "S3Bucket" }
        # The output can be nil if the stack failed and is in rollback state
        @@name = output.output_value if output # cache only once found
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jets-6.0.5 lib/jets/cfn/resource/s3/jets_bucket.rb
jets-6.0.4 lib/jets/cfn/resource/s3/jets_bucket.rb
jets-6.0.3 lib/jets/cfn/resource/s3/jets_bucket.rb
jets-6.0.2 lib/jets/cfn/resource/s3/jets_bucket.rb