Class: Stax::Aws::Sg

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

Constant Summary

Constants inherited from Sdk

Stax::Aws::Sdk::RETRY_LIMIT

Class Method Summary collapse

Methods inherited from Sdk

paginate

Class Method Details

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



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

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



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

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



9
10
11
# File 'lib/stax/aws/sg.rb', line 9

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

.describe(ids) ⇒ Object



13
14
15
# File 'lib/stax/aws/sg.rb', line 13

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

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



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

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



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

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