Skip to content

Commit fdc12eb

Browse files
authored
Merge pull request #187 from MsysTechnologiesllc/harry/parse-env-var
add python script to parse env variables
2 parents c5ea48b + b6e3ddd commit fdc12eb

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import json
2+
import sys
3+
with open(sys.argv[1]) as data_file:
4+
data = json.load(data_file, strict=False)
5+
data = data['runtimeSettings'][0]['handlerSettings']['publicSettings']['environment_variables']
6+
commands=""
7+
for key, value in data.items():
8+
commands=commands+'export '+key+'="'+value+'";'
9+
print commands

ChefExtensionHandler/bin/shared.sh

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,29 @@ get_config_settings_file() {
2121
echo $config_file_name
2222
}
2323

24-
extract_environment_variables_list() {
25-
env_vars_list=$(sed ':a;N;$!ba;s/\n//g' $1 | tr -d ' ' | sed 's/.*environment_variables":{\(.*\)}/\1/g' | awk -F\} '{print $1}' | awk '{n=split($0,arr,",");for(i=1;i<=n;i++) print arr[i]}')
26-
27-
echo $env_vars_list
24+
get_file_path_to_parse_env_variables(){
25+
path_to_parse_env_variables="$1/bin/parse_env_variables.py"
26+
echo $path_to_parse_env_variables
2827
}
2928

3029
export_env_vars() {
31-
eval "export $1=$2"
30+
commands="`python $path_to_parse_env_variables \"$1\"`"
31+
eval $commands
3232
}
3333

3434
read_environment_variables(){
3535
echo "[$(date)] Reading environment variables"
3636
config_file_name=$(get_config_settings_file $1)
37+
path_to_parse_env_variables=$(get_file_path_to_parse_env_variables $1)
3738

3839
if [ -z "$config_file_name" ]; then
3940
echo "Configuration error. Azure chef extension's config/settings file missing."
4041
exit 1
4142
else
4243
if cat $config_file_name 2>/dev/null | grep -q "environment_variables"; then
43-
env_vars_list=$(extract_environment_variables_list $config_file_name)
44-
45-
for i in $env_vars_list
46-
do
47-
env_var_name=$(echo $i | awk -F':' '{print $1}')
48-
env_var_value=$(echo $i | awk -F':' '{OFS=":";$1="";print $0}' | sed 's/^:*//g;s/^ *//g;s/ *$//g')
49-
export_env_vars $env_var_name $env_var_value
50-
done
44+
export_env_vars $config_file_name
5145
echo "[$(date)] Environment variables read operation completed"
46+
echo "`env`"
5247
else
5348
echo "[$(date)] No environment variables found"
5449
fi

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ PESTER_SANDBOX = './PESTER_SANDBOX'
2525
LINUX_PACKAGE_LIST = [
2626
{"ChefExtensionHandler/*.sh" => "#{CHEF_BUILD_DIR}/"},
2727
{"ChefExtensionHandler/bin/*.sh" => "#{CHEF_BUILD_DIR}/bin"},
28+
{"ChefExtensionHandler/bin/*.py" => "#{CHEF_BUILD_DIR}/bin"},
2829
{"ChefExtensionHandler/bin/*.rb" => "#{CHEF_BUILD_DIR}/bin"},
2930
{"ChefExtensionHandler/bin/chef-client" => "#{CHEF_BUILD_DIR}/bin"},
3031
{"*.gem" => "#{CHEF_BUILD_DIR}/gems"},

0 commit comments

Comments
 (0)