Class: Stax::Aws::Sg

Inherits:
Sdk
  • Object
show all
Defined in:
lib/stax/aws/sg.rb

Class Method Summary collapse

Methods inherited from Sdk

paginate

Class Method Details

.authorize(id, cidr, port = 22) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/stax/aws/sg.rb', line 15

def authorize(id, cidr, port = 22)
  client.authorize_security_group_ingress(
    group_id:    id,
    ip_protocol: :tcp,
    from_port:   port,
    to_port:     port,
    cidr_ip:     cidr,
  )
rescue ::Aws::EC2::Errors::InvalidPermissionDuplicate => e
  warn(e.message)
end

.authorize_sg(id, sg, port) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stax/aws/sg.rb', line 27

def authorize_sg(id, sg, port)
  client.authorize_security_group_ingress(
    group_id: id,
    ip_permissions: [
      {
        ip_protocol: :tcp,
        from_port: port,
        to_port: port,
        user_id_group_pairs: [ { group_id: sg } ],
      }
    ]
  )
rescue ::Aws::EC2::Errors::InvalidPermissionDuplicate => e
  warn(e.message)
end

.clientObject



7
8
9
# File 'lib/stax/aws/sg.rb', line 7

def client
  @_client ||= ::Aws::EC2::Client.new
end

.describe(ids) ⇒ Object



11
12
13
# File 'lib/stax/aws/sg.rb', line 11

def describe(ids)
  client.describe_security_groups(group_ids: Array(ids)).security_groups
end

.revoke(id, cidr, port = 22) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/stax/aws/sg.rb', line 43

def revoke(id, cidr, port = 22)
  client.revoke_security_group_ingress(
    group_id:    id,
    ip_protocol: :tcp,
    from_port:   port,
    to_port:     port,
    cidr_ip:     cidr,
  )
rescue ::Aws::EC2::Errors::InvalidPermissionNotFound => e
  warn(e.message)
end

.revoke_sg(id, sg, port) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/stax/aws/sg.rb', line 55

def revoke_sg(id, sg, port)
  client.revoke_security_group_ingress(
    group_id: id,
    ip_permissions: [
      {
        ip_protocol: :tcp,
        from_port: port,
        to_port: port,
        user_id_group_pairs: [ { group_id: sg } ],
      }
    ]
  )
rescue ::Aws::EC2::Errors::InvalidPermissionNotFound => e
  warn(e.message)
end