Skip to content

Commit

Permalink
Adding basic singular resource code
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick committed Oct 16, 2018
1 parent 078067a commit 1867189
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
1 change: 1 addition & 0 deletions provider/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Provider
# Code generator for Example Cookbooks that manage Google Cloud Platform
# resources.
class Inspec < Provider::Core
include Google::RubyUtils
# Settings for the provider
class Config < Provider::Config
attr_reader :manifest
Expand Down
59 changes: 58 additions & 1 deletion templates/inspec/singular_resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,61 @@
-%>
<%= compile 'templates/license.erb' -%>
<%= lines(autogen_notice :ruby) -%>
<%= lines(autogen_notice :ruby) -%>

# A provider to manage <%= @api.name -%> resources.
<%= lines(indent(
emit_rubocop(binding, :class,
['Google', @api.prefix.upcase, object.name].join('::'),
:disabled),
4)) -%>
class <%= object.name -%> < Inspec.resource(1)

name 'google_<%= product_ns.downcase -%>_<%= object.name.downcase -%>'
desc '<%= object.name -%>'
supports platform: 'gcp-mm'

<% object.properties.reject(&:input).each do |prop| -%>
<%= "attr_reader :#{prop.out_name}" -%>
<% end -%>
<%
base = "'#{object.self_link_url[0].join}'"
url = object.self_link_url[1]
if url.is_a?(Array)
url = url.join('')
else
url = url.split("\n").join('')
end
url = "'#{url}'"
-%>
def base
<%= base %>
end

def url
<%= url %>
end

<% if object.self_link_query.nil? -%>
def initialize(params)
@fetched = <%= method_call('fetch_resource', ['params', ("'#{object.kind}'" if object.kind?)], 2) %>
parse unless @fetched.nil?
end
<% else # object.self_link_query.nil? -%>
def initialize(params)
@fetched = <%= method_call('fetch_wrapped_resource', ['params', ("'#{object.kind}'" if object.kind?),
"'#{object.self_link_query.kind}'",
"'#{object.self_link_query.items}'"], 2) %>
parse unless @fetched.nil?
end
<% end # object.self_link_query.nil? -%>

# TODO
def parse end

def exists?
[email protected]?
end
end

0 comments on commit 1867189

Please sign in to comment.