11require 'aws-sdk-s3'
2+ require_relative 'output'
23require_relative 'exec_command'
34
45module S3
@@ -15,23 +16,23 @@ def initialize(endpoint: "")
1516 end
1617 def get ( bucket , key , file_name )
1718 bucket , key = rationalize ( bucket , key )
18- puts "Downloading the #{ key } from #{ bucket } to #{ file_name } "
19+ Output . say "Downloading the #{ key } from #{ bucket } to #{ file_name } "
1920 path = File . dirname ( file_name )
2021 FileUtils . mkdir_p ( path )
2122 File . open ( file_name , 'wb' ) do |file |
2223 @s3 . get_object ( { bucket :bucket , key :key , response_target : file } )
2324 end
24- puts "Finished Downloading the #{ key } from #{ bucket } to #{ file_name } "
25+ Output . say "Finished Downloading the #{ key } from #{ bucket } to #{ file_name } "
2526 end
2627 def put ( bucket , key , file_name )
2728 bucket , key = rationalize ( bucket , key )
28- puts "Uploading the #{ file_name } to #{ bucket } :#{ key } "
29+ Output . say "Uploading the #{ file_name } to #{ bucket } :#{ key } "
2930 @s3_resource . bucket ( bucket ) . object ( key ) . upload_file ( file_name )
30- puts "Finished uploading the #{ file_name } to #{ bucket } :#{ key } "
31+ Output . say "Finished uploading the #{ file_name } to #{ bucket } :#{ key } "
3132 end
3233 def list ( bucket )
3334 bucket , prefix = rationalize ( bucket , '' )
34- puts "Listing bucket #{ bucket } with prefix #{ prefix } "
35+ Output . say "Listing bucket #{ bucket } with prefix #{ prefix } "
3536 resp = @s3 . list_objects ( {
3637 bucket : bucket ,
3738 delimiter : '/' ,
@@ -40,9 +41,9 @@ def list(bucket)
4041 resp . to_h [ :contents ] . map { |x | x [ :key ] }
4142 end
4243 def clear ( bucket )
43- puts "Clearing bucket #{ bucket } "
44+ Output . say "Clearing bucket #{ bucket } "
4445 @s3_resource . bucket ( bucket ) . clear!
45- puts "Finished: clearing bucket #{ bucket } "
46+ Output . puts "Finished: clearing bucket #{ bucket } "
4647 end
4748 private
4849 # Our ci passes the bucket and key as bucket: bucket/path/to/file,
@@ -56,7 +57,7 @@ def rationalize(bucket, key)
5657 end
5758
5859 def self . test_upload_permissions ( bucket , endpoint = "" )
59- puts "Testing upload permissions for #{ bucket } "
60+ Output . say "Testing upload permissions for #{ bucket } "
6061 tempfile = Tempfile . new ( "stemcell-permissions-tempfile" )
6162 s3_client = Client . new ( endpoint : endpoint )
6263 s3_client . put ( bucket , 'test-upload-permissions' , tempfile . path )
0 commit comments