diff --git a/mmv1/compiler.rb b/mmv1/compiler.rb index 1f2cdc5f82c3..3b58de03fe6c 100755 --- a/mmv1/compiler.rb +++ b/mmv1/compiler.rb @@ -156,10 +156,10 @@ api_override_path = File.join(override_dir, product_name, 'api.yaml') if override_dir api_yaml_path = File.join(product_name, 'api.yaml') - provider_override_path = '' - provider_override_path = File.join(override_dir, product_name, "#{provider_name}.yaml") \ - if override_dir - provider_yaml_path = File.join(product_name, "#{provider_name}.yaml") + # provider_override_path = '' + # provider_override_path = File.join(override_dir, product_name, "#{provider_name}.yaml") \ + # if override_dir + # provider_yaml_path = File.join(product_name, "#{provider_name}.yaml") unless File.exist?(product_yaml_path) || File.exist?(product_override_path) \ || File.exist?(api_yaml_path) || File.exist?(api_override_path) @@ -188,13 +188,13 @@ product_yaml = File.read(product_yaml_path) end - unless File.exist?(provider_yaml_path) || File.exist?(provider_override_path) - unless File.exist?(product_yaml_path) || File.exist?(product_override_path) - Google::LOGGER.info "#{product_name}: Skipped as no #{provider_name}.yaml file exists" - next - end - provider_yaml_path = 'templates/terraform.yaml' - end + # unless File.exist?(provider_yaml_path) || File.exist?(provider_override_path) + # unless File.exist?(product_yaml_path) || File.exist?(product_override_path) + # Google::LOGGER.info "#{product_name}: Skipped as no #{provider_name}.yaml file exists" + # next + # end + # provider_yaml_path = 'templates/terraform.yaml' + # end raise "Output path '#{output_path}' does not exist or is not a directory" \ unless Dir.exist?(output_path) @@ -209,6 +209,8 @@ next end + Google::LOGGER.info "#{product_yaml_path}: product_yaml_path" + if File.exist?(product_yaml_path) || File.exist?(product_override_path) resources = [] Dir["#{product_name}/*"].each do |file_path| @@ -262,22 +264,33 @@ product_api.set_variable(resources, 'objects') end - if File.exist?(provider_yaml_path) - product_api, provider_config, = \ - Provider::Config.parse(provider_yaml_path, product_api, version) - end - # Load any dynamic overrides passed in with -r - if File.exist?(provider_override_path) - product_api, provider_config, = \ - Provider::Config.parse(provider_override_path, product_api, version, override_dir) - end + # Google::LOGGER.info "#{provider_yaml_path}: provider_yaml_path" + # Google::LOGGER.info "#{provider_override_path}: provider_override_path" + + # Google::LOGGER.info "#{product_api}: Compiling provider config product_api 0" + + # if File.exist?(provider_yaml_path) + # product_api, provider_config, = \ + # Provider::Config.parse(provider_yaml_path, product_api, version) + # end + # # Load any dynamic overrides passed in with -r + # if File.exist?(provider_override_path) + # product_api, provider_config, = \ + # Provider::Config.parse(provider_override_path, product_api, version, override_dir) + # end + + provider_config = nil + product_api&.validate + + # Google::LOGGER.info "#{product_api}: Compiling provider config product_api" + # Google::LOGGER.info "#{provider_config}: Compiling provider config provider_config" Google::LOGGER.info "#{product_name}: Compiling provider config" - pp provider_config if ENV['COMPILER_DEBUG'] + # pp provider_config if ENV['COMPILER_DEBUG'] if force_provider.nil? provider = \ - provider_config.provider.new(provider_config, product_api, version, start_time) + Provider::Terraform.new(provider_config, product_api, version, start_time) else override_providers = { 'oics' => Provider::TerraformOiCS, diff --git a/mmv1/provider/config.rb b/mmv1/provider/config.rb deleted file mode 100644 index a306cda5caa4..000000000000 --- a/mmv1/provider/config.rb +++ /dev/null @@ -1,114 +0,0 @@ -# Copyright 2017 Google Inc. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -require 'api/object' -require 'compile/core' - -module Provider - # Settings for the provider - class Config < Api::Object - include Compile::Core - extend Compile::Core - - # Overrides for datasources - attr_reader :datasources - attr_reader :files - - # Some tool-specific names may be in use, and they won't all match; - # For Terraform, some products use the API client name w/o spaces and - # others use spaces. Eg: "app_engine" vs "appengine". - # Note: This should not be used for vanity names for new products. - # This was added for services with a mix of handwritten and generated - # resources. - attr_reader :legacy_name - - # Some product names do not match their [golang] client name - attr_reader :client_name - - attr_reader :overrides - - # List of files to copy or compile into target module - class Files < Api::Object - attr_reader :compile - attr_reader :copy - attr_reader :resource - - def validate - super - check :compile, type: Hash - check :copy, type: Hash - check :resource, type: Hash - end - end - - def self.parse(cfg_file, api = nil, version_name = 'ga', provider_override_path = nil) - raise 'Version passed to the compiler cannot be nil' if version_name.nil? - - # Compile step #1: compile with generic class to instantiate target class - source = compile(cfg_file) - - unless provider_override_path.nil? - # Replace overrides directory if we are running with a provider override - # This allows providers to reference files in their override path - source = source.gsub('{{override_path}}', provider_override_path) - end - config = Google::YamlValidator.parse(source) - - raise "Config #{cfg_file}(#{config.class}) is not a Provider::Config" \ - unless config.class <= Provider::Config - - config.spread_api config, api, [], '' unless api.nil? - config.validate - api&.validate - [api, config] - end - - def provider - raise "#{self.class}#provider not implemented" - end - - def self.next_version(version) - [Gem::Version.new(version).bump, 0].join('.') - end - - def validate - super - - check :files, type: Provider::Config::Files - end - - # Provides the API object to any type that requires, e.g. for validation - # purposes, such as Api::Resource::HashArray which enforces that the keys - # are necessarily objects defined in the API. - def spread_api(object, api, visited, indent) - object.instance_variables.each do |var| - var_value = object.instance_variable_get(var) - next if visited.include?(var_value) - - visited << var_value - var_value.consume_api api if var_value.respond_to?(:consume_api) - var_value.consume_config api, self \ - if var_value.respond_to?(:consume_config) - spread_api(var_value, api, visited, indent) - end - end - - def resource_override - Overrides::ResourceOverride - end - - def property_override - Overrides::PropertyOverride - end - end -end diff --git a/mmv1/provider/terraform.rb b/mmv1/provider/terraform.rb index 20c513bf5d6e..5eb250709831 100644 --- a/mmv1/provider/terraform.rb +++ b/mmv1/provider/terraform.rb @@ -91,8 +91,8 @@ def generate(output_folder, types, product_path, dump_yaml, generate_code, gener # common-compile.yaml is a special file that will get compiled by the last product # used in a single invocation of the compiled. It should not contain product-specific # information; instead, it should be run-specific such as the version to compile at. - compile_product_files(output_folder) \ - unless @config.files.nil? || @config.files.compile.nil? + # compile_product_files(output_folder) \ + # unless @config.files.nil? || @config.files.compile.nil? FileUtils.mkpath output_folder pwd = Dir.pwd @@ -160,16 +160,16 @@ def copy_file_list(output_folder, files) end # Compiles files specified within the product - def compile_product_files(output_folder) - file_template = ProductFileTemplate.new( - output_folder, - nil, - @api, - @target_version_name, - build_env - ) - compile_file_list(output_folder, @config.files.compile, file_template) - end + # def compile_product_files(output_folder) + # file_template = ProductFileTemplate.new( + # output_folder, + # nil, + # @api, + # @target_version_name, + # build_env + # ) + # compile_file_list(output_folder, @config.files.compile, file_template) + # end # Compiles files that are shared at the provider level def compile_common_files( diff --git a/mmv1/provider/terraform/config.rb b/mmv1/provider/terraform/config.rb index 23f60d2deec9..da665c17eb21 100644 --- a/mmv1/provider/terraform/config.rb +++ b/mmv1/provider/terraform/config.rb @@ -11,12 +11,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'provider/config' +# require 'provider/config' module Provider class Terraform # Settings for the provider - class Config < Provider::Config + class Config def provider Provider::Terraform end diff --git a/mmv1/templates/terraform.yaml b/mmv1/templates/terraform.yaml deleted file mode 100644 index d68eb1db3342..000000000000 --- a/mmv1/templates/terraform.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2023 Google Inc. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Base terraform.yaml for product folders that have been converted over to the -# per-resource format. ---- !ruby/object:Provider::Terraform::Config -# This is for copying files over -files: !ruby/object:Provider::Config::Files - # These files have templating (ERB) code that will be run. - # This is usually to add licensing info, autogeneration notices, etc. - compile: -<%= lines(indent(compile('provider/terraform/product~compile.yaml'), 4)) -%> \ No newline at end of file