From 9088ce589a2ef44e172a59e5d418becd3998b264 Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Tue, 12 Mar 2019 17:29:02 -0700 Subject: [PATCH] Add override for exclude_reader in InSpec --- overrides/inspec/property_override.rb | 4 +++- products/bigquery/inspec.yaml | 4 ++-- templates/inspec/plural_resource.erb | 4 ++-- templates/inspec/singular_resource.erb | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/overrides/inspec/property_override.rb b/overrides/inspec/property_override.rb index 53807781e503..d235eb7cc5fd 100644 --- a/overrides/inspec/property_override.rb +++ b/overrides/inspec/property_override.rb @@ -23,7 +23,8 @@ class PropertyOverride < Overrides::PropertyOverride def self.attributes [ :name_from_self_link, # Set to convert self link to name - :exclude_plural + :exclude_plural, + :exclude_reader # Set to exclude the attribute reader within generated resources ] end @@ -32,6 +33,7 @@ def self.attributes def self.validate check :name_from_self_link, type: :boolean, default: false check :exclude_plural, type: :boolean, default: false + check :exclude_reader, type: :boolean, default: false end end end diff --git a/products/bigquery/inspec.yaml b/products/bigquery/inspec.yaml index 91c459b78b88..5e76a6bf6c95 100644 --- a/products/bigquery/inspec.yaml +++ b/products/bigquery/inspec.yaml @@ -21,6 +21,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides properties: description: !ruby/object:Overrides::Inspec::PropertyOverride exclude_plural: true + exclude_reader: true access: !ruby/object:Overrides::Inspec::PropertyOverride exclude_plural: true defaultTableExpirationMs: !ruby/object:Overrides::Inspec::PropertyOverride @@ -29,6 +30,7 @@ overrides: !ruby/object:Overrides::ResourceOverrides exclude_plural: true name: !ruby/object:Overrides::Inspec::PropertyOverride exclude_plural: true + exclude_reader: true lastModifiedTime: !ruby/object:Overrides::Inspec::PropertyOverride exclude_plural: true additional_functions: | @@ -38,7 +40,5 @@ overrides: !ruby/object:Overrides::ResourceOverrides Table: !ruby/object:Overrides::Inspec::ResourceOverride properties: - name: !ruby/object:Overrides::Inspec::PropertyOverride - exclude_plural: true description: !ruby/object:Overrides::Inspec::PropertyOverride exclude_plural: true \ No newline at end of file diff --git a/templates/inspec/plural_resource.erb b/templates/inspec/plural_resource.erb index eb4b4f15a958..440c8778cf6f 100644 --- a/templates/inspec/plural_resource.erb +++ b/templates/inspec/plural_resource.erb @@ -27,7 +27,7 @@ name = "google_#{product_ns.downcase}_#{object.name.underscore}" attr_reader :table filter_table_config = FilterTable.create -<% object.all_user_properties.reject {|prop| prop.exclude_plural }.each do |prop| -%> +<% object.all_user_properties.reject(&:exclude_plural).reject(&:exclude_reader).each do |prop| -%> <%= "filter_table_config.add(:#{prop.out_name.pluralize}, field: :#{prop.out_name})" -%> <% end # object.all_user_properties.each do -%> @@ -74,7 +74,7 @@ link_query = object.self_link_query || object.collection_url_response def transformers { -<% object.all_user_properties.reject(&:exclude_plural).each do |prop| -%> +<% object.all_user_properties.reject(&:exclude_plural).reject(&:exclude_reader).each do |prop| -%> '<%= prop.api_name -%>' => ->(obj) { <%= "return :#{prop.out_name}, #{parse_code(prop, 'obj')}" -%> }, <% end # object.all_user_properties.each -%> } diff --git a/templates/inspec/singular_resource.erb b/templates/inspec/singular_resource.erb index e708fb37b78b..ab55f9f2c2cc 100644 --- a/templates/inspec/singular_resource.erb +++ b/templates/inspec/singular_resource.erb @@ -32,7 +32,7 @@ class <%= object.name -%> < GcpResourceBase desc '<%= object.name -%>' supports platform: 'gcp' -<% object.all_user_properties.each do |prop| -%> +<% object.all_user_properties.reject(&:exclude_reader).each do |prop| -%> <%= "attr_reader :#{prop.out_name}" -%> <% end -%> @@ -67,7 +67,7 @@ class <%= object.name -%> < GcpResourceBase def parse <% - parse_code = object.all_user_properties.map do |prop| + parse_code = object.all_user_properties.reject(&:exclude_reader).map do |prop| assignment = "@#{prop.out_name} = #{parse_code(prop, '@fetched')}" end -%>