piculet 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- M2YwYTA3MWY5YTBlYzNlZDY0MTBiZjA0OTRkYzVmMDVhNTNiODg0OQ==
5
- data.tar.gz: !binary |-
6
- ZTgzYWIxZjBhODE1ZjBmNzZkZTg2YWM5ODBjZjYxOGQ5MmRjYzc4NA==
2
+ SHA1:
3
+ metadata.gz: b7be7c72108966fd702024bbf57244efd91de9a7
4
+ data.tar.gz: 885ae36b3897675d9255e56c9efcd79756c10963
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NTM5YzcwNDY1Mzc3YWViNWNmNWI4ZTVlNTg2MWQ3MDc1NDdiNGU5NDU4MTA4
10
- NWNjMGRmNDM0ZTZmM2I3NjBhYjFjNjI5NWI2MjkyYTcwMWVlN2RmZWY1NjJk
11
- OWY3ZTFjNDBlZTFlNjM2ODczODNhYzExNTliMzc4Yjc0NDg2MGQ=
12
- data.tar.gz: !binary |-
13
- MjdiNmM0ZjJmMjM3YWZjN2I1NmZhZjU5YzI5MDA4NzhjYzc5NmExY2QzZGU2
14
- OTFjOWM3MGUyMjE1ZGFkNGExNTkwNGY1MGE0MzMwNWU4YWJiM2RjYjI5OTc5
15
- MzFlY2Y2ODIxMWFiYWQxMTkxMWNkZWYyYjRkODg2NzRjZTdlZjQ=
6
+ metadata.gz: ac5cf7f08e29eb902cdc5b60b3b0c104f5d44f84131a20d5132c2836f7d8db3621f22530c8faac1814fef25212b36f0ec133b9cedc4a3f2b44243a4fa6e48bed
7
+ data.tar.gz: 465276c6d0464a38ee8cf6e51e57584f52b25543596f7040dc1137729cb339fab54d7e323a147419aa4841954112e3c2810523360325eb0379e38ce5f9fd7f0d
data/README.md CHANGED
@@ -4,6 +4,7 @@ Piculet is a tool to manage EC2 Security Group.
4
4
 
5
5
  It defines the state of EC2 Security Group using DSL, and updates EC2 Security Group according to DSL.
6
6
 
7
+ [![Gem Version](https://badge.fury.io/rb/piculet.png)](http://badge.fury.io/rb/piculet)
7
8
  [![Build Status](https://drone.io/bitbucket.org/winebarrel/piculet/status.png)](https://drone.io/bitbucket.org/winebarrel/piculet/latest)
8
9
 
9
10
  ## Installation
@@ -124,6 +125,3 @@ ec2 "vpc-XXXXXXXX" do
124
125
  end
125
126
  end
126
127
  ```
127
-
128
- ## Link
129
- * [RubyGems.org site](http://rubygems.org/gems/piculet)
data/bin/piculet CHANGED
@@ -26,6 +26,8 @@ ARGV.options do |opt|
26
26
  opt.on('-r', '--region REGION') {|v| region = v }
27
27
  opt.on('-a', '--apply') {|v| mode = :apply }
28
28
  opt.on('-f', '--file FILE') {|v| file = v }
29
+ opt.on('-n', '--names SG_LIST', Array) {|v| options[:sg_names] = v }
30
+ opt.on('', '--ec2s VPC_IDS', Array) {|v| options[:ec2s] = v }
29
31
  opt.on('', '--dry-run') {|v| options[:dry_run] = true }
30
32
  opt.on('-e', '--export') {|v| mode = :export }
31
33
  opt.on('-o', '--output FILE') {|v| output_file = v }
@@ -73,7 +75,7 @@ begin
73
75
  output_file = 'Groupfile' if output_file == '-'
74
76
  requires = []
75
77
 
76
- client.export do |exported, converter|
78
+ client.export(options) do |exported, converter|
77
79
  exported.each do |vpc, security_groups|
78
80
  group_file = File.join(File.dirname(output_file), "#{vpc || :classic}.group")
79
81
  requires << group_file
@@ -96,10 +98,10 @@ begin
96
98
  else
97
99
  if output_file == '-'
98
100
  logger.info('# Export SecurityGroup')
99
- puts client.export
101
+ puts client.export(options)
100
102
  else
101
103
  logger.info("Export SecurityGroup to `#{output_file}`")
102
- open(output_file, 'wb') {|f| f.puts client.export }
104
+ open(output_file, 'wb') {|f| f.puts client.export(options) }
103
105
  end
104
106
  end
105
107
  when :apply
@@ -19,8 +19,10 @@ module Piculet
19
19
  AWS.memoize { walk(file) }
20
20
  end
21
21
 
22
- def export
23
- exported = AWS.memoize { Exporter.export(@options.ec2) }
22
+ def export(options = {})
23
+ exported = AWS.memoize do
24
+ Exporter.export(@options.ec2, options)
25
+ end
24
26
 
25
27
  if block_given?
26
28
  converter = proc do |src|
@@ -57,6 +59,10 @@ module Piculet
57
59
  end
58
60
 
59
61
  dsl_ec2s.each do |vpc, ec2_dsl|
62
+ if @options.ec2s
63
+ next unless @options.ec2s.any? {|i| (i == 'classic' and vpc.nil?) or i == vpc }
64
+ end
65
+
60
66
  ec2_aws = aws_ec2s[vpc]
61
67
 
62
68
  if ec2_aws
@@ -75,6 +81,11 @@ module Piculet
75
81
 
76
82
  sg_list_dsl.each do |key, sg_dsl|
77
83
  name = key[0]
84
+
85
+ if @options.sg_names
86
+ next unless @options.sg_names.include?(name)
87
+ end
88
+
78
89
  sg_aws = sg_list_aws[key]
79
90
 
80
91
  unless sg_aws
@@ -85,16 +96,33 @@ module Piculet
85
96
 
86
97
  sg_list_dsl.each do |key, sg_dsl|
87
98
  name = key[0]
99
+
100
+ if @options.sg_names
101
+ next unless @options.sg_names.include?(name)
102
+ end
103
+
88
104
  sg_aws = sg_list_aws.delete(key)
89
105
  walk_security_group(sg_dsl, sg_aws)
90
106
  end
91
107
 
92
108
  sg_list_aws.each do |key, sg_aws|
109
+ name = key[0]
110
+
111
+ if @options.sg_names
112
+ next unless @options.sg_names.include?(name)
113
+ end
114
+
93
115
  sg_aws.ingress_ip_permissions.each {|i| i.delete }
94
116
  sg_aws.egress_ip_permissions.each {|i| i.delete } if vpc
95
117
  end
96
118
 
97
119
  sg_list_aws.each do |key, sg_aws|
120
+ name = key[0]
121
+
122
+ if @options.sg_names
123
+ next unless @options.sg_names.include?(name)
124
+ end
125
+
98
126
  sg_aws.delete
99
127
  end
100
128
  end
@@ -3,21 +3,31 @@ require 'piculet/ext/ip-permission-collection-ext'
3
3
  module Piculet
4
4
  class Exporter
5
5
  class << self
6
- def export(ec2)
7
- self.new(ec2).export
6
+ def export(ec2, options = {})
7
+ self.new(ec2, options).export
8
8
  end
9
9
  end # of class methods
10
10
 
11
- def initialize(ec2)
11
+ def initialize(ec2, options = {})
12
12
  @ec2 = ec2
13
+ @options = options
13
14
  end
14
15
 
15
16
  def export
16
17
  result = {}
18
+ ec2s = @options[:ec2s]
19
+ sg_names = @options[:sg_names]
20
+ sgs = @ec2.security_groups
21
+ sgs = sgs.filter('group-name', *sg_names) if sg_names
17
22
 
18
- @ec2.security_groups.each do |sg|
23
+ sgs.each do |sg|
19
24
  vpc = sg.vpc
20
25
  vpc = vpc.id if vpc
26
+
27
+ if ec2s
28
+ next unless ec2s.any? {|i| (i == 'classic' and vpc.nil?) or i == vpc }
29
+ end
30
+
21
31
  result[vpc] ||= {}
22
32
  result[vpc][sg.id] = export_security_group(sg)
23
33
  end
@@ -1,5 +1,5 @@
1
1
  module Piculet
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
4
4
 
5
5
  Version = Piculet::VERSION
metadata CHANGED
@@ -1,41 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piculet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - winebarrel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2013-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.19.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.19.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: term-ansicolor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.2.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.2.2
41
41
  - !ruby/object:Gem::Dependency
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -120,17 +120,17 @@ require_paths:
120
120
  - lib
121
121
  required_ruby_version: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ! '>='
123
+ - - '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  required_rubygems_version: !ruby/object:Gem::Requirement
127
127
  requirements:
128
- - - ! '>='
128
+ - - '>='
129
129
  - !ruby/object:Gem::Version
130
130
  version: '0'
131
131
  requirements: []
132
132
  rubyforge_project:
133
- rubygems_version: 2.1.5
133
+ rubygems_version: 2.0.14
134
134
  signing_key:
135
135
  specification_version: 4
136
136
  summary: Piculet is a tool to manage EC2 Security Group.