Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions provider/azure/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,37 @@ def get_example_by_reference(reference)
end

def get_example_by_names(example_name, product_name = nil)
spec_dir = File.dirname(@config.config_file)
product_name ||= File.basename(spec_dir)
example_yaml = File.join(File.dirname(spec_dir), product_name, 'examples', @provider, "#{example_name}.yaml")
resource_dir = get_resource_dir(File.dirname(@config.config_file))
resource_dir = File.join(File.dirname(resource_dir), product_name) unless product_name.nil?
spec_dir = get_spec_dir(resource_dir)
example_yaml = File.join(spec_dir, 'examples', @provider, "#{example_name}.yaml")
example = Google::YamlValidator.parse(File.read(example_yaml))
raise "#{example_yaml}(#{example.class}) is not Provider::Azure::Example" unless example.is_a?(Provider::Azure::Example)
example.validate
example
end

# The folder structure generated by autorest.cli is different than the magic-module-spec folder
# structure, where autorest.cli has one more subdirectory named after `package-YY-MM-DD` for each
# resource, which contains the content otherwise had been placed directly under the resource_dir
# in magic-module-spec.
#
# Given a `config_dir` and return the `resource_dir` taking *package-xxx* subdirectory
# into consideration.
def get_resource_dir(config_dir)
return File.dirname(config_dir) if /^package-[\d-]+$/ =~ File.basename(config_dir)

config_dir
end

# Given a `resource_dir` and return the `config_dir` taking *package-xxx* subdirectory
# into consideration.
# NOTE: currently we assume there is at most only one subdirectory.
def get_spec_dir(resource_dir)
potential_subdir = Dir.glob(File.join(resource_dir, 'package-[0-9-]*'))[0]
potential_subdir.nil? ? resource_dir : potential_subdir
end

def get_custom_template_path(template_path)
return nil if template_path.nil?
spec_dir = File.dirname(@config.config_file)
Expand Down