Class: AwsS3Bucket

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

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.



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

def bucket_name
  @bucket_name
end

#has_access_logging_enabledObject (readonly)

Returns the value of attribute has_access_logging_enabled.



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

def has_access_logging_enabled
  @has_access_logging_enabled
end

#has_default_encryption_enabledObject (readonly)

Returns the value of attribute has_default_encryption_enabled.



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

def has_default_encryption_enabled
  @has_default_encryption_enabled
end

#regionObject (readonly)

Returns the value of attribute region.



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

def region
  @region
end

Instance Method Details

#bucket_aclObject



22
23
24
25
26
# File 'lib/resources/aws/aws_s3_bucket.rb', line 22

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

#bucket_policyObject



28
29
30
# File 'lib/resources/aws/aws_s3_bucket.rb', line 28

def bucket_policy
  @bucket_policy ||= fetch_bucket_policy
end

#has_access_logging_enabled?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/resources/aws/aws_s3_bucket.rb', line 47

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)


41
42
43
44
45
# File 'lib/resources/aws/aws_s3_bucket.rb', line 41

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)


33
34
35
36
37
38
39
# File 'lib/resources/aws/aws_s3_bucket.rb', line 33

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



18
19
20
# File 'lib/resources/aws/aws_s3_bucket.rb', line 18

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