From da36f4ca74591d7646f5625c5bad87a6075bbf3e Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 22 Sep 2020 11:35:54 -0700 Subject: [PATCH] Add network peerings for inspec (#4002) (#449) Signed-off-by: Modular Magician --- docs/resources/google_compute_network.md | 16 +++++ docs/resources/google_compute_networks.md | 1 + .../compute/property/network_peerings.rb | 60 +++++++++++++++++++ libraries/google_compute_network.rb | 3 + libraries/google_compute_networks.rb | 2 + 5 files changed, 82 insertions(+) create mode 100644 libraries/google/compute/property/network_peerings.rb diff --git a/docs/resources/google_compute_network.md b/docs/resources/google_compute_network.md index b17c8bd14..ca06a8536 100644 --- a/docs/resources/google_compute_network.md +++ b/docs/resources/google_compute_network.md @@ -86,6 +86,22 @@ Properties that can be accessed from the `google_compute_network` resource: * REGIONAL * GLOBAL + * `peerings`: Peerings for a network + + * `name`: Name of the peering. + + * `state`: State of the peering. + + * `state_details`: Details about the current state of the peering. + + * `network`: URL of the peer network + + * `export_custom_routes`: Whether to export the custom routes to the peer network. + + * `import_custom_routes`: Whether to import the custom routes to the peer network. + + * `peer_mtu`: Maximum Transmission Unit in bytes. + ## GCP Permissions diff --git a/docs/resources/google_compute_networks.md b/docs/resources/google_compute_networks.md index 099d22cb8..c081a2fdc 100644 --- a/docs/resources/google_compute_networks.md +++ b/docs/resources/google_compute_networks.md @@ -48,6 +48,7 @@ See [google_compute_network.md](google_compute_network.md) for more detailed inf * `auto_create_subnetworks`: an array of `google_compute_network` auto_create_subnetworks * `creation_timestamps`: an array of `google_compute_network` creation_timestamp * `routing_configs`: an array of `google_compute_network` routing_config + * `peerings`: an array of `google_compute_network` peerings ## Filter Criteria This resource supports all of the above properties as filter criteria, which can be used diff --git a/libraries/google/compute/property/network_peerings.rb b/libraries/google/compute/property/network_peerings.rb new file mode 100644 index 000000000..499a519fd --- /dev/null +++ b/libraries/google/compute/property/network_peerings.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: false + +# ---------------------------------------------------------------------------- +# +# *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** +# +# ---------------------------------------------------------------------------- +# +# This file is automatically generated by Magic Modules and manual +# changes will be clobbered when the file is regenerated. +# +# Please read more about how to change this file in README.md and +# CONTRIBUTING.md located at the root of this package. +# +# ---------------------------------------------------------------------------- +module GoogleInSpec + module Compute + module Property + class NetworkPeerings + attr_reader :name + + attr_reader :state + + attr_reader :state_details + + attr_reader :network + + attr_reader :export_custom_routes + + attr_reader :import_custom_routes + + attr_reader :peer_mtu + + def initialize(args = nil, parent_identifier = nil) + return if args.nil? + @parent_identifier = parent_identifier + @name = args['name'] + @state = args['state'] + @state_details = args['stateDetails'] + @network = args['network'] + @export_custom_routes = args['exportCustomRoutes'] + @import_custom_routes = args['importCustomRoutes'] + @peer_mtu = args['peerMtu'] + end + + def to_s + "#{@parent_identifier} NetworkPeerings" + end + end + + class NetworkPeeringsArray + def self.parse(value, parent_identifier) + return if value.nil? + return NetworkPeerings.new(value, parent_identifier) unless value.is_a?(::Array) + value.map { |v| NetworkPeerings.new(v, parent_identifier) } + end + end + end + end +end diff --git a/libraries/google_compute_network.rb b/libraries/google_compute_network.rb index 9f4f220c9..2e3b4272d 100644 --- a/libraries/google_compute_network.rb +++ b/libraries/google_compute_network.rb @@ -14,6 +14,7 @@ # # ---------------------------------------------------------------------------- require 'gcp_backend' +require 'google/compute/property/network_peerings' require 'google/compute/property/network_routing_config' # A provider to manage Compute Engine resources. @@ -31,6 +32,7 @@ class ComputeNetwork < GcpResourceBase attr_reader :auto_create_subnetworks attr_reader :creation_timestamp attr_reader :routing_config + attr_reader :peerings def initialize(params) super(params.merge({ use_http_transport: true })) @@ -48,6 +50,7 @@ def parse @auto_create_subnetworks = @fetched['autoCreateSubnetworks'] @creation_timestamp = parse_time_string(@fetched['creationTimestamp']) @routing_config = GoogleInSpec::Compute::Property::NetworkRoutingConfig.new(@fetched['routingConfig'], to_s) + @peerings = GoogleInSpec::Compute::Property::NetworkPeeringsArray.parse(@fetched['peerings'], to_s) end # Handles parsing RFC3339 time string diff --git a/libraries/google_compute_networks.rb b/libraries/google_compute_networks.rb index 0a420562d..59f33cc5a 100644 --- a/libraries/google_compute_networks.rb +++ b/libraries/google_compute_networks.rb @@ -31,6 +31,7 @@ class ComputeNetworks < GcpResourceBase filter_table_config.add(:auto_create_subnetworks, field: :auto_create_subnetworks) filter_table_config.add(:creation_timestamps, field: :creation_timestamp) filter_table_config.add(:routing_configs, field: :routing_config) + filter_table_config.add(:peerings, field: :peerings) filter_table_config.connect(self, :table) @@ -78,6 +79,7 @@ def transformers 'autoCreateSubnetworks' => ->(obj) { return :auto_create_subnetworks, obj['autoCreateSubnetworks'] }, 'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) }, 'routingConfig' => ->(obj) { return :routing_config, GoogleInSpec::Compute::Property::NetworkRoutingConfig.new(obj['routingConfig'], to_s) }, + 'peerings' => ->(obj) { return :peerings, GoogleInSpec::Compute::Property::NetworkPeeringsArray.parse(obj['peerings'], to_s) }, } end