Skip to content

Commit

Permalink
chore(node): normalize config.sh to return empty string (#3502)
Browse files Browse the repository at this point in the history
normalize config.sh get_config_value:
- If key not found or value is "null", returns empty string. Otherwise,
returns value
  • Loading branch information
andrewbattat authored Jan 27, 2025
1 parent 048d528 commit 0626768
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 11 additions & 2 deletions ic-os/components/misc/config/setupos/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
# Retrieves a value from the config.json file using a JSON path.
# Arguments:
# $1 - JSON path to the desired value (e.g., '.icos_settings.nns_urls')
# Note: If the key is not found, this function will return null.
# Returns:
# If key is not found or value is "null", returns empty string.
# Otherwise, returns value.
function get_config_value() {
local CONFIG_FILE="/var/ic/config/config.json"
local key=$1
jq -r "${key}" "${CONFIG_FILE}"

local value=$(jq -r "${key}" "${CONFIG_FILE}")

if [[ "${value}" == "null" ]]; then
echo ""
else
echo "${value}"
fi
}
13 changes: 5 additions & 8 deletions ic-os/components/setupos-scripts/check-network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,13 @@ function print_network_settings() {
echo "* Printing user defined network settings..."
echo " IPv6 Prefix : ${ipv6_prefix}"
echo " IPv6 Gateway: ${ipv6_gateway}"
if [[ -n ${ipv4_address} && "${ipv4_address}" != "null" &&
-n ${ipv4_prefix_length} && "${ipv4_prefix_length}" != "null" &&
-n ${ipv4_gateway} && "${ipv4_gateway}" != "null" ]]; then

if [[ -n ${ipv4_address} && -n ${ipv4_prefix_length} && -n ${ipv4_gateway} ]]; then
echo " IPv4 Address: ${ipv4_address}"
echo " IPv4 Prefix Length: ${ipv4_prefix_length}"
echo " IPv4 Gateway: ${ipv4_gateway}"
fi
if [[ -n ${domain_name} && "${domain_name}" != "null" ]]; then
if [[ -n ${domain_name} ]]; then
echo " Domain name: ${domain_name}"
fi
echo " "
Expand Down Expand Up @@ -214,13 +213,11 @@ main() {
get_network_settings
print_network_settings

if [[ -n ${domain_name} && "${domain_name}" != "null" ]]; then
if [[ -n ${domain_name} ]]; then
validate_domain_name
fi

if [[ -n ${ipv4_address} && "${ipv4_address}" != "null" &&
-n ${ipv4_prefix_length} && "${ipv4_prefix_length}" != "null" &&
-n ${ipv4_gateway} && "${ipv4_gateway}" != "null" ]]; then
if [[ -n ${ipv4_address} && -n ${ipv4_prefix_length} && -n ${ipv4_gateway} ]]; then
setup_ipv4_network
ping_ipv4_gateway
fi
Expand Down

0 comments on commit 0626768

Please sign in to comment.