diff --git a/provider/inspec.rb b/provider/inspec.rb index 7f66da907f30..5c309a87d08a 100644 --- a/provider/inspec.rb +++ b/provider/inspec.rb @@ -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 diff --git a/templates/inspec/singular_resource.erb b/templates/inspec/singular_resource.erb index 3628efec92c1..8251616a6796 100644 --- a/templates/inspec/singular_resource.erb +++ b/templates/inspec/singular_resource.erb @@ -14,4 +14,61 @@ -%> <%= compile 'templates/license.erb' -%> -<%= lines(autogen_notice :ruby) -%> \ No newline at end of file +<%= 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? + !@fetched.nil? + end +end \ No newline at end of file