-
Notifications
You must be signed in to change notification settings - Fork 71
/
google_project.rb
86 lines (72 loc) · 2.2 KB
/
google_project.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
# 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/resourcemanager/property/project_parent'
# A provider to manage Resource Manager resources.
class ResourceManagerProject < GcpResourceBase
name 'google_project'
desc 'Project'
supports platform: 'gcp'
attr_reader :params
attr_reader :number
attr_reader :lifecycle_state
attr_reader :name
attr_reader :create_time
attr_reader :labels
attr_reader :parent
attr_reader :project_id
def initialize(params)
super(params.merge({ use_http_transport: true }))
@params = params
@fetched = @connection.fetch(product_url(params[:beta]), resource_base_url, params, 'Get')
parse unless @fetched.nil?
end
def parse
@number = @fetched['projectNumber']
@lifecycle_state = @fetched['lifecycleState']
@name = @fetched['name']
@create_time = parse_time_string(@fetched['createTime'])
@labels = @fetched['labels']
@parent = GoogleInSpec::ResourceManager::Property::ProjectParent.new(@fetched['parent'], to_s)
@project_id = @fetched['projectId']
end
# Handles parsing RFC3339 time string
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end
def exists?
end
def to_s
"Project #{@params[:project]}"
end
def project_name
@name
end
def project_number
@number&.to_i
end
def label_value_by_key(label_key)
return nil if @labels.nil? || [email protected]_key(label_key)
@labels[label_key]
end
private
def product_url(_ = nil)
'https://cloudresourcemanager.googleapis.com/v1/'
end
def resource_base_url
'projects/{{project}}'
end
end