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_router.rb
74 lines (63 loc) · 1.99 KB
/
google_compute_router.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
# 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'
require 'google/compute/property/router_bgp'
require 'google/compute/property/router_bgp_advertised_ip_ranges'
# A provider to manage Compute Engine resources.
class Router < GcpResourceBase
name 'google_compute_router'
desc 'Router'
supports platform: 'gcp'
attr_reader :params
attr_reader :id
attr_reader :creation_timestamp
attr_reader :name
attr_reader :description
attr_reader :network
attr_reader :bgp
attr_reader :region
def initialize(params)
super(params.merge({ use_http_transport: true }))
@params = params
@fetched = @connection.fetch(product_url, resource_base_url, params)
parse unless @fetched.nil?
end
def parse
@id = @fetched['id']
@creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
@name = @fetched['name']
@description = @fetched['description']
@network = @fetched['network']
@bgp = GoogleInSpec::Compute::Property::RouterBgp.new(@fetched['bgp'], to_s)
@region = @fetched['region']
end
# Handles parsing RFC3339 time string
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end
def exists?
!@fetched.nil?
end
def to_s
"Router #{@params[:name]}"
end
private
def product_url
'https://www.googleapis.com/compute/v1/'
end
def resource_base_url
'projects/{{project}}/regions/{{region}}/routers/{{name}}'
end
end