Skip to content

Commit

Permalink
Allow supervisord environment vars to have "=" (ddollar#572)
Browse files Browse the repository at this point in the history
Prior to this PR, an environment variable configured for use with Foreman could not contain a `?`, `=` or `&` (common in URLs) if the target configuration was set to SupervisorD. This PR cleans up the output from `Shellwords.escape` in order to be ready for use in a `app*.conf` file. I've updated the tests to cover this particular issue.

Fixes ddollar#571
Fixes ddollar#519

/cc @inbeom, @ddollar
  • Loading branch information
stephenyeargin authored and ddollar committed Apr 23, 2016
1 parent 0f57247 commit 812f38e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion data/export/supervisord/app.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ engine.each_process do |name, process|
port = engine.port_for(process, num)
full_name = "#{app}-#{name}-#{num}"
environment = engine.env.merge("PORT" => port.to_s).map do |key, value|
"#{key}=\"#{shell_quote(value)}\""
value = shell_quote(value)
value = value.gsub('\=', '=')
value = value.gsub('\&', '&')
value = value.gsub('\?', '?')
"#{key}=\"#{value}\""
end
app_names << full_name
-%>
Expand Down
2 changes: 2 additions & 0 deletions spec/foreman/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,14 @@ def shutdown
f.puts 'BAZ="qux"'
f.puts "FRED='barney'"
f.puts 'OTHER="escaped\"quote"'
f.puts 'URL="http://example.com/api?foo=bar&baz=1"'
end
subject.load_env "/tmp/env"
expect(subject.env["FOO"]).to eq("bar")
expect(subject.env["BAZ"]).to eq("qux")
expect(subject.env["FRED"]).to eq("barney")
expect(subject.env["OTHER"]).to eq('escaped"quote')
expect(subject.env["URL"]).to eq("http://example.com/api?foo=bar&baz=1")
end

it "should handle multiline strings" do
Expand Down
2 changes: 2 additions & 0 deletions spec/foreman/export/supervisord_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
before(:each) { stub(supervisord).say }

it "exports to the filesystem" do
write_env(".env", "FOO"=>"bar", "URL"=>"http://example.com/api?foo=bar&baz=1")
supervisord.engine.load_env('.env')
supervisord.export
expect(File.read("/tmp/init/app.conf")).to eq(example_export_file("supervisord/app-alpha-1.conf"))
end
Expand Down
8 changes: 4 additions & 4 deletions spec/resources/export/supervisord/app-alpha-1.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stdout_logfile=/var/log/app/alpha-1.log
stderr_logfile=/var/log/app/alpha-1.error.log
user=app
directory=/tmp/app
environment=PORT="5000"
environment=FOO="bar",URL="http://example.com/api?foo=bar&baz=1",PORT="5000"

[program:app-bravo-1]
command=./bravo
Expand All @@ -18,7 +18,7 @@ stdout_logfile=/var/log/app/bravo-1.log
stderr_logfile=/var/log/app/bravo-1.error.log
user=app
directory=/tmp/app
environment=PORT="5100"
environment=FOO="bar",URL="http://example.com/api?foo=bar&baz=1",PORT="5100"

[program:app-foo_bar-1]
command=./foo_bar
Expand All @@ -29,7 +29,7 @@ stdout_logfile=/var/log/app/foo_bar-1.log
stderr_logfile=/var/log/app/foo_bar-1.error.log
user=app
directory=/tmp/app
environment=PORT="5200"
environment=FOO="bar",URL="http://example.com/api?foo=bar&baz=1",PORT="5200"

[program:app-foo-bar-1]
command=./foo-bar
Expand All @@ -40,7 +40,7 @@ stdout_logfile=/var/log/app/foo-bar-1.log
stderr_logfile=/var/log/app/foo-bar-1.error.log
user=app
directory=/tmp/app
environment=PORT="5300"
environment=FOO="bar",URL="http://example.com/api?foo=bar&baz=1",PORT="5300"

[group:app]
programs=app-alpha-1,app-bravo-1,app-foo_bar-1,app-foo-bar-1

0 comments on commit 812f38e

Please sign in to comment.