Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

xml file content replacement form variable value #251

Open
vivuu1989 opened this issue Feb 11, 2024 · 0 comments
Open

xml file content replacement form variable value #251

vivuu1989 opened this issue Feb 11, 2024 · 0 comments

Comments

@vivuu1989
Copy link

it seems its very complex to insert xml content variable from shell script to a specific portion of xml based on the condition which satisfying

I have followed many threads in internet and couldn't find any solution to fulfill my requirement here.

HEADER=$(cat <<EOF
<policies>
EOF)

FOOTER==$(cat <<EOF
</policies>
EOF)
IN_IP_FILTER=$(cat <<EOF
    <inbound>
        <base />
        <ip-filter action="allow">
            <address-range from="$ipAddressesFrom" to="$ipAddressesTo" />
        </ip-filter>
    </inbound>
EOF)

################Variables##################
source parse_yaml.sh
eval $(parse_yaml sample2.yaml policy)

echo ".............Eval Result..............................."
for f in $policy_ ; do eval echo \$f \$${f}_ ; done
echo "............Eval Result................................"
echo " ********policy is ************ "
echo "{$IP_FILTER}"

for f in $policy_ ; do
  if [[ $(eval echo \$${f}_name) == "ipfilter" ]]; then
    echo " given policy name is ipfilter "
    for g in $(eval echo \$${f}_session_); do
      if [[ $(eval echo \$${g}) == "inbound" ]]; then
      echo "add the add above Ipfilter string to the inbound session of xml"
      echo "${HEADER}" >> result_$(eval echo \$${f}_name).xml
      echo "${IN_IP_FILTER}" >> result_$(eval echo \$${f}_name).xml
      fi
      if [[ $(eval echo \$${g}) == "outbound" ]]; then
      echo "add the add above Ipfilter string to the outbound session of xml"
      fi
      if [[ $(eval echo \$${g}) == "backend" ]]; then
      echo "add the add above Ipfilter string to the backend session of xml"
      fi
    done

The file which need to customized based on the condition is as below , but need to replace only the content which is satisfying from the condition.

<policies>
    <inbound>
        <base />
		 $(ip_filter)
         $(rate-limit-by_ip)
		 $(rate-limit-by_subkey)
		 $(rate-limit-by_DevID)
		 $(rate-limit-by_ip)+$(rate-limit-by_DevID)
    </inbound>
    <backend>
        <base />
		 $(ip_filter)
         $(rate-limit-by_ip)
		 $(rate-limit-by_subkey)
		 $(rate-limit-by_DevID)
		 $(rate-limit-by_ip)+$(rate-limit-by_DevID)
    </backend>
    <outbound>
        <base />
		 $(ip_filter)
         $(rate-limit-by_ip)
		 $(rate-limit-by_subkey)
		 $(rate-limit-by_DevID)
		 $(rate-limit-by_ip)+$(rate-limit-by_DevID)
    </outbound>
    <on-error>
        <base />
		 $(rate-limit-by-ip_error)
		 $(rate-limit-by_DevID_error) 
    </on-error>
</policies>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant