stem 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/stem/group.rb +31 -2
- metadata +2 -2
data/lib/stem/group.rb
CHANGED
@@ -22,7 +22,7 @@ module Stem
|
|
22
22
|
nil
|
23
23
|
end
|
24
24
|
|
25
|
-
def create(name, rules = nil, description =
|
25
|
+
def create(name, rules = nil, description = nil)
|
26
26
|
create!(name, rules, description)
|
27
27
|
true
|
28
28
|
rescue Swirl::InvalidRequest => e
|
@@ -30,7 +30,8 @@ module Stem
|
|
30
30
|
false
|
31
31
|
end
|
32
32
|
|
33
|
-
def create!(name, rules = nil, description =
|
33
|
+
def create!(name, rules = nil, description = nil)
|
34
|
+
description ||= name
|
34
35
|
swirl.call "CreateSecurityGroup", "GroupName" => name, "GroupDescription" => description
|
35
36
|
auth(name, rules) if rules
|
36
37
|
end
|
@@ -69,6 +70,24 @@ module Stem
|
|
69
70
|
swirl.call "RevokeSecurityGroupIngress", args
|
70
71
|
end
|
71
72
|
|
73
|
+
def rules(name)
|
74
|
+
group = get(name)
|
75
|
+
return unless group
|
76
|
+
perms = group["ipPermissions"] || []
|
77
|
+
list = []
|
78
|
+
perms.map do |h|
|
79
|
+
h['ipRanges'].each do |ipr|
|
80
|
+
rule = "#{h['ipProtocol']}://#{ipr['cidrIp']}"
|
81
|
+
list << [ rule, parse_rule_ports(h) ].join
|
82
|
+
end if h['ipRanges']
|
83
|
+
h['groups'].each do |group|
|
84
|
+
rule = "#{h['ipProtocol']}://#{group['groupName']}@#{group['userId']}"
|
85
|
+
list << [ rule, parse_rule_ports(h) ].join
|
86
|
+
end if h['groups']
|
87
|
+
end
|
88
|
+
list
|
89
|
+
end
|
90
|
+
|
72
91
|
def gen_authorize_target(index, target)
|
73
92
|
if target =~ /^\d+\.\d+\.\d+.\d+\/\d+$/
|
74
93
|
{ "IpPermissions.#{index}.IpRanges.1.CidrIp" => target }
|
@@ -108,6 +127,16 @@ module Stem
|
|
108
127
|
raise "bad rule: #{rule}"
|
109
128
|
end
|
110
129
|
end
|
130
|
+
|
131
|
+
def parse_rule_ports(rule)
|
132
|
+
if rule['ipProtocol'] == 'icmp'
|
133
|
+
""
|
134
|
+
elsif rule['fromPort'] == '0' && rule['toPort'] == '65535'
|
135
|
+
":"
|
136
|
+
else
|
137
|
+
":#{[ rule['fromPort'], rule['toPort']].uniq.join('-')}"
|
138
|
+
end
|
139
|
+
end
|
111
140
|
end
|
112
141
|
end
|
113
142
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: stem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.8.
|
5
|
+
version: 0.8.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Peter van Hardenberg
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2011-
|
15
|
+
date: 2011-05-02 00:00:00 -07:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|