Class: AWSPolicyFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/bucket_client/aws/aws_policy_factory.rb

Instance Method Summary collapse

Instance Method Details

#generate_policy(access, key) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bucket_client/aws/aws_policy_factory.rb', line 4

def generate_policy(access, key)
	statements = []
	if access === :public
		# uuid_2 = "69cab402-0674-40e6-9915-982b92016d6a"
		uuid_2 = SecureRandom.uuid.to_s
		policy_statement = {
			"Sid": "AllowPublicRead#{uuid_2}",
			"Action": ["s3:GetObject"],
			"Effect": "Allow",
			"Resource": "arn:aws:s3:::#{key}/*",
			"Principal": "*"
		}
		statements.push policy_statement
	end
	uuid_1 = SecureRandom.uuid.to_s
	# uuid_1 = "668c8c5d-3efb-458d-bebb-6fa194b55732"
	{
		"Id": "ReadPolicy#{uuid_1}",
		"Version": "2012-10-17",
		"Statement": statements
	}
end