Class: Cumulus::S3::Manager
- Inherits:
-
Common::Manager
- Object
- Common::Manager
- Cumulus::S3::Manager
- Defined in:
- lib/s3/manager/Manager.rb
Instance Method Summary collapse
- #added_diff(local) ⇒ Object
- #aws_resources ⇒ Object
- #create(local) ⇒ Object
- #diff_resource(local, aws) ⇒ Object
- #local_resources ⇒ Object
- #migrate ⇒ Object
- #resource_name ⇒ Object
- #unmanaged_diff(aws) ⇒ Object
- #update(local, diffs) ⇒ Object
Methods inherited from Common::Manager
#diff, #diff_one, #filter_local, #initialize, #list, #sync, #sync_one
Constructor Details
This class inherits a constructor from Cumulus::Common::Manager
Instance Method Details
#added_diff(local) ⇒ Object
59 60 61 |
# File 'lib/s3/manager/Manager.rb', line 59 def added_diff(local) BucketDiff.added(local) end |
#aws_resources ⇒ Object
51 52 53 |
# File 'lib/s3/manager/Manager.rb', line 51 def aws_resources S3.buckets end |
#create(local) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/s3/manager/Manager.rb', line 71 def create(local) S3.client(local.region).create_bucket({ bucket: local.name, create_bucket_configuration: if local.region != "us-east-1" then { location_constraint: local.region } end }) S3.refresh! update_policy(local.region, local.name, local.policy) update_cors(local.region, local.name, local.cors) update_grants(local.region, local.name, local.grants) update_versioning(local.region, local.name, local.versioning) update_logging(local.region, local.name, local.logging) update_website(local.region, local.name, local.website) update_lifecycle(local.region, local.name, local.lifecycle) update_notifications(local.region, local.name, local.notifications) update_replication(local.region, local.name, local.replication) update_default_encryption(local.region, local.name, local.default_encryption) (local.region, local.name, local.) if !local..empty? end |
#diff_resource(local, aws) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/s3/manager/Manager.rb', line 63 def diff_resource(local, aws) if Configuration.instance.s3.print_progress puts "checking for differences in #{local.name}" end full_aws = S3.full_bucket(aws.name) local.diff(full_aws) end |
#local_resources ⇒ Object
47 48 49 |
# File 'lib/s3/manager/Manager.rb', line 47 def local_resources Hash[Loader.buckets.map { |bucket| [bucket.name, bucket] }] end |
#migrate ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/s3/manager/Manager.rb', line 12 def migrate buckets_dir = "#{@migration_root}/buckets" cors_dir = "#{@migration_root}/cors" policy_dir = "#{@migration_root}/policies" [@migration_root, buckets_dir, cors_dir, policy_dir].each do |dir| if !Dir.exists?(dir) Dir.mkdir(dir) end end cors = {} policies = {} aws_resources.each_value do |resource| puts "Processing #{resource.name}..." full_aws = S3.full_bucket(resource.name) config = BucketConfig.new(resource.name) new_policy_key, new_cors_key = config.populate!(full_aws, cors, policies) puts "Writing #{resource.name} configuration to file..." if new_policy_key File.open("#{policy_dir}/#{new_policy_key}.json", "w") { |f| f.write(policies[new_policy_key]) } end if new_cors_key File.open("#{cors_dir}/#{new_cors_key}.json", "w") { |f| f.write(cors[new_cors_key]) } end File.open("#{buckets_dir}/#{resource.name}.json", "w") { |f| f.write(config.pretty_json) } end end |
#resource_name ⇒ Object
43 44 45 |
# File 'lib/s3/manager/Manager.rb', line 43 def resource_name "Bucket" end |
#unmanaged_diff(aws) ⇒ Object
55 56 57 |
# File 'lib/s3/manager/Manager.rb', line 55 def unmanaged_diff(aws) BucketDiff.unmanaged(aws) end |
#update(local, diffs) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/s3/manager/Manager.rb', line 92 def update(local, diffs) diffs.each do |diff| if diff.type == BucketChange::TAGS puts Colors.blue("\tupdating tags...") (diff.local.region, diff.local.name, diff.local.) elsif diff.type == BucketChange::POLICY puts Colors.blue("\tupdating policy...") update_policy(diff.local.region, diff.local.name, diff.local.policy) elsif diff.type == BucketChange::CORS puts Colors.blue("\tupdating CORS rules...") update_cors(diff.local.region, diff.local.name, diff.local.cors) elsif diff.type == BucketChange::WEBSITE puts Colors.blue("\tupdating S3 bucket website...") update_website(diff.local.region, diff.local.name, diff.local.website) elsif diff.type == BucketChange::LOGGING puts Colors.blue("\tupdating S3 bucket logging..") update_logging(diff.local.region, diff.local.name, diff.local.logging) elsif diff.type == BucketChange::VERSIONING puts Colors.blue("\tupdating versioning status...") update_versioning(diff.local.region, diff.local.name, diff.local.versioning) elsif diff.type == BucketChange::GRANTS puts Colors.blue("\tupdating grants...") update_grants(diff.local.region, diff.local.name, diff.local.grants) elsif diff.type == BucketChange::LIFECYCLE puts Colors.blue("\tupdating lifecycle...") update_lifecycle(diff.local.region, diff.local.name, diff.local.lifecycle) elsif diff.type == BucketChange::NOTIFICATIONS puts Colors.blue("\tupdating notifications...") update_notifications(diff.local.region, diff.local.name, diff.local.notifications) elsif diff.type == BucketChange::REPLICATION puts Colors.blue("\tupdating replication...") update_replication(diff.local.region, diff.local.name, diff.local.replication) elsif diff.type == BucketChange::ENCRYPTION puts Colors.blue("\tupdating default encryption...") update_default_encryption(diff.local.region, diff.local.name, diff.local.default_encryption) end end end |