-
Notifications
You must be signed in to change notification settings - Fork 27
/
azure_container_upgradation_validate.sh
121 lines (104 loc) · 3.5 KB
/
azure_container_upgradation_validate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
check_az_key(){
az_key_status=0
export AZURE_STORAGE_CONNECTION_STRING="$1"
az storage container list --account-name $azure_account_name --account-key $azure_account_key > /dev/null 2>&1
if [ ! $? -eq 0 ]; then echo "Error - Invalid az account key"; fail=1
az_key_status=1
fi
}
check_az_storage_account_name(){
az_account_status=0
export AZURE_STORAGE_CONNECTION_STRING="$1"
az storage container list --account-name $azure_account_name > /dev/null 2>&1
if [ ! $? -eq 0 ]; then echo "Error - Invalid az account name"; fail=1
az_account_status=1
fi
}
check_az_container(){
if [[ -e "$base_dir/cqube/.cqube_config" ]]; then
az_container=$(cat $base_dir/cqube/.cqube_config | grep $3 )
az_container_name=$(cut -d "=" -f2 <<< "$az_container")
if [[ ! "$2" == "$az_container_name" ]]; then
echo "Error - $1 must be same as previously used container"; fail=1
fi
fi
}
get_azure_container_config_values(){
key=$1
vals[$key]=$(awk ''/^$key:' /{ if ($2 !~ /#.*/) {print $2}}' azure_container_config.yml)
}
bold=$(tput bold)
normal=$(tput sgr0)
fail=0
if [[ ! $# -eq 0 ]]; then
core_install=$1
else
core_install="NA"
fi
echo -e "\e[0;33m${bold}Validating the azure_container_config file...${normal}"
# An array of mandatory values
declare -a arr=("azure_account_name" "azure_account_key" "azure_input_container" "azure_output_container" "azure_emission_container")
# Create and empty array which will store the key and value pair from config file
declare -A vals
# Getting aws keys
azure_account_name=$(awk ''/^azure_account_name:' /{ if ($2 !~ /#.*/) {print $2}}' azure_container_config.yml)
azure_account_key=$(awk ''/^azure_account_key:' /{ if ($2 !~ /#.*/) {print $2}}' azure_container_config.yml)
# Iterate the array and retrieve values for mandatory fields from config file
for i in ${arr[@]}
do
get_azure_container_config_values $i
done
for i in ${arr[@]}
do
key=$i
value=${vals[$key]}
case $key in
azure_account_name)
if [[ $value == "" ]]; then
echo "Error - in $key. Unable to get the value. Please check."; fail=1
#else
# check_az_storage_account_name $key $value
fi
;;
azure_account_key)
if [[ $value == "" ]]; then
echo "Error - in $key. Unable to get the value. Please check."; fail=1
else
check_az_key $key $value
fi
;;
azure_input_container)
if [[ $value == "" ]]; then
echo "Error - in $key. Unable to get the value. Please check."; fail=1
else
check_az_container $key $value "AZURE_INPUT_STORAGE"
fi
;;
azure_output_container)
if [[ $value == "" ]]; then
echo "Error - in $key. Unable to get the value. Please check."; fail=1
else
check_az_container $key $value "AZURE_OUTPUT_STORAGE"
fi
;;
azure_emission_container)
if [[ $value == "" ]]; then
echo "Error - in $key. Unable to get the value. Please check."; fail=1
else
check_az_container $key $value "AZURE_EMISSION_STORAGE"
fi
;;
*)
if [[ $value == "" ]]; then
echo -e "\e[0;31m${bold}Error - Value for $key cannot be empty. Please fill this value${normal}"; fail=1
fi
;;
esac
done
if [[ $fail -eq 1 ]]; then
echo -e "\e[0;34m${bold}azure_container_Config file has errors. Please rectify the issues and restart the installation${normal}"
exit 1
else
echo -e "\e[0;32m${bold}azure_container_Config file successfully validated${normal}"
fi