Class: AwsS3Bucket

Inherits:
Object
  • Object
show all
Includes:
AwsSingularResourceMixin
Defined in:
lib/resources/aws/aws_s3_bucket.rb

Overview

author: Matthew Dromazos

Defined Under Namespace

Classes: Backend

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AwsSingularResourceMixin

#exists?, included

Methods included from AwsResourceMixin

#catch_aws_errors, #check_resource_param_names, #initialize, #inspec_runner

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



13
14
15
# File 'lib/resources/aws/aws_s3_bucket.rb', line 13

def bucket_name
  @bucket_name
end

#has_access_logging_enabledObject (readonly)

Returns the value of attribute has_access_logging_enabled.



13
14
15
# File 'lib/resources/aws/aws_s3_bucket.rb', line 13

def has_access_logging_enabled
  @has_access_logging_enabled
end

#has_default_encryption_enabledObject (readonly)

Returns the value of attribute has_default_encryption_enabled.



13
14
15
# File 'lib/resources/aws/aws_s3_bucket.rb', line 13

def has_default_encryption_enabled
  @has_default_encryption_enabled
end

#regionObject (readonly)

Returns the value of attribute region.



13
14
15
# File 'lib/resources/aws/aws_s3_bucket.rb', line 13

def region
  @region
end

Instance Method Details

#bucket_aclObject



19
20
21
22
23
# File 'lib/resources/aws/aws_s3_bucket.rb', line 19

def bucket_acl
  catch_aws_errors do
    @bucket_acl ||= BackendFactory.create(inspec_runner).get_bucket_acl(bucket: bucket_name).grants
  end
end

#bucket_policyObject



25
26
27
# File 'lib/resources/aws/aws_s3_bucket.rb', line 25

def bucket_policy
  @bucket_policy ||= fetch_bucket_policy
end

#has_access_logging_enabled?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'lib/resources/aws/aws_s3_bucket.rb', line 43

def has_access_logging_enabled?
  return false unless @exists
  catch_aws_errors do
    @has_access_logging_enabled ||= !BackendFactory.create(inspec_runner).get_bucket_logging(bucket: bucket_name).logging_enabled.nil?
  end
end

#has_default_encryption_enabled?Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/resources/aws/aws_s3_bucket.rb', line 38

def has_default_encryption_enabled?
  return false unless @exists
  @has_default_encryption_enabled ||= fetch_bucket_encryption_configuration
end

#public?Boolean

RSpec will alias this to be_public

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/resources/aws/aws_s3_bucket.rb', line 30

def public?
  # first line just for formatting
  false || \
    bucket_acl.any? { |g| g.grantee.type == 'Group' && g.grantee.uri =~ /AllUsers/ } || \
    bucket_acl.any? { |g| g.grantee.type == 'Group' && g.grantee.uri =~ /AuthenticatedUsers/ } || \
    bucket_policy.any? { |s| s.effect == 'Allow' && s.principal == '*' }
end

#to_sObject



15
16
17
# File 'lib/resources/aws/aws_s3_bucket.rb', line 15

def to_s
  "S3 Bucket #{@bucket_name}"
end