Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CC-1227] Capability to provide environment variables from dashboard #317

Open
wants to merge 1 commit into
base: next-release
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion cookbooks/env_vars/libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ def fetch_environment_variables(app_data)
return [] unless metadata && metadata['environment_variables']

variables = metadata['environment_variables'].map do |var_hash|
{ :name => var_hash['name'], :value => ::Base64.strict_decode64(var_hash['value']) }
if variable_validator(var_hash[:name])
{ :name => var_hash['name'], :value => escape_variable_value(::Base64.strict_decode64(var_hash['value'])).delete!("\n") }
else
Chef::Log.error('[COOKBOOK ENV_VARS] Variable name is not valid')
end
end
end

# Function for variable name validation
def variable_validator(name)
!!name.match(/\A[a-zA-Z]\w*\z/)
end

# Escapes the value of variable to be correctly enclosed in double quotes. Enclosing characters
# in double quotes (") preserves the literal value of all characters within the quotes, with the
# exception of $, `, \, and, when history expansion is enabled, !.
Expand Down
6 changes: 3 additions & 3 deletions cookbooks/env_vars/templates/default/env.cloud.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<% @environment_variables.each do |variable| %>
export <%= variable[:name] %>="<%= escape_variable_value(variable[:value]) %>"
<% end %>
<% @environment_variables.each do |variable| -%>
export <%=variable[:name]%>="<%= variable[:value] %>"
<% end -%>