Skip to content

Commit

Permalink
Fixing resource imports
Browse files Browse the repository at this point in the history
  • Loading branch information
slevenick committed Oct 16, 2018
1 parent 332c368 commit 9ec2097
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
10 changes: 9 additions & 1 deletion provider/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def emit_nested_object_overrides(data)
end

def primitive? (property)
return property.is_a?(::Api::Type::Primitive) || (property.is_a?(Api::Type::Array) && !property.item_type.is_a?(::Api::Type::NestedObject))
array_nested = (property.is_a?(Api::Type::Array) && !property.item_type.is_a?(::Api::Type::NestedObject))
map = property.is_a?(::Api::Type::NameValues)
return property.is_a?(::Api::Type::Primitive) || array_nested || map
end

def resource_ref? (property)
Expand All @@ -117,6 +119,12 @@ def generate_requires(properties, requires = [])
requires
end

# InSpec doesn't need wrappers for primitives, so exclude them
def emit_requires(requires)
primitives = ['boolean', 'enum', 'string', 'time', 'integer', 'array', 'string_array', 'double']
requires.flatten.sort.uniq.reject{|r| primitives.include?(r.split('/').last)}.map { |r| "require '#{r}'" }.join("\n")
end

def plural(word)
# TODO use a real ruby gem for this? Pluralization is hard
if word[-1] == 's'
Expand Down
2 changes: 1 addition & 1 deletion templates/inspec/nested_object.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Google
return nil if args.nil?
<% nested_properties.each do |prop| -%>
<%
if primitive?(prop)
if primitive?(prop) || resource_ref?(prop)
init = "args['#{prop.api_name}']"
elsif typed_array?(prop)
init = "#{prop.property_type}.parse(args['#{prop.api_name}'])"
Expand Down
2 changes: 1 addition & 1 deletion templates/inspec/plural_resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name = "google_#{product_ns.downcase}_#{object.name.underscore}"
-%>
name '<%= plural(name) -%>'
desc '<%= object.name -%> plural resource'
supports platform: 'gcp-mm'
supports platform: 'gcp2'

filter_table_config = FilterTable.create
<% object.all_user_properties.each do |prop| -%>
Expand Down
2 changes: 1 addition & 1 deletion templates/inspec/singular_resource.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class <%= object.name -%> < Inspec.resource(1)

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

<% object.properties.reject(&:input).each do |prop| -%>
<%= "attr_reader :#{prop.out_name}" -%>
Expand Down

0 comments on commit 9ec2097

Please sign in to comment.