Skip to content

Commit e3531b3

Browse files
author
Kevin Paulisse
committed
Enable specified environments for hiera configuration, un-hardcode production
1 parent e8262ce commit e3531b3

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

lib/octocatalog-diff/catalog-util/builddir.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module CatalogUtil
1313
# - Register a handler to remove the temporary directory upon exit
1414
# - Install needed configuration files within the directory (e.g. puppetdb.conf)
1515
# - Install the facts into the directory
16-
# - Install 'environments/production' which is a symlink to the checkout of the puppet code
16+
# - Install 'environments/(environment)' which is a symlink to the checkout of the puppet code
1717
class BuildDir
1818
# Allow the path to the temporary directory to be read
1919
attr_reader :tempdir, :enc, :fact_file
@@ -220,10 +220,10 @@ def install_hiera_config(logger, options)
220220
end
221221
file_src = if hiera_config.start_with? '/'
222222
hiera_config
223-
elsif hiera_config =~ %r{^environments/production/}
223+
elsif hiera_config =~ %r{^environments/#{Regexp.escape(environment)}/}
224224
File.join(@tempdir, hiera_config)
225225
else
226-
File.join(@tempdir, 'environments', 'production', hiera_config)
226+
File.join(@tempdir, 'environments', environment, hiera_config)
227227
end
228228
raise Errno::ENOENT, "hiera.yaml (#{file_src}) wasn't found" unless File.file?(file_src)
229229

@@ -236,10 +236,10 @@ def install_hiera_config(logger, options)
236236
rexp1 = Regexp.new('^' + options[:hiera_path_strip])
237237
obj[key.to_sym][:datadir].sub!(rexp1, @tempdir)
238238
elsif options[:hiera_path].is_a?(String)
239-
obj[key.to_sym][:datadir] = File.join(@tempdir, 'environments', 'production', options[:hiera_path])
239+
obj[key.to_sym][:datadir] = File.join(@tempdir, 'environments', environment, options[:hiera_path])
240240
end
241241
rexp2 = Regexp.new('%{(::)?environment}')
242-
obj[key.to_sym][:datadir].sub!(rexp2, 'production')
242+
obj[key.to_sym][:datadir].sub!(rexp2, environment)
243243

244244
# Make sure the dirctory exists. If not, log a warning. This is *probably* a setup error, but we don't
245245
# want it to be fatal in case (for example) someone is doing an octocatalog-diff to verify moving this
@@ -327,6 +327,10 @@ def install_ssl_client_password(logger, password)
327327
File.open(password_outfile, 'w') { |f| f.write(password) }
328328
logger.debug "Installed SSL client key password in #{password_outfile}"
329329
end
330+
331+
def environment
332+
@options[:preserve_environments] ? @options.fetch(:environment, 'production') : 'production'
333+
end
330334
end
331335
end
332336
end

0 commit comments

Comments
 (0)