class Codepipe::Pipeline::S3Bucket
Public Class Methods
name()
click to toggle source
# File lib/codepipe/pipeline/s3_bucket.rb, line 10 def name new.name end
Public Instance Methods
bucket_name()
click to toggle source
# File lib/codepipe/pipeline/s3_bucket.rb, line 22 def bucket_name "codepipeline-#{aws.region}-#{aws.account}" end
ensure_exists(name)
click to toggle source
# File lib/codepipe/pipeline/s3_bucket.rb, line 26 def ensure_exists(name) return if exists?(name) || ENV['TEST'] s3.create_bucket(bucket: name) policy = { "Version": "2012-10-17", "Id": "SSEAndSSLPolicy", "Statement": [ { "Sid": "DenyUnEncryptedObjectUploads", "Effect": "Deny", "Principal": "*", "Action": "s3:PutObject", "Resource": "arn:aws:s3:::#{name}/*", "Condition": { "StringNotEquals": { "s3:x-amz-server-side-encryption": "aws:kms" } } }, { "Sid": "DenyInsecureConnections", "Effect": "Deny", "Principal": "*", "Action": "s3:*", "Resource": "arn:aws:s3:::#{name}/*", "Condition": { "Bool": { "aws:SecureTransport": "false" } } } ] } s3.put_bucket_policy( bucket: name, policy: JSON.dump(policy), ) rescue Aws::S3::Errors::BucketAlreadyExists => e puts "ERROR #{e.class}: #{e.message}".color(:red) puts "Bucket name: #{name}" exit 1 end
exists?(name)
click to toggle source
# File lib/codepipe/pipeline/s3_bucket.rb, line 69 def exists?(name) begin s3.head_bucket(bucket: name) true rescue Aws::S3::Errors::BucketAlreadyOwnedByYou, Aws::S3::Errors::Http301Error # These exceptions indicate bucket already exists # Aws::S3::Errors::Http301Error could be inaccurate but compromising for simplicity true rescue false end end
name()
click to toggle source
# File lib/codepipe/pipeline/s3_bucket.rb, line 16 def name ensure_exists(bucket_name) bucket_name end
Private Instance Methods
aws()
click to toggle source
# File lib/codepipe/pipeline/s3_bucket.rb, line 83 def aws AwsData.new end