Class: Sgupdater::Client
- Inherits:
-
Object
- Object
- Sgupdater::Client
- Defined in:
- lib/sgupdater/client.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #get(cidr = ) ⇒ Object
-
#initialize(cli_options = {}, aws_configuration = {}) ⇒ Client
constructor
A new instance of Client.
- #put_perms(sg, cidr) ⇒ Object
- #security_groups_with_cidr(cidr) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(cli_options = {}, aws_configuration = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 |
# File 'lib/sgupdater/client.rb', line 8 def initialize( = {}, aws_configuration = {}) @cli_options = @logger ||= Logger.new STDOUT aws_configuration[:logger] = Logger.new STDOUT if @cli_options[:verbose] @ec2 = Aws::EC2::Resource.new aws_configuration end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
6 7 8 |
# File 'lib/sgupdater/client.rb', line 6 def logger @logger end |
Instance Method Details
#get(cidr = ) ⇒ Object
17 18 19 |
# File 'lib/sgupdater/client.rb', line 17 def get(cidr = @cli_options[:from_cidr]) security_groups_with_cidr(cidr) end |
#put_perms(sg, cidr) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/sgupdater/client.rb', line 35 def put_perms(sg, cidr) sg..each do |perm| perm.ip_ranges.select {|ip| ip.values.include? cidr}.each do puts [sg.vpc_id, sg.group_id, sg.group_name, perm.from_port, perm.to_port, cidr].join("\t") end end end |
#security_groups_with_cidr(cidr) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/sgupdater/client.rb', line 27 def security_groups_with_cidr(cidr) @ec2.security_groups( filters: [ {name: 'ip-permission.cidr', values: [cidr]} ] ) end |