Class: AwsS3BucketObject

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



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

def bucket_name
  @bucket_name
end

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

#object_aclObject



24
25
26
27
28
29
30
31
# File 'lib/resources/aws/aws_s3_bucket_object.rb', line 24

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)


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

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



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

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