File: security_group.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (46 lines) | stat: -rw-r--r-- 1,401 bytes parent folder | download | duplicates (5)
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
module Fog
  module AWS
    class Elasticache
      class SecurityGroup < Fog::Model
        identity :id, :aliases => 'CacheSecurityGroupName'
        attribute :description, :aliases => 'Description'
        attribute :ec2_groups, :aliases => 'EC2SecurityGroups', :type => :array
        attribute :owner_id, :aliases => 'OwnerId'

        def ready?
          ec2_groups.all?{|ingress| ingress['Status'] == 'authorized'}
        end

        def destroy
          requires :id
          service.delete_cache_security_group(id)
          true
        end

        def save
          requires :id
          requires :description
          service.create_cache_security_group(id, description)
        end

        def authorize_ec2_group(group_name, group_owner_id=owner_id)
          requires :id
          requires :owner_id if group_owner_id.nil?
          data = service.authorize_cache_security_group_ingress(
            id, group_name, group_owner_id
          )
          merge_attributes(data.body['CacheSecurityGroup'])
        end

        def revoke_ec2_group(group_name, group_owner_id=owner_id)
          requires :id
          requires :owner_id if group_owner_id.nil?
          data = service.revoke_cache_security_group_ingress(
            id, group_name, group_owner_id
          )
          merge_attributes(data.body['CacheSecurityGroup'])
        end
      end
    end
  end
end