Created
June 13, 2020 02:17
-
-
Save Wind010/77c0e99094cf5750029063d7f64ef12a to your computer and use it in GitHub Desktop.
Used to replace exported Apigee proxy with expected pipeline tokens. Can be a pre-commit githook.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash. | |
# Author: wind.TWD@gmail.com | |
# Description: Used to replace exported Apigee proxy with expected pipeline tokens. Can be a pre-commit githook. | |
# Notes: | |
# Generally I wouldn't parse XML/HTML with regex, use xmlstarlet, but whatever. | |
# Can run the commands without the -i to test. | |
blue="\e[104m" | |
normal=$(tput sgr0) | |
proxy_name="PROXY_NAME" | |
# Remove manifest directory | |
rm -rf ./manifests | |
# Validate that script is referencing correct directory. | |
shopt -s nocasematch | |
if [[ ${PWD##*/} != "apiproxy" ]] | |
then | |
echo "Expected root directory to be 'apiproxy', but found '${PWD##*/}'." | |
fi | |
# See if only the root APIProxy xml exists. | |
fileCount=$(find . -mindepth 1 -maxdepth 1 -type f -name "*.xml" -printf x | wc -c) | |
if [ "$fileCount" = "0" ] | |
then | |
echo "Found '${fileCount}' XML files in this directory. Expected only one." | |
exit 1 | |
fi | |
# Rename the root XLML File. | |
apiProxyXmlWithEnv=$(find . -mindepth 1 -maxdepth 1 -type f -name "*.xml") | |
apiProxyXmlFileName=$(echo $apiProxyXmlWithEnv | sed -e "s/-test.*\.xml/.xml/g") | |
mv $apiProxyXmlWithEnv $apiProxyXmlFileName | |
printf "\n\n${blue}Renamed '${apiProxyXmlWithEnv}' to '${apiProxyXmlFileName}'${normal}\n\n" | |
# Update APIProxy | |
printf "\n\n${blue}Updating '${apiProxyXmlFileName}'...${normal}\n\n" | |
sed -i -e 's/\(^<APIProxy *revision="[[:digit:]]*" *name\)="[^"]*"/\1="'${proxy_name}'"/' $apiProxyXmlFileName; | |
sed -i -e ':a;N;$!ba; s|<Basepaths>.*<\/Basepaths>|<Basepaths>/'${proxy_name}'<Basepaths\/>|g' $apiProxyXmlFileName; | |
sed -i -e ':a;N;$!ba; s|<DisplayName>.*<\/DisplayName>|<DisplayName>'${proxy_name}'<DisplayName\/>|g' $apiProxyXmlFileName; | |
sed -i -e ':a;N;$!ba; s|<Description>.*<\/Description>|<Description>DEPLOYMENT_DESCRIPTION<Description\/>|g' $apiProxyXmlFileName; | |
sed -i -e '/<ManifestVersion>/d' $apiProxyXmlFileName; | |
# Could possibly use: sed -i -se 's|foo|bar|g' proxies/*.xml | |
# Update ProxiesEndpoints | |
printf "\n\n${blue}Updating proxies...${normal}\n\n" | |
find ./proxies -name '*.xml' \ | |
-exec sed -i -e ':a;N;$!ba; s|<VirtualHost>.*<\/VirtualHost>|<VirtualHost>VIRTUALHOST_VALUE<VirtualHost\/>|g' {} \; | |
# Update Targets | |
printf "\n\n${blue}Updating targets...${normal}\n\n" | |
find ./targets -name '*.xml' \ | |
-exec sed -i -e 's/\(<Server *name\)="[^"]*"/\1="secureDEPLOYMENT_SUFFIX"/' {} \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment