bukelatta 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/bukelatta +2 -1
- data/lib/bukelatta/driver.rb +15 -6
- data/lib/bukelatta/exporter.rb +8 -3
- data/lib/bukelatta/ext/aws_s3_bucket_ext.rb +25 -0
- data/lib/bukelatta/version.rb +1 -1
- data/lib/bukelatta.rb +1 -1
- metadata +3 -3
- data/lib/bukelatta/ext/aws_s3_resource_ext.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86be96883447847f16acf96e0166721567a75681
|
4
|
+
data.tar.gz: 5c3a19f8a13b9fc0687d22bd1b18a24d7dd2640a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5eaba78d7726b8a57cffd8dc98af1b10f350ba1b57f2bdae025ae3a5be04d79ba6efeddd2a696a60394ee1cb1c63634c968ec733c8a75ce46d56adee565d8d4
|
7
|
+
data.tar.gz: a64338561ad9f7b39c1d4667d20e0da0dadaaeaa4f398b7f840247dc6cbcce63f0ae47d134c4833abc9de06077fd2e5346e3663fe24dcf1ffb5a00356cae0e2d
|
data/exe/bukelatta
CHANGED
@@ -20,7 +20,7 @@ def parse_options(argv)
|
|
20
20
|
dry_run: false,
|
21
21
|
color: true,
|
22
22
|
request_concurrency: 8,
|
23
|
-
aws: {},
|
23
|
+
aws: { ssl_verify_peer: false },
|
24
24
|
}
|
25
25
|
|
26
26
|
opt = OptionParser.new
|
@@ -64,6 +64,7 @@ def parse_options(argv)
|
|
64
64
|
options[:aws][:credentials] = credentials
|
65
65
|
end
|
66
66
|
|
67
|
+
Aws.config.update(options[:aws])
|
67
68
|
String.colorize = options[:color]
|
68
69
|
|
69
70
|
if options[:debug]
|
data/lib/bukelatta/driver.rb
CHANGED
@@ -12,8 +12,11 @@ class Bukelatta::Driver
|
|
12
12
|
log(:info, "Create Bucket `#{bucket_name}` Policy", color: :cyan)
|
13
13
|
|
14
14
|
unless @options[:dry_run]
|
15
|
-
bucket = @resource.
|
16
|
-
|
15
|
+
bucket = @resource.bucket(bucket_name)
|
16
|
+
|
17
|
+
bucket.auto_redirect do |b|
|
18
|
+
b.policy.put(policy: JSON.dump(policy))
|
19
|
+
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
@@ -21,8 +24,11 @@ class Bukelatta::Driver
|
|
21
24
|
log(:info, "Delete Bucket `#{bucket_name}` Policy", color: :red)
|
22
25
|
|
23
26
|
unless @options[:dry_run]
|
24
|
-
bucket = @resource.
|
25
|
-
|
27
|
+
bucket = @resource.bucket(bucket_name)
|
28
|
+
|
29
|
+
bucket.auto_redirect do |b|
|
30
|
+
b.policy.delete
|
31
|
+
end
|
26
32
|
end
|
27
33
|
end
|
28
34
|
|
@@ -31,8 +37,11 @@ class Bukelatta::Driver
|
|
31
37
|
log(:info, diff(old_policy, policy, color: @options[:color]), color: false)
|
32
38
|
|
33
39
|
unless @options[:dry_run]
|
34
|
-
bucket = @resource.
|
35
|
-
|
40
|
+
bucket = @resource.bucket(bucket_name)
|
41
|
+
|
42
|
+
bucket.auto_redirect do |b|
|
43
|
+
b.policy.put(policy: JSON.dump(policy))
|
44
|
+
end
|
36
45
|
end
|
37
46
|
end
|
38
47
|
end
|
data/lib/bukelatta/exporter.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
class Bukelatta::Exporter
|
2
|
+
include Bukelatta::Utils::Helper
|
3
|
+
|
2
4
|
def self.export(client, options = {})
|
3
5
|
self.new(client, options).export
|
4
6
|
end
|
@@ -15,11 +17,12 @@ class Bukelatta::Exporter
|
|
15
17
|
|
16
18
|
def export_buckets
|
17
19
|
result = {}
|
20
|
+
buckets = @resource.buckets
|
18
21
|
concurrency = @options[:request_concurrency]
|
19
22
|
|
20
|
-
buckets = @resource.buckets(concurrency: concurrency)
|
21
|
-
|
22
23
|
Parallel.each(buckets, in_threads: concurrency) do |bucket|
|
24
|
+
next unless matched?(bucket.name)
|
25
|
+
|
23
26
|
policy = export_bucket_policy(bucket)
|
24
27
|
result[bucket.name] = policy
|
25
28
|
end
|
@@ -28,7 +31,9 @@ class Bukelatta::Exporter
|
|
28
31
|
end
|
29
32
|
|
30
33
|
def export_bucket_policy(bucket)
|
31
|
-
|
34
|
+
bucket.auto_redirect do |b|
|
35
|
+
JSON.parse(b.policy.policy.string)
|
36
|
+
end
|
32
37
|
rescue Aws::S3::Errors::NoSuchBucketPolicy
|
33
38
|
nil
|
34
39
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Bukelatta::Ext
|
2
|
+
module AwsS3BucketExt
|
3
|
+
DEFULT_CONCURRENCY = 8
|
4
|
+
|
5
|
+
def auto_redirect
|
6
|
+
ret = nil
|
7
|
+
bckt = self
|
8
|
+
|
9
|
+
begin
|
10
|
+
ret = yield(bckt)
|
11
|
+
rescue Aws::S3::Errors::PermanentRedirect => e
|
12
|
+
res_body = MultiXml.parse(e.context.http_response.body.read)
|
13
|
+
edpnt = res_body['Error']['Endpoint']
|
14
|
+
clnt = Aws::S3::Client.new(endpoint: "https://#{edpnt}")
|
15
|
+
rsrc = Aws::S3::Resource.new(client: clnt)
|
16
|
+
bckt = rsrc.bucket(bckt.name)
|
17
|
+
retry
|
18
|
+
end
|
19
|
+
|
20
|
+
ret
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Aws::S3::Bucket.include(Bukelatta::Ext::AwsS3BucketExt)
|
data/lib/bukelatta/version.rb
CHANGED
data/lib/bukelatta.rb
CHANGED
@@ -10,7 +10,7 @@ require 'singleton'
|
|
10
10
|
require 'term/ansicolor'
|
11
11
|
|
12
12
|
require 'bukelatta/version'
|
13
|
-
require 'bukelatta/ext/
|
13
|
+
require 'bukelatta/ext/aws_s3_bucket_ext'
|
14
14
|
require 'bukelatta/ext/hash_ext'
|
15
15
|
require 'bukelatta/ext/string_ext'
|
16
16
|
require 'bukelatta/logger'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bukelatta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -163,7 +163,7 @@ files:
|
|
163
163
|
- lib/bukelatta/dsl/converter.rb
|
164
164
|
- lib/bukelatta/dsl/template_helper.rb
|
165
165
|
- lib/bukelatta/exporter.rb
|
166
|
-
- lib/bukelatta/ext/
|
166
|
+
- lib/bukelatta/ext/aws_s3_bucket_ext.rb
|
167
167
|
- lib/bukelatta/ext/hash_ext.rb
|
168
168
|
- lib/bukelatta/ext/string_ext.rb
|
169
169
|
- lib/bukelatta/logger.rb
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Bukelatta::Ext
|
2
|
-
module AwsS3ResourceExt
|
3
|
-
DEFULT_CONCURRENCY = 8
|
4
|
-
|
5
|
-
def buckets(options = {})
|
6
|
-
concurrency = options[:concurrency] || DEFULT_CONCURRENCY
|
7
|
-
|
8
|
-
Parallel.map(super(), in_threads: concurrency) do |b|
|
9
|
-
region_bucket0(b)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def region_bucket(name)
|
14
|
-
b = self.bucket(name)
|
15
|
-
region_bucket0(b)
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def region_bucket0(b)
|
21
|
-
begin
|
22
|
-
b.objects.limit(1).first
|
23
|
-
b
|
24
|
-
rescue Aws::S3::Errors::PermanentRedirect => e
|
25
|
-
responce_body = e.context.http_response.body.read
|
26
|
-
responce_body = MultiXml.parse(responce_body)
|
27
|
-
endpoint = responce_body['Error']['Endpoint']
|
28
|
-
client = Aws::S3::Client.new(endpoint: "https://#{endpoint}")
|
29
|
-
resource = Aws::S3::Resource.new(client: client)
|
30
|
-
resource.bucket(b.name)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
Aws::S3::Resource.prepend(Bukelatta::Ext::AwsS3ResourceExt)
|