Skip to content

Commit 1867189

Browse files
committed
Adding basic singular resource code
1 parent 078067a commit 1867189

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

provider/inspec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module Provider
2121
# Code generator for Example Cookbooks that manage Google Cloud Platform
2222
# resources.
2323
class Inspec < Provider::Core
24+
include Google::RubyUtils
2425
# Settings for the provider
2526
class Config < Provider::Config
2627
attr_reader :manifest

templates/inspec/singular_resource.erb

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,61 @@
1414
-%>
1515
<%= compile 'templates/license.erb' -%>
1616

17-
<%= lines(autogen_notice :ruby) -%>
17+
<%= lines(autogen_notice :ruby) -%>
18+
19+
# A provider to manage <%= @api.name -%> resources.
20+
<%= lines(indent(
21+
emit_rubocop(binding, :class,
22+
['Google', @api.prefix.upcase, object.name].join('::'),
23+
:disabled),
24+
4)) -%>
25+
class <%= object.name -%> < Inspec.resource(1)
26+
27+
name 'google_<%= product_ns.downcase -%>_<%= object.name.downcase -%>'
28+
desc '<%= object.name -%>'
29+
supports platform: 'gcp-mm'
30+
31+
<% object.properties.reject(&:input).each do |prop| -%>
32+
<%= "attr_reader :#{prop.out_name}" -%>
33+
34+
<% end -%>
35+
36+
<%
37+
base = "'#{object.self_link_url[0].join}'"
38+
url = object.self_link_url[1]
39+
if url.is_a?(Array)
40+
url = url.join('')
41+
else
42+
url = url.split("\n").join('')
43+
end
44+
url = "'#{url}'"
45+
-%>
46+
def base
47+
<%= base %>
48+
end
49+
50+
def url
51+
<%= url %>
52+
end
53+
54+
<% if object.self_link_query.nil? -%>
55+
def initialize(params)
56+
@fetched = <%= method_call('fetch_resource', ['params', ("'#{object.kind}'" if object.kind?)], 2) %>
57+
parse unless @fetched.nil?
58+
end
59+
<% else # object.self_link_query.nil? -%>
60+
def initialize(params)
61+
@fetched = <%= method_call('fetch_wrapped_resource', ['params', ("'#{object.kind}'" if object.kind?),
62+
"'#{object.self_link_query.kind}'",
63+
"'#{object.self_link_query.items}'"], 2) %>
64+
parse unless @fetched.nil?
65+
end
66+
<% end # object.self_link_query.nil? -%>
67+
68+
# TODO
69+
def parse end
70+
71+
def exists?
72+
!@fetched.nil?
73+
end
74+
end

0 commit comments

Comments
 (0)