This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
forked from inspec/inspec-gcp
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgoogle_dns_resource_record_sets.rb
92 lines (76 loc) · 2.72 KB
/
google_dns_resource_record_sets.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
# 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.
#
# ----------------------------------------------------------------------------
require 'gcp_backend'
class ResourceRecordSets < GcpResourceBase
name 'google_dns_resource_record_sets'
desc 'ResourceRecordSet plural resource'
supports platform: 'gcp'
attr_reader :table
filter_table_config = FilterTable.create
filter_table_config.add(:names, field: :name)
filter_table_config.add(:types, field: :type)
filter_table_config.add(:ttls, field: :ttl)
filter_table_config.add(:targets, field: :target)
filter_table_config.add(:managed_zones, field: :managed_zone)
filter_table_config.connect(self, :table)
def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('rrsets')
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)
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
{
'name' => ->(obj) { return :name, obj['name'] },
'type' => ->(obj) { return :type, obj['type'] },
'ttl' => ->(obj) { return :ttl, obj['ttl'] },
'rrdatas' => ->(obj) { return :target, obj['rrdatas'] },
'managed_zone' => ->(obj) { return :managed_zone, obj['managed_zone'] },
}
end
# Handles parsing RFC3339 time string
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end
private
def product_url
'https://www.googleapis.com/dns/v1/'
end
def resource_base_url
'projects/{{project}}/managedZones/{{managed_zone}}/rrsets'
end
end