-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathgoogle_compute_public_advertised_prefixes.rb
107 lines (92 loc) · 4.17 KB
/
google_compute_public_advertised_prefixes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# frozen_string_literal: false
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** Type: MMv1 ***
#
# ----------------------------------------------------------------------------
#
# 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.
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
class ComputePublicAdvertisedPrefixs < GcpResourceBase
name 'google_compute_public_advertised_prefixes'
desc 'PublicAdvertisedPrefix plural resource'
supports platform: 'gcp'
attr_reader :table
filter_table_config = FilterTable.create
filter_table_config.add(:kinds, field: :kind)
filter_table_config.add(:ids, field: :id)
filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:names, field: :name)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:self_links, field: :self_link)
filter_table_config.add(:self_link_with_ids, field: :self_link_with_id)
filter_table_config.add(:ip_cidr_ranges, field: :ip_cidr_range)
filter_table_config.add(:dns_verification_ips, field: :dns_verification_ip)
filter_table_config.add(:shared_secrets, field: :shared_secret)
filter_table_config.add(:statuses, field: :status)
filter_table_config.add(:pdp_scopes, field: :pdp_scope)
filter_table_config.add(:public_delegated_prefixs, field: :public_delegated_prefixs)
filter_table_config.add(:fingerprints, field: :fingerprint)
filter_table_config.add(:byoip_api_versions, field: :byoip_api_version)
filter_table_config.connect(self, :table)
def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('publicAdvertisedPrefixes')
end
def fetch_wrapped_resource(wrap_path)
# fetch_resource returns an array of responses (to handle pagination)
result = @connection.fetch_all(product_url, resource_base_url, @params, 'Get')
return if result.nil?
# Conversion of string -> object hash to symbol -> object hash that InSpec needs
converted = []
result.each do |response|
next if response.nil? || !response.key?(wrap_path)
response[wrap_path].each do |hash|
hash_with_symbols = {}
hash.each_key do |key|
name, value = transform(key, hash)
hash_with_symbols[name] = value
end
converted.push(hash_with_symbols)
end
end
converted
end
def transform(key, value)
return transformers[key].call(value) if transformers.key?(key)
[key.to_sym, value]
end
def transformers
{
'kind' => ->(obj) { [:kind, obj['kind']] },
'id' => ->(obj) { [:id, obj['id']] },
'creationTimestamp' => ->(obj) { [:creation_timestamp, obj['creationTimestamp']] },
'name' => ->(obj) { [:name, obj['name']] },
'description' => ->(obj) { [:description, obj['description']] },
'selfLink' => ->(obj) { [:self_link, obj['selfLink']] },
'selfLinkWithId' => ->(obj) { [:self_link_with_id, obj['selfLinkWithId']] },
'ipCidrRange' => ->(obj) { [:ip_cidr_range, obj['ipCidrRange']] },
'dnsVerificationIp' => ->(obj) { [:dns_verification_ip, obj['dnsVerificationIp']] },
'sharedSecret' => ->(obj) { [:shared_secret, obj['sharedSecret']] },
'status' => ->(obj) { [:status, obj['status']] },
'pdpScope' => ->(obj) { [:pdp_scope, obj['pdpScope']] },
'publicDelegatedPrefixs' => ->(obj) { [:public_delegated_prefixs, GoogleInSpec::Compute::Property::PublicAdvertisedPrefixPublicDelegatedPrefixsArray.parse(obj['publicDelegatedPrefixs'], to_s)] },
'fingerprint' => ->(obj) { [:fingerprint, obj['fingerprint']] },
'byoipApiVersion' => ->(obj) { [:byoip_api_version, obj['byoipApiVersion']] },
}
end
private
def product_url(_ = nil)
'https://compute.googleapis.com/compute/v1/'
end
def resource_base_url
'projects/{{project}}/global/publicAdvertisedPrefixes'
end
end