Skip to content

Commit 988ac1c

Browse files
committed
Clean up resource converter
1 parent 7882cee commit 988ac1c

File tree

4 files changed

+18
-45
lines changed

4 files changed

+18
-45
lines changed

lib/octocatalog-diff/catalog.rb

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,7 @@ def build(logger = Logger.new(StringIO.new))
100100
validate_references
101101
return unless valid?
102102

103-
if supports_compare_file_text?
104-
convert_file_resources(logger)
105-
elsif @options[:compare_file_text]
106-
logger.debug "Disabling --compare-file-text; not supported by #{self.class}"
107-
end
103+
convert_file_resources if @options[:compare_file_text]
108104

109105
true
110106
end
@@ -144,12 +140,10 @@ def compilation_dir=(dir)
144140
@override_compilation_dir = dir
145141
end
146142

147-
# Stub method for "convert_file_resources" to raise an error if the backend doesn't support this.
148-
# Getting here is expected to be a bug condition.
149-
def convert_file_resources(_logger = Logger.new(StringIO.new))
150-
# :nocov:
151-
raise "convert_file_resources was called on but is not supported by #{self.class}"
152-
# :nocov:
143+
# Stub method for "convert_file_resources" -- returns false because if the underlying class does
144+
# not implement this method, it's not supported.
145+
def convert_file_resources(_dry_run = false)
146+
false
153147
end
154148

155149
# Retrieve the error message.
@@ -211,12 +205,6 @@ def retries
211205
nil
212206
end
213207

214-
# By default, catalogs do not support converting and comparing file resources. This can be overridden
215-
# by backends that do support it.
216-
def supports_compare_file_text?
217-
false
218-
end
219-
220208
# Determine if the catalog build was successful.
221209
# @return [Boolean] Whether the catalog is valid
222210
def valid?
@@ -332,16 +320,5 @@ def build_resource_hash
332320
end
333321
end
334322
end
335-
336-
# Private method: A common way of running convert_file_resources for backends that allow it.
337-
def convert_file_resources_real(logger = Logger.new(StringIO.new))
338-
return false unless @options[:compare_file_text]
339-
if @options[:basedir]
340-
OctocatalogDiff::CatalogUtil::FileResources.convert_file_resources(self, environment)
341-
else
342-
logger.debug "Disabling --compare-file-text; not supported by #{self.class} without basedir"
343-
false
344-
end
345-
end
346323
end
347324
end

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ def environment
6363
@options.fetch(:environment, 'production')
6464
end
6565

66-
# Convert file source => ... to content => ... if a basedir is given.
67-
def convert_file_resources(logger = Logger.new(StringIO.new))
68-
convert_file_resources_real(logger)
69-
end
70-
71-
def supports_compare_file_text?
72-
true
66+
# Convert file resources source => "puppet:///..." to content => "actual content of file".
67+
def convert_file_resources(dry_run = false)
68+
return @options.key?(:basedir) if dry_run
69+
return false unless @options[:basedir]
70+
OctocatalogDiff::CatalogUtil::FileResources.convert_file_resources(self, environment)
7371
end
7472

7573
private

lib/octocatalog-diff/catalog/json.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ def initialize(options)
2929
end
3030
end
3131

32-
# Convert file source => ... to content => ... if a basedir is given.
33-
def convert_file_resources(logger = Logger.new(StringIO.new))
34-
convert_file_resources_real(logger)
35-
end
36-
37-
def supports_compare_file_text?
38-
true
32+
# Convert file resources source => "puppet:///..." to content => "actual content of file".
33+
def convert_file_resources(dry_run = false)
34+
return @options.key?(:basedir) if dry_run
35+
return false unless @options[:basedir]
36+
OctocatalogDiff::CatalogUtil::FileResources.convert_file_resources(self, environment)
3937
end
4038
end
4139
end

lib/octocatalog-diff/util/catalogs.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def build_catalog_parallelizer
6969

7070
# Disable --compare-file-text if either (or both) of the chosen backends do not support it
7171
if @options.fetch(:compare_file_text, false)
72-
result.each do |_key, val|
73-
next if val.supports_compare_file_text?
74-
@logger.debug "Disabling --compare-file-text; not supported by #{val.builder}"
72+
result.each do |_key, builder_obj|
73+
next if builder_obj.convert_file_resources(true)
74+
@logger.debug "Disabling --compare-file-text; not supported by #{builder_obj.builder}"
7575
@options[:compare_file_text] = false
7676
catalog_tasks.map! do |x|
7777
x[1].args[:compare_file_text] = false

0 commit comments

Comments
 (0)