Skip to content

Commit

Permalink
Removed the ::NONE types to clean up provider yamls
Browse files Browse the repository at this point in the history
Removed the use of Api::Object::MissingObject and ::NONE types to clean up provider yaml files.

For attributes in .yaml files with no properties, you can remove the attribute all together or place in a !ruby/object:Provider::Config::TestData (or HashArray) with no properties.
  • Loading branch information
rambleraptor authored Jan 18, 2018
2 parents 4581a45 + 488416a commit 5654ff2
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 75 deletions.
17 changes: 0 additions & 17 deletions api/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@
module Api
# Repesents a base object
class Object < Google::YamlValidator
# Basic functions for defining classes that explicitly marks a property as
# not in use, such as Provider::Config::TestData::NONE
module MissingObject
attr_reader :reason

def validate
return if @validated
check_property :reason, String
# Now that we verified a reason was provided, delete it so it does not
# end in the object mapping (and eventually fail as the type "reason"
# will likely never exist)
remove_instance_variable('@reason')
super
@validated = true
end
end

# Represents an object that has a (mandatory) name
class Named < Api::Object
attr_reader :name
Expand Down
5 changes: 0 additions & 5 deletions api/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ def kind?
# - data3
# - data4
class HashArray < Api::Object
# A dummy class that identifies the property as deliberately unused.
class NONE < HashArray
include Api::Object::MissingObject
end

def consume_api(api)
@__api = api
end
Expand Down
2 changes: 0 additions & 2 deletions products/compute/chef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ files: !ruby/object:Provider::Config::Files
<%= indent(include('provider/chef/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/chef/common~compile~after.yaml'), 4) %>
<% # common~compile~after.yaml should be the last line of compile: section %>
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: 'Test Data will be automatically generated'
style:
- !ruby/object:Provider::Config::StyleException
name: libraries/google/compute/property/backendservice_cache_key_policy.rb
Expand Down
2 changes: 0 additions & 2 deletions products/container/chef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ files: !ruby/object:Provider::Config::Files
<%= indent(include('provider/chef/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/chef/common~compile~after.yaml'), 4) %>
<% # common~compile~after.yaml should be the last line of compile: section %>
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: "Autogenerated"
style:
- !ruby/object:Provider::Config::StyleException
name: resources/cluster.rb
Expand Down
5 changes: 0 additions & 5 deletions products/container/puppet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ bolt_tasks:
puts({ status: 'failure', error: e }.to_json)
exit 1
end
tests: !ruby/object:Api::Resource::HashArray::NONE
# TODO(nelsonjr): Create all the necessary code here.
reason: 'Prototype.'
properties:
- array
- namevalues
Expand All @@ -124,8 +121,6 @@ files: !ruby/object:Provider::Config::Files
lib/google/object_store.rb: google/object_store.rb
<%= indent(include('provider/puppet/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/puppet/common~compile~after.yaml'), 4) %>
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: 'Autogenerated'
style:
- !ruby/object:Provider::Config::StyleException
name: lib/google/container/property/cluster_node_config.rb
Expand Down
2 changes: 0 additions & 2 deletions products/iam/puppet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ files: !ruby/object:Provider::Config::Files
<%= indent(include('provider/puppet/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/puppet/common~compile~after.yaml'), 4) %>
<% # common~compile~after.yaml should be the last line of compile: section %>
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: 'Test Data will be automatically generated'
changelog:
- !ruby/object:Provider::Config::Changelog
version: '0.1.0'
Expand Down
17 changes: 8 additions & 9 deletions products/pubsub/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@

--- !ruby/object:Provider::Example::Config
# This is where custom code would be defined eventually.
objects: !ruby/object:Api::Resource::HashArray::NONE
# All classes need at least one attribute for YAML parsing because Ruby.
reason: 'Not needed'
objects: !ruby/object:Api::Resource::HashArray

# This is for a list of example files.
examples: !ruby/object:Api::Resource::HashArray::NONE
reason: 'Not needed'
examples: !ruby/object:Api::Resource::HashArray

# This is for copying files over
files: !ruby/object:Provider::Config::Files
# All of these files will be copied verbatim.
Expand All @@ -28,14 +27,14 @@ files: !ruby/object:Provider::Config::Files
# This is usually to add licensing info, autogeneration notices, etc.
compile:
'compiled_file': 'templates/example/compiled_file'

# This is for custom testing code. All of our tests follow a specific pattern
# that sometimes needs to be deviated from. We're working towards a world where
# these handwritten tests would be unnecessary in many cases (custom types).
tests: !ruby/object:Api::Resource::HashArray::NONE
reason: 'Not needed.'
tests: !ruby/object:Api::Resource::HashArray

# This would be for custom network responses. Tests work by running some block
# of autogenerated Chef/Puppet code and then verifying the network calls.
# The network call verifications are automatically generated, but can be
# overriden.
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: 'Test Data will be automatically generated'
test_data: !ruby/object:Provider::Config::TestData
2 changes: 0 additions & 2 deletions products/resourcemanager/chef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ files: !ruby/object:Provider::Config::Files
<%= indent(include('provider/chef/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/chef/common~compile~after.yaml'), 4) %>
<% # common~compile~after.yaml should be the last line of compile: section %>
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: 'Network data will be autogenerated'
changelog:
- !ruby/object:Provider::Config::Changelog
version: '0.1.0'
Expand Down
2 changes: 0 additions & 2 deletions products/resourcemanager/puppet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ files: !ruby/object:Provider::Config::Files
<%= indent(include('provider/puppet/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/puppet/common~compile~after.yaml'), 4) %>
<% # common~compile~after.yaml should be the last line of compile: section %>
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: 'Network data will be autogenerated'
changelog:
- !ruby/object:Provider::Config::Changelog
version: '0.1.0'
Expand Down
2 changes: 0 additions & 2 deletions products/storage/chef.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ files: !ruby/object:Provider::Config::Files
<%= indent(include('provider/chef/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/chef/common~compile~after.yaml'), 4) %>
<% # common~compile~after.yaml should be the last line of compile: section %>
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: 'Test Data will be automatically generated'
style:
- !ruby/object:Provider::Config::StyleException
name: libraries/google/storage/property/bucket_acl.rb
Expand Down
4 changes: 0 additions & 4 deletions products/storage/puppet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ manifest: !ruby/object:Provider::Puppet::Manifest
versions: '>= 0.2.0 < 0.3.0'
operating_systems:
<%= indent(include('provider/puppet/common~operating_systems.yaml'), 4) %>
objects: !ruby/object:Api::Resource::HashArray::NONE
reason: 'No configuration needed for objects.'
bolt_tasks:
- !ruby/object:Provider::Puppet::BoltTask
name: 'upload'
Expand Down Expand Up @@ -101,8 +99,6 @@ files: !ruby/object:Provider::Config::Files
<%= indent(include('provider/puppet/common~compile~before.yaml'), 4) %>
<%= indent(include('provider/puppet/common~compile~after.yaml'), 4) %>
<% # common~compile~after.yaml should be the last line of compile: section %>
test_data: !ruby/object:Provider::Config::TestData::NONE
reason: 'Test Data will be automatically generated'
style:
- !ruby/object:Provider::Config::StyleException
name: lib/google/storage/property/bucket_acl.rb
Expand Down
33 changes: 11 additions & 22 deletions provider/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ def initialize(name, versions)
class TestData < Api::Object
attr_reader :network

# A dummy class that identifies the property as deliberately unused.
class NONE < TestData
include Api::Object::MissingObject

def validate
@network = Api::Resource::HashArray.new
super
end
end

def validate
super
check_property :network, Api::Resource::HashArray
Expand All @@ -124,11 +114,6 @@ class Files < Api::Object
attr_reader :copy
attr_reader :permissions

# A dummy class that identifies the property as deliberately unused.
class NONE < Files
include Api::Object::MissingObject
end

def validate
super
check_property :compile, Hash unless @compile.nil?
Expand Down Expand Up @@ -205,14 +190,18 @@ def provider

def validate
super
check_property :examples, Api::Resource::HashArray
check_property :files, Provider::Config::Files
check_property :objects, Api::Resource::HashArray
check_property :test_data, Provider::Config::TestData
check_property :examples, Api::Resource::HashArray unless @examples.nil?
check_property :files, Provider::Config::Files unless @files.nil?
check_property :objects, Api::Resource::HashArray unless @objects.nil?
check_property :test_data, Provider::Config::TestData \
unless @test_data.nil?
check_property :tests, Api::Resource::HashArray unless @tests.nil?
check_property_list :style, @style, Provider::Config::StyleException
check_property_list :changelog, @changelog, Provider::Config::Changelog
check_property_list :functions, @functions, Provider::Config::Function
check_property_list :style, @style, Provider::Config::StyleException \
unless @style.nil?
check_property_list :changelog, @changelog, Provider::Config::Changelog \
unless @changelog.nil?
check_property_list :functions, @functions, Provider::Config::Function \
unless @functions.nil?
end

# Provides the API object to any type that requires, e.g. for validation
Expand Down
7 changes: 6 additions & 1 deletion provider/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,13 @@ def create_object_list(section, mapper)
end

def list_manual_network_data
test_data = if @config.test_data && @config.test_data.network
@config.test_data.network
else
{}
end
create_object_list(
@config.test_data.network,
test_data,
lambda do |object, file|
type = Google::StringUtils.underscore(object.name)
["spec/data/network/#{object.out_name}/#{file}.yaml",
Expand Down

0 comments on commit 5654ff2

Please sign in to comment.