diff --git a/jobs/web/templates/bpm.yml.erb b/jobs/web/templates/bpm.yml.erb index be21e56f7..357ec3ad0 100644 --- a/jobs/web/templates/bpm.yml.erb +++ b/jobs/web/templates/bpm.yml.erb @@ -69,8 +69,6 @@ processes: def env_file_flag(v, env) case v - when Array - v.collect.with_index { |v, i| "/var/vcap/jobs/web/config/env/#{env}_#{i}" }.join(",") when Hash v.collect { |k, v| "#{k}:/var/vcap/jobs/web/config/env/#{env}_#{k}" }.join(",") else @@ -80,8 +78,6 @@ processes: def env_windows_file_flag(v, env) case v - when Array - v.collect.with_index { |v, i| "C:\\var\\vcap\\jobs\\web\\config\\env\\#{env}_#{i}" }.join(",") when Hash v.collect { |k, v| "#{k}:C:\\var\\vcap\\jobs\\web\\config\\env\\#{env}_#{k}" }.join(",") else diff --git a/jobs/web/templates/pre_start.erb b/jobs/web/templates/pre_start.erb index e9e06a16a..209f51ace 100644 --- a/jobs/web/templates/pre_start.erb +++ b/jobs/web/templates/pre_start.erb @@ -22,7 +22,7 @@ mkdir -p /var/vcap/jobs/web/config/env def env_file_content(v) case v when Array - v.join("\n").chomp + "\n" + v.collect(&:chomp).join("\n").chomp + "\n" when String v.chomp + "\n" else @@ -34,18 +34,13 @@ mkdir -p /var/vcap/jobs/web/config/env path = "/var/vcap/jobs/web/config/env/#{env}" case v - when Array - v.collect.with_index do |v, i| - fn = "#{path}_#{i}" - "cat > #{fn} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(fn)}" - end.join("\n\n") when Hash v.collect do |k, v| fn = "#{path}_#{k}" "cat > #{fn} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(fn)}" end.join("\n\n") else - "cat > #{path} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(path)}\n" + "cat > #{path} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(path)}" end end -%> diff --git a/jobs/worker-windows/templates/env.ps1.erb b/jobs/worker-windows/templates/env.ps1.erb index 3b07c2550..c324710ea 100644 --- a/jobs/worker-windows/templates/env.ps1.erb +++ b/jobs/worker-windows/templates/env.ps1.erb @@ -59,8 +59,6 @@ $env:CONCOURSE_TSA_PUBLIC_KEY = "C:\var\vcap\jobs\worker-windows\config\worker_g def env_file_flag(v, env) case v - when Array - v.collect.with_index { |v, i| "/var/vcap/jobs/worker-windows/config/env/#{env}_#{i}" }.join(",") when Hash v.collect { |k, v| "#{k}:/var/vcap/jobs/worker-windows/config/env/#{env}_#{k}" }.join(",") else @@ -70,8 +68,6 @@ $env:CONCOURSE_TSA_PUBLIC_KEY = "C:\var\vcap\jobs\worker-windows\config\worker_g def env_windows_file_flag(v, env) case v - when Array - v.collect.with_index { |v, i| "C:\\var\\vcap\\jobs\\worker-windows\\config\\env\\#{env}_#{i}" }.join(",") when Hash v.collect { |k, v| "#{k}:C:\\var\\vcap\\jobs\\worker-windows\\config\\env\\#{env}_#{k}" }.join(",") else diff --git a/jobs/worker/templates/env.sh.erb b/jobs/worker/templates/env.sh.erb index fd4fe53e5..5d50b95fb 100644 --- a/jobs/worker/templates/env.sh.erb +++ b/jobs/worker/templates/env.sh.erb @@ -42,8 +42,6 @@ export CONCOURSE_TSA_PUBLIC_KEY=/var/vcap/jobs/worker/config/worker_gateway_host def env_file_flag(v, env) case v - when Array - v.collect.with_index { |v, i| "/var/vcap/jobs/worker/config/env/#{env}_#{i}" }.join(",") when Hash v.collect { |k, v| "#{k}:/var/vcap/jobs/worker/config/env/#{env}_#{k}" }.join(",") else @@ -53,8 +51,6 @@ export CONCOURSE_TSA_PUBLIC_KEY=/var/vcap/jobs/worker/config/worker_gateway_host def env_windows_file_flag(v, env) case v - when Array - v.collect.with_index { |v, i| "C:\\var\\vcap\\jobs\\worker\\config\\env\\#{env}_#{i}" }.join(",") when Hash v.collect { |k, v| "#{k}:C:\\var\\vcap\\jobs\\worker\\config\\env\\#{env}_#{k}" }.join(",") else diff --git a/jobs/worker/templates/pre_start.erb b/jobs/worker/templates/pre_start.erb index beb10dee2..236b3761d 100644 --- a/jobs/worker/templates/pre_start.erb +++ b/jobs/worker/templates/pre_start.erb @@ -23,7 +23,7 @@ mkdir -p /var/vcap/jobs/worker/config/env def env_file_content(v) case v when Array - v.join("\n").chomp + "\n" + v.collect(&:chomp).join("\n").chomp + "\n" when String v.chomp + "\n" else @@ -35,18 +35,13 @@ mkdir -p /var/vcap/jobs/worker/config/env path = "/var/vcap/jobs/worker/config/env/#{env}" case v - when Array - v.collect.with_index do |v, i| - fn = "#{path}_#{i}" - "cat > #{fn} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(fn)}" - end.join("\n\n") when Hash v.collect do |k, v| fn = "#{path}_#{k}" "cat > #{fn} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(fn)}" end.join("\n\n") else - "cat > #{path} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(path)}\n" + "cat > #{path} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(path)}" end end -%> diff --git a/tmpl/create_env_files.erb.tmpl b/tmpl/create_env_files.erb.tmpl index a62040c75..0c89d1192 100644 --- a/tmpl/create_env_files.erb.tmpl +++ b/tmpl/create_env_files.erb.tmpl @@ -15,7 +15,7 @@ mkdir -p /var/vcap/jobs/{{.Name}}/config/env def env_file_content(v) case v when Array - v.join("\n").chomp + "\n" + v.collect(&:chomp).join("\n").chomp + "\n" when String v.chomp + "\n" else @@ -27,18 +27,13 @@ mkdir -p /var/vcap/jobs/{{.Name}}/config/env path = "/var/vcap/jobs/{{.Name}}/config/env/#{env}" case v - when Array - v.collect.with_index do |v, i| - fn = "#{path}_#{i}" - "cat > #{fn} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(fn)}" - end.join("\n\n") when Hash v.collect do |k, v| fn = "#{path}_#{k}" "cat > #{fn} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(fn)}" end.join("\n\n") else - "cat > #{path} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(path)}\n" + "cat > #{path} <<\"ENVGEN_EOF\"\n#{env_file_content(v)}ENVGEN_EOF\n#{env_file_perms(path)}" end end -%> diff --git a/tmpl/create_env_files_spec.rb b/tmpl/create_env_files_spec.rb index 769af3672..cb649817e 100755 --- a/tmpl/create_env_files_spec.rb +++ b/tmpl/create_env_files_spec.rb @@ -13,45 +13,27 @@ require "rspec" require "json" -describe "env_file_write" do +describe "env_file_writer" do context "Array" do let(:value) { [ - "bar", - ["quux", "quuux", "quuuux"], - { "grunt" => "gorp" }, + "foo", + "bar\n", # public_key variable attrs have a trailing linebreak + "baz", ] } let(:expected) { <<~EOS - cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv_0 <<"ENVGEN_EOF" + cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv <<"ENVGEN_EOF" + foo bar + baz ENVGEN_EOF if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then - chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv_0 - fi - chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv_0 - - - cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv_1 <<"ENVGEN_EOF" - quux - quuux - quuuux - ENVGEN_EOF - if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then - chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv_1 - fi - chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv_1 - - - cat > /var/vcap/jobs/{{.Name}}/config/env/MyEnv_2 <<"ENVGEN_EOF" - {"grunt":"gorp"} - ENVGEN_EOF - if [[ "${ENV_FILE_OWNER:-}" != "" ]] ; then - chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv_2 + chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv fi - chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv_2 + chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv EOS } it { expect(env_file_writer(value, "MyEnv")).to eq(expected) } @@ -112,7 +94,6 @@ chown ${ENV_FILE_OWNER}:${ENV_FILE_OWNER} /var/vcap/jobs/{{.Name}}/config/env/MyEnv fi chmod 0600 /var/vcap/jobs/{{.Name}}/config/env/MyEnv - EOS } it { expect(env_file_writer(value, "MyEnv")).to eq(expected) } diff --git a/tmpl/env_helpers.erb.tmpl b/tmpl/env_helpers.erb.tmpl index 848f6e825..adb299582 100644 --- a/tmpl/env_helpers.erb.tmpl +++ b/tmpl/env_helpers.erb.tmpl @@ -14,8 +14,6 @@ def env_file_flag(v, env) case v - when Array - v.collect.with_index { |v, i| "/var/vcap/jobs/{{.Name}}/config/env/#{env}_#{i}" }.join(",") when Hash v.collect { |k, v| "#{k}:/var/vcap/jobs/{{.Name}}/config/env/#{env}_#{k}" }.join(",") else @@ -25,8 +23,6 @@ def env_windows_file_flag(v, env) case v - when Array - v.collect.with_index { |v, i| "C:\\var\\vcap\\jobs\\{{.Name}}\\config\\env\\#{env}_#{i}" }.join(",") when Hash v.collect { |k, v| "#{k}:C:\\var\\vcap\\jobs\\{{.Name}}\\config\\env\\#{env}_#{k}" }.join(",") else