/
security_group.rb
77 lines (59 loc) · 2.03 KB
/
security_group.rb
1
2
3
4
5
6
7
8
9
10
11
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'fog/model'
module Fog
module AWS
class Compute
class SecurityGroup < Fog::Model
identity :name, :aliases => 'groupName'
attribute :description, :aliases => 'groupDescription'
attribute :ip_permissions, :aliases => 'ipPermissions'
attribute :owner_id, :aliases => 'ownerId'
def authorize_group_and_owner(group, owner)
requires :name
connection.authorize_security_group_ingress(
'GroupName' => @name,
'SourceSecurityGroupName' => group,
'SourceSecurityGroupOwnerId' => owner
)
end
def authorize_port_range(range, options = {})
requires :name
connection.authorize_security_group_ingress(
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
'FromPort' => range.min,
'GroupName' => @name,
'ToPort' => range.max,
'IpProtocol' => options[:ip_protocol] || 'tcp'
)
end
def destroy
requires :name
connection.delete_security_group(@name)
true
end
def revoke_group_and_owner(group, owner)
requires :name
connection.revoke_security_group_ingress(
'GroupName' => @name,
'SourceSecurityGroupName' => group,
'SourceSecurityGroupOwnerId' => owner
)
end
def revoke_port_range(range, options = {})
requires :name
connection.revoke_security_group_ingress(
'CidrIp' => options[:cidr_ip] || '0.0.0.0/0',
'FromPort' => range.min,
'GroupName' => @name,
'ToPort' => range.max,
'IpProtocol' => options[:ip_protocol] || 'tcp'
)
end
def save
requires :description, :name
data = connection.create_security_group(@name, @description).body
true
end
end
end
end
end