Class: AwsS3BucketObject

Inherits:
Object
  • Object
show all
Includes:
AwsSingularResourceMixin
Defined in:
lib/resources/aws/aws_s3_bucket_object.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.



14
15
16
# File 'lib/resources/aws/aws_s3_bucket_object.rb', line 14

def bucket_name
  @bucket_name
end

#keyObject (readonly)

Returns the value of attribute key.



14
15
16
# File 'lib/resources/aws/aws_s3_bucket_object.rb', line 14

def key
  @key
end

Instance Method Details

#object_aclObject



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

def object_acl
  return @object_acl if defined? @object_acl
  catch_aws_errors do
    @object_acl = BackendFactory.create(inspec_runner).get_object_acl(bucket: bucket_name, key: key).grants
  end
  @object_acl
end

#public?Boolean

RSpec will alias this to be_public

Returns:

  • (Boolean)


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

def public?
  # first line just for formatting
  false || \
    object_acl.any? { |g| g.grantee.type == 'Group' && g.grantee.uri =~ /AllUsers/ } || \
    object_acl.any? { |g| g.grantee.type == 'Group' && g.grantee.uri =~ /AuthenticatedUsers/ }
end

#to_sObject



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

def to_s
  # keep the format that aws uses.
  "s3://#{@bucket_name}/#{@key}"
end