Class: Cucloud::VpcUtils
- Inherits:
-
Object
- Object
- Cucloud::VpcUtils
- Defined in:
- lib/cucloud/vpc_utils.rb
Overview
Utilities library for interacting with VPC
Defined Under Namespace
Classes: PROTOCOL
Instance Method Summary collapse
-
#compare_nacls(rules, skip_acl = []) ⇒ Array<Hash <String, String>>
Compare NACLS in a the current region with a specified rule set.
-
#flow_logs? ⇒ boolean
Does the current region have vpc flow logs?.
-
#initialize(vpc_client = Aws::EC2::Client.new) ⇒ VpcUtils
constructor
A new instance of VpcUtils.
-
#vpc_flow_log_status ⇒ Array<Hash>
Get flow log status for all VPCs in this region.
Constructor Details
#initialize(vpc_client = Aws::EC2::Client.new) ⇒ VpcUtils
Returns a new instance of VpcUtils.
17 18 19 |
# File 'lib/cucloud/vpc_utils.rb', line 17 def initialize(vpc_client = Aws::EC2::Client.new) @vpc = vpc_client end |
Instance Method Details
#compare_nacls(rules, skip_acl = []) ⇒ Array<Hash <String, String>>
Compare NACLS in a the current region with a specified rule set
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cucloud/vpc_utils.rb', line 38 def compare_nacls(rules, skip_acl = []) raise ArgumentError, 'rules is not an array' unless rules.is_a? Array compared_rules = [] nacls = @vpc.describe_network_acls({}) nacls.network_acls.each do |acl| next if skip_acl.include?(acl.network_acl_id) compared_rules.push(check_acls(acl, rules)) end compared_rules end |
#flow_logs? ⇒ boolean
Does the current region have vpc flow logs?
53 54 55 |
# File 'lib/cucloud/vpc_utils.rb', line 53 def flow_logs? vpc_flow_log_status.find { |x| !x[:flow_logs_active] }.nil? end |
#vpc_flow_log_status ⇒ Array<Hash>
Get flow log status for all VPCs in this region
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cucloud/vpc_utils.rb', line 59 def vpc_flow_log_status @vpc.describe_vpcs.vpcs.map do |vpc| { vpc_id: vpc.vpc_id, flow_logs_active: !@vpc.describe_flow_logs( filter: [{ name: 'resource-id', values: [vpc.vpc_id] }] ).flow_logs.empty? } end end |