piculet 0.2.7 → 0.2.8.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +74 -0
- data/bin/piculet +47 -28
- data/lib/piculet/client.rb +27 -5
- data/lib/piculet/dsl/converter.rb +3 -2
- data/lib/piculet/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 964c624907487d13b2db743957f28a4d6e20e94c
|
4
|
+
data.tar.gz: 744750153bd12e4cda705d5c8b66042a17246d05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2a3df7fed7c6ca29e38f197ed03e2de54b00f305bdb76b014b0b42ff1cdc4f257e4209f8c33d5fda0347383774bb92eb1a8d97159f2d530880fe93568de2947
|
7
|
+
data.tar.gz: 651d72e1ed2e96c8a04288b1494748c6f006369891993cf2f3d6cd40b5fa4da3a7e64b88abc5ce18aecb3f047b04bff531823cd29742a4af4d2f5702783d82c4
|
data/README.md
CHANGED
@@ -53,6 +53,7 @@ Usage: piculet [options]
|
|
53
53
|
-e, --export
|
54
54
|
-o, --output FILE
|
55
55
|
--split
|
56
|
+
--format=FORMAT
|
56
57
|
--no-color
|
57
58
|
--debug
|
58
59
|
```
|
@@ -168,5 +169,78 @@ ec2 "vpc-XXXXXXXX" do
|
|
168
169
|
end
|
169
170
|
```
|
170
171
|
|
172
|
+
## JSON Groupfile
|
173
|
+
|
174
|
+
```json
|
175
|
+
{
|
176
|
+
"vpc-12345678": {
|
177
|
+
"sg-12345678": {
|
178
|
+
"name": "default",
|
179
|
+
"description": "default VPC security group",
|
180
|
+
"tags": {
|
181
|
+
"key": "val"
|
182
|
+
},
|
183
|
+
"owner_id": "123456789012",
|
184
|
+
"ingress": [
|
185
|
+
{
|
186
|
+
"protocol": "any",
|
187
|
+
"port_range": null,
|
188
|
+
"ip_ranges": [
|
189
|
+
|
190
|
+
],
|
191
|
+
"groups": [
|
192
|
+
{
|
193
|
+
"id": "sg-12345678",
|
194
|
+
"name": "default",
|
195
|
+
"owner_id": "123456789012"
|
196
|
+
}
|
197
|
+
]
|
198
|
+
},
|
199
|
+
{
|
200
|
+
"protocol": "tcp",
|
201
|
+
"port_range": "22..22",
|
202
|
+
"ip_ranges": [
|
203
|
+
"0.0.0.0/0"
|
204
|
+
],
|
205
|
+
"groups": [
|
206
|
+
|
207
|
+
]
|
208
|
+
},
|
209
|
+
{
|
210
|
+
"protocol": "tcp",
|
211
|
+
"port_range": "80..80",
|
212
|
+
"ip_ranges": [
|
213
|
+
"0.0.0.0/0"
|
214
|
+
],
|
215
|
+
"groups": [
|
216
|
+
|
217
|
+
]
|
218
|
+
}
|
219
|
+
],
|
220
|
+
"egress": [
|
221
|
+
{
|
222
|
+
"protocol": "any",
|
223
|
+
"port_range": null,
|
224
|
+
"ip_ranges": [
|
225
|
+
"0.0.0.0/0"
|
226
|
+
],
|
227
|
+
"groups": [
|
228
|
+
|
229
|
+
]
|
230
|
+
}
|
231
|
+
]
|
232
|
+
}
|
233
|
+
}
|
234
|
+
}
|
235
|
+
```
|
236
|
+
|
237
|
+
### Export
|
238
|
+
|
239
|
+
$ piculet --export --format=json -o Groupfile.json
|
240
|
+
|
241
|
+
### Apply
|
242
|
+
|
243
|
+
$ piculet --apply --format=json -f Groupfile.json
|
244
|
+
|
171
245
|
## Similar tools
|
172
246
|
* [Codenize.tools](http://codenize.tools/)
|
data/bin/piculet
CHANGED
@@ -17,6 +17,7 @@ EOS
|
|
17
17
|
|
18
18
|
options = {
|
19
19
|
:dry_run => false,
|
20
|
+
:format => :json,
|
20
21
|
:color => true,
|
21
22
|
:debug => false,
|
22
23
|
}
|
@@ -29,22 +30,23 @@ ARGV.options do |opt|
|
|
29
30
|
profile_name = nil
|
30
31
|
credentials_path = nil
|
31
32
|
|
32
|
-
opt.on('-p', '--profile PROFILE_NAME')
|
33
|
-
opt.on('' , '--credentials-path PATH')
|
34
|
-
opt.on('-k', '--access-key ACCESS_KEY')
|
35
|
-
opt.on('-s', '--secret-key SECRET_KEY')
|
36
|
-
opt.on('-r', '--region REGION')
|
37
|
-
opt.on('-a', '--apply')
|
38
|
-
opt.on('-f', '--file FILE')
|
39
|
-
opt.on('-n', '--names SG_LIST', Array)
|
40
|
-
opt.on('-x', '--exclude SG_LIST', Array)
|
41
|
-
opt.on('', '--ec2s VPC_IDS', Array)
|
42
|
-
opt.on('', '--dry-run')
|
43
|
-
opt.on('-e', '--export')
|
44
|
-
opt.on('-o', '--output FILE')
|
45
|
-
opt.on('', '--split')
|
46
|
-
opt.on(''
|
47
|
-
opt.on('' , '--
|
33
|
+
opt.on('-p', '--profile PROFILE_NAME') {|v| profile_name = v }
|
34
|
+
opt.on('' , '--credentials-path PATH') {|v| credentials_path = v }
|
35
|
+
opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
|
36
|
+
opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
|
37
|
+
opt.on('-r', '--region REGION') {|v| region = v }
|
38
|
+
opt.on('-a', '--apply') {|v| mode = :apply }
|
39
|
+
opt.on('-f', '--file FILE') {|v| file = v }
|
40
|
+
opt.on('-n', '--names SG_LIST', Array) {|v| options[:sg_names] = v }
|
41
|
+
opt.on('-x', '--exclude SG_LIST', Array) {|v| options[:exclude_sgs] = v }
|
42
|
+
opt.on('', '--ec2s VPC_IDS', Array) {|v| options[:ec2s] = v }
|
43
|
+
opt.on('', '--dry-run') {|v| options[:dry_run] = true }
|
44
|
+
opt.on('-e', '--export') {|v| mode = :export }
|
45
|
+
opt.on('-o', '--output FILE') {|v| output_file = v }
|
46
|
+
opt.on('', '--split') {|v| split = true }
|
47
|
+
opt.on('', '--format=FORMAT', [:ruby, :json]) {|v| options[:format] = v }
|
48
|
+
opt.on('' , '--no-color') { options[:color] = false }
|
49
|
+
opt.on('' , '--debug') { options[:debug] = true }
|
48
50
|
opt.parse!
|
49
51
|
|
50
52
|
aws_opts = {}
|
@@ -102,39 +104,56 @@ begin
|
|
102
104
|
output_file = 'Groupfile' if output_file == '-'
|
103
105
|
requires = []
|
104
106
|
|
105
|
-
client.export(options) do |exported, converter|
|
107
|
+
client.export(options.merge(:without_convert => options[:format] != :ruby)) do |exported, converter|
|
106
108
|
exported.each do |vpc, security_groups|
|
107
109
|
group_file = File.join(File.dirname(output_file), "#{vpc || :classic}.group")
|
110
|
+
|
111
|
+
if options[:format] == :json
|
112
|
+
group_file << '.json'
|
113
|
+
end
|
114
|
+
|
108
115
|
requires << group_file
|
109
116
|
|
110
117
|
logger.info(" write `#{group_file}`")
|
111
118
|
|
112
119
|
open(group_file, 'wb') do |f|
|
113
|
-
|
114
|
-
|
120
|
+
if options[:format] == :json
|
121
|
+
f.puts JSON.pretty_generate(vpc => security_groups)
|
122
|
+
else
|
123
|
+
f.puts MAGIC_COMMENT
|
124
|
+
f.puts converter.call(vpc => security_groups)
|
125
|
+
end
|
115
126
|
end
|
116
127
|
end
|
117
128
|
end
|
118
129
|
|
119
|
-
|
130
|
+
if options[:format] == :ruby
|
131
|
+
logger.info(" write `#{output_file}`")
|
120
132
|
|
121
|
-
|
122
|
-
|
133
|
+
open(output_file, 'wb') do |f|
|
134
|
+
f.puts MAGIC_COMMENT
|
123
135
|
|
124
|
-
|
125
|
-
|
136
|
+
requires.each do |group_file|
|
137
|
+
f.puts "require '#{File.basename group_file}'"
|
138
|
+
end
|
126
139
|
end
|
127
140
|
end
|
128
141
|
else
|
142
|
+
exported = client.export(options.merge(:without_convert => options[:format] != :ruby))
|
143
|
+
|
144
|
+
if options[:format] == :json
|
145
|
+
exported = JSON.pretty_generate(exported)
|
146
|
+
end
|
147
|
+
|
129
148
|
if output_file == '-'
|
130
|
-
logger.info('# Export SecurityGroup')
|
131
|
-
puts
|
149
|
+
logger.info('# Export SecurityGroup') if options[:format] == :ruby
|
150
|
+
puts exported
|
132
151
|
else
|
133
152
|
logger.info("Export SecurityGroup to `#{output_file}`")
|
134
153
|
|
135
154
|
open(output_file, 'wb') do |f|
|
136
|
-
f.puts MAGIC_COMMENT
|
137
|
-
f.puts
|
155
|
+
f.puts MAGIC_COMMENT if options[:format] == :ruby
|
156
|
+
f.puts exported
|
138
157
|
end
|
139
158
|
end
|
140
159
|
end
|
data/lib/piculet/client.rb
CHANGED
@@ -18,14 +18,18 @@ module Piculet
|
|
18
18
|
Exporter.export(@options.ec2, @options_hash.merge(options))
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
converter = proc do |src|
|
22
|
+
if options[:without_convert]
|
23
|
+
exported
|
24
|
+
else
|
23
25
|
DSL.convert(src, @options.ec2.owner_id)
|
24
26
|
end
|
27
|
+
end
|
25
28
|
|
29
|
+
if block_given?
|
26
30
|
yield(exported, converter)
|
27
31
|
else
|
28
|
-
|
32
|
+
converter.call(exported)
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
@@ -33,15 +37,33 @@ module Piculet
|
|
33
37
|
def load_file(file)
|
34
38
|
if file.kind_of?(String)
|
35
39
|
open(file) do |f|
|
36
|
-
|
40
|
+
load_by_format(f.read, file)
|
37
41
|
end
|
38
42
|
elsif file.respond_to?(:read)
|
39
|
-
|
43
|
+
load_by_format(file.read, file.path)
|
40
44
|
else
|
41
45
|
raise TypeError, "can't convert #{file} into File"
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
49
|
+
def load_by_format(src, path)
|
50
|
+
if @options.format == :json
|
51
|
+
src = load_json(src, path)
|
52
|
+
end
|
53
|
+
|
54
|
+
DSL.define(src, path).result
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_json(json, path)
|
58
|
+
json = JSON.parse(json, :symbolize_names => true)
|
59
|
+
|
60
|
+
if json.has_key?(:'')
|
61
|
+
json[nil] = json.delete(:'')
|
62
|
+
end
|
63
|
+
|
64
|
+
DSL.convert(json, @options.ec2.owner_id)
|
65
|
+
end
|
66
|
+
|
45
67
|
def walk(file)
|
46
68
|
dsl = load_file(file)
|
47
69
|
|
@@ -20,7 +20,7 @@ module Piculet
|
|
20
20
|
|
21
21
|
private
|
22
22
|
def output_ec2(vpc, security_groups)
|
23
|
-
vpc = vpc ? vpc.inspect + ' ' : ''
|
23
|
+
vpc = vpc ? vpc.to_s.inspect + ' ' : ''
|
24
24
|
security_groups = security_groups.map {|sg_id, sg|
|
25
25
|
output_security_group(sg_id, sg)
|
26
26
|
}.join("\n").strip
|
@@ -76,8 +76,9 @@ end
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def output_perm(permission)
|
79
|
-
protocol = permission[:protocol]
|
79
|
+
protocol = permission[:protocol].to_sym
|
80
80
|
port_range = permission[:port_range]
|
81
|
+
port_range = eval(port_range) if port_range.kind_of?(String)
|
81
82
|
args = [protocol, port_range].select {|i| i }.map {|i| i.inspect }.join(', ') + ' '
|
82
83
|
|
83
84
|
ip_ranges = permission.fetch(:ip_ranges, [])
|
data/lib/piculet/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: piculet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
@@ -146,9 +146,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: '0'
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
requirements:
|
149
|
-
- - '
|
149
|
+
- - '>'
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
151
|
+
version: 1.3.1
|
152
152
|
requirements: []
|
153
153
|
rubyforge_project:
|
154
154
|
rubygems_version: 2.0.14
|