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_compute_https_health_checks.rb
104 lines (88 loc) · 3.65 KB
/
google_compute_https_health_checks.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
# 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 HttpsHealthChecks < GcpResourceBase
name 'google_compute_https_health_checks'
desc 'HttpsHealthCheck plural resource'
supports platform: 'gcp'
attr_reader :table
filter_table_config = FilterTable.create
filter_table_config.add(:check_interval_secs, field: :check_interval_sec)
filter_table_config.add(:creation_timestamps, field: :creation_timestamp)
filter_table_config.add(:descriptions, field: :description)
filter_table_config.add(:healthy_thresholds, field: :healthy_threshold)
filter_table_config.add(:hosts, field: :host)
filter_table_config.add(:ids, field: :id)
filter_table_config.add(:names, field: :name)
filter_table_config.add(:ports, field: :port)
filter_table_config.add(:request_paths, field: :request_path)
filter_table_config.add(:timeout_secs, field: :timeout_sec)
filter_table_config.add(:unhealthy_thresholds, field: :unhealthy_threshold)
filter_table_config.connect(self, :table)
def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('items')
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
{
'checkIntervalSec' => ->(obj) { return :check_interval_sec, obj['checkIntervalSec'] },
'creationTimestamp' => ->(obj) { return :creation_timestamp, parse_time_string(obj['creationTimestamp']) },
'description' => ->(obj) { return :description, obj['description'] },
'healthyThreshold' => ->(obj) { return :healthy_threshold, obj['healthyThreshold'] },
'host' => ->(obj) { return :host, obj['host'] },
'id' => ->(obj) { return :id, obj['id'] },
'name' => ->(obj) { return :name, obj['name'] },
'port' => ->(obj) { return :port, obj['port'] },
'requestPath' => ->(obj) { return :request_path, obj['requestPath'] },
'timeoutSec' => ->(obj) { return :timeout_sec, obj['timeoutSec'] },
'unhealthyThreshold' => ->(obj) { return :unhealthy_threshold, obj['unhealthyThreshold'] },
}
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/compute/v1/'
end
def resource_base_url
'projects/{{project}}/global/httpsHealthChecks'
end
end