lib/cicd/builder/mixlib/repo/S3.rb in cicd-builder-0.9.27 vs lib/cicd/builder/mixlib/repo/S3.rb in cicd-builder-0.9.28
- old
+ new
@@ -14,10 +14,11 @@
# ---------------------------------------------------------------------------------------------------------------
def getS3()
region = ENV['AWS_REGION'] || ::Aws.config[:region] || 'us-east-1'
unless @s3
+ # noinspection RubyArgCount
@s3 = ::Aws::S3::Client.new(region: region)
end
unless @s3 and ((@s3.config.access_key_id and @s3.config.secret_access_key) or @s3.config.credentials)
@logger.warn "Unable to find AWS credentials in standard locations:
ENV['AWS_ACCESS_KEY'] and ENV['AWS_SECRET_ACCESS_KEY']
@@ -27,10 +28,11 @@
"
if ENV['AWS_PROFILE']
@logger.info "Trying profile '#{ENV['AWS_PROFILE']}' explicitly"
creds = Aws::SharedCredentials.new( path: File.expand_path('~/.aws/credentials'), profile: ENV['AWS_PROFILE'] )
if creds.loadable?
+ # noinspection RubyArgCount
@s3 = ::Aws::S3::Client.new(region: region, credentials: creds)
end
else
@logger.warn 'No AWS_PROFILE defined'
end
@@ -46,25 +48,27 @@
s3 = getS3()
artifacts.each{|art|
s3_obj = maybeS3Object(art[:key], s3)
upload = false
- md5 = nil
if art[:data][:data]
# md5 = Digest::MD5.hexdigest(art[:data][:data])
tempArtifactFile('artifact', art[:data])
end
if s3_obj.nil?
upload = true
+ etag = ''
else
@logger.info "s3://#{ENV['AWS_S3_BUCKET']}/#{art[:key]} exists"
etag = s3_obj.etag.gsub(/"/, '')
- md5 = if art[:data].has_key?(:file)
- # md5 = Digest::MD5.file(art[:data][:file]).hexdigest
- calcLocalETag(etag, art[:data][:file])
- else
- raise "Internal error: No :file in #{art[:data].ai}"
- end
+ end
+ md5 = if art[:data].has_key?(:file)
+ # md5 = Digest::MD5.file(art[:data][:file]).hexdigest
+ calcLocalETag(etag, art[:data][:file])
+ else
+ raise "Internal error: No :file in #{art[:data].ai}"
+ end
+ unless s3_obj.nil?
unless etag == md5
checksum = s3_obj.metadata[:checksum]
unless checksum and checksum == md5
@logger.warn "s3://#{ENV['AWS_S3_BUCKET']}/#{art[:key]} is different from our #{art[:key]}(#{s3_obj.etag} <=> #{md5})"
upload = true
\ No newline at end of file