Last active
April 6, 2023 18:17
-
-
Save dynamicguy/719dd51c5488cc87c9d855fc620ced24 to your computer and use it in GitHub Desktop.
Revisions
-
dynamicguy revised this gist
Apr 6, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,7 @@ def initialize(bucket) @bucket = bucket end # Lists object in a bucket and update it's mime type. # # @param start [Integer] The maximum number of objects to list. # @param max_objects [Integer] The maximum number of objects to list. -
dynamicguy renamed this gist
Apr 6, 2023 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
dynamicguy revised this gist
Apr 5, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ def list_objects(start, max_objects) def run_script bucket_name = "oscar-dev-document-service" if ARGV.length != 2 puts "We need exactly two arguments. a start and limit. Example: ruby s3batch.rb 0 2" exit -
dynamicguy revised this gist
Apr 5, 2023 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ def list_objects(start, max_objects) source = Aws::S3::Object.new(obj_summary.bucket_name, obj_summary.key) target = source mime = Rack::Mime.mime_type('.' + obj_summary.key.split('.').last) puts "processing key: #{obj_summary.key} to set content type as: #{mime}" target.copy_from(source, content_type: mime, metadata_directive: 'REPLACE') end count += 1 @@ -38,13 +38,15 @@ def list_objects(start, max_objects) def run_script bucket_name = "oscar-dev-document-service" puts ARGV[1] if ARGV.length != 2 puts "We need exactly two arguments. a start and limit. Example: ruby s3batch.rb 0 2" exit end bkt = Aws::S3::Bucket.new(bucket_name) wrapper = BucketListObjectsWrapper.new(bkt) count = wrapper.list_objects(ARGV[0].to_i, ARGV[1].to_i) puts "Updated #{count} objects out of #{bkt.objects.count}" end run_script if $PROGRAM_NAME == __FILE__ -
dynamicguy created this gist
Apr 5, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ #!/usr/bin/env ruby require 'aws-sdk-s3' require 'rack' class BucketListObjectsWrapper attr_reader :bucket def initialize(bucket) @bucket = bucket end # Lists object in a bucket update it's mime type. # # @param start [Integer] The maximum number of objects to list. # @param max_objects [Integer] The maximum number of objects to list. # @return [Integer] The number of objects listed. def list_objects(start, max_objects) count = 0 puts "The objects in #{@bucket.name} are:" @bucket.objects.each do |obj_summary| if count >= start source = Aws::S3::Object.new(obj_summary.bucket_name, obj_summary.key) target = source mime = Rack::Mime.mime_type('.' + obj_summary.key.split('.').last) puts "processing key: \t#{obj_summary.key} to set content type as: \t#{mime}" target.copy_from(source, content_type: mime, metadata_directive: 'REPLACE') end count += 1 break if count == max_objects end count rescue Aws::Errors::ServiceError => e puts "Couldn't list objects in bucket #{bucket.name}. Here's why: #{e.message}" 0 end end def run_script bucket_name = "oscar-dev-document-service" if ARGV.length != 2 puts "We need exactly two arguments. a start and limit. Example: ruby s3batch.rb 0 2" exit end wrapper = BucketListObjectsWrapper.new(Aws::S3::Bucket.new(bucket_name)) count = wrapper.list_objects(ARGV[0].to_i, ARGV[1].to_i) puts "Listed #{count} objects." end run_script if $PROGRAM_NAME == __FILE__