Class: Jets::Cfn::Resource::S3::JetsBucket

Inherits:
Bucket
  • Object
show all
Extended by:
AwsServices
Defined in:
lib/jets/cfn/resource/s3/jets_bucket.rb

Constant Summary collapse

@@name =
nil

Instance Attribute Summary

Attributes inherited from Bucket

#bucket_logical_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AwsServices

apigateway, aws_lambda, aws_options, cfn, dynamodb, logs, s3, s3_resource, sns, sqs, sts

Methods included from AwsServices::StackStatus

#lookup, #stack_exists?, #stack_in_progress?

Methods included from AwsServices::GlobalMemoist

included

Methods inherited from Bucket

#definition, #outputs

Methods inherited from Base

#attributes, #logical_id, #outputs, #parameters, #permission, #properties, #replacements, #replacer, #standarize, #template, truncate_id, #type

Methods included from Util::Camelize

#camelize

Constructor Details

#initializeJetsBucket

Returns a new instance of JetsBucket.



3
4
5
6
# File 'lib/jets/cfn/resource/s3/jets_bucket.rb', line 3

def initialize
  @bucket_logical_id = "S3Bucket"
  @props = props
end

Class Method Details

.nameObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jets/cfn/resource/s3/jets_bucket.rb', line 48

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') && Jets::Command.original_cli_command == 'build' # jets build
      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'}
  @@name = output.output_value # cache only once found
end

Instance Method Details

#cors_configurationObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/jets/cfn/resource/s3/jets_bucket.rb', line 31

def cors_configuration
  Jets.config.api.s3_cors_configuration || {
    CorsRules: [{
      AllowedHeaders: ["*"],
      AllowedMethods: ["GET"],
      AllowedOrigins: ["*"],
      ExposedHeaders: [],
    }]
  }
end

#propsObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jets/cfn/resource/s3/jets_bucket.rb', line 8

def props
  props = {
    PublicAccessBlockConfiguration: {
      BlockPublicAcls: false,
      # BlockPublicPolicy: false,
      # IgnorePublicAcls: false,
      # RestrictPublicBuckets: false
    },
    OwnershipControls: {
      Rules: [{ObjectOwnership: "ObjectWriter"}]
    },
    BucketEncryption: {
      ServerSideEncryptionConfiguration: [
        ServerSideEncryptionByDefault: {
          SSEAlgorithm: "AES256"
        }
      ]
    },
  }
  props[:CorsConfiguration] = cors_configuration # dont check config.api.cors since javascript_importmap_tags also uses
  props
end