Skip to content

Instantly share code, notes, and snippets.

@ls-rajan-rauniyar
Last active October 2, 2018 06:53
Show Gist options
  • Save ls-rajan-rauniyar/6e3ab5b021301ef4f5caafdc9a0a5bf3 to your computer and use it in GitHub Desktop.
Save ls-rajan-rauniyar/6e3ab5b021301ef4f5caafdc9a0a5bf3 to your computer and use it in GitHub Desktop.
#!/bin/bash
looker_client_id="${LOOKER_CLIENT_ID:-""}"
looker_client_secret="${LOOKER_CLIENT_SECRET:-""}"
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
printf "\n"
if [[ ${looker_client_id} == "" ]]; then
printf "${RED} Failed: Looker client Id is not set. ${NC} \n"
exit
else
printf "${GREEN} Using client Id ${looker_client_id} ${NC} \n"
fi
if [[ ${looker_client_secret} == "" ]]; then
printf "${RED} Failed: Looker client secret is not set. ${NC} \n"
exit
else
printf "${GREEN} Using client secret ${looker_client_secret} ${NC} \n"
fi
rm -rf /tmp/looker && mkdir /tmp/looker && cd /tmp/looker
# Get access token from looker for API calls
printf "\n${GREEN} https://kountastaging.au.looker.com:19999/api/3.0/login?client_id=${looker_client_id}&client_secret=${looker_client_secret} ${NC} \n"
accessToken="$(curl -s --request POST \
--url "https://kountastaging.au.looker.com:19999/api/3.0/login?client_id=${looker_client_id}&client_secret=${looker_client_secret}" \
--header 'Cache-Control: no-cache' | jq -r '.access_token')"
if [ -z "$accessToken" ]; then
printf "${RED} Could not get access token ${NC} \n"
exit
else
printf "${GREEN} Got access token ${accessToken} ${NC} \n"
fi
# grab all space ids
spaces="$(curl --request GET \
--url 'https://kountastaging.au.looker.com:19999/api/3.0/spaces?fields=id' \
--header "Authorization: Bearer ${accessToken}" \
--header 'Cache-Control: no-cache' | jq -r ".[] | .id")"
echo $spaces
for i in $spaces ; do
# space with id 1 is shared space
# Fixme: Remove hardcoded filter for 6
if [[ ${i} != "lookml" && ${i} != 1 && ${i} == 6 ]]; then
printf "\n${GREEN}exporting space with Id ${i} using gazer \n\n"
# store dashboard json in /tmp/looker
gzr space export $i --host kountastaging.au.looker.com --client-id ${looker_client_id} --client-secret ${looker_client_secret} --debug --dir /tmp/looker/
# loop thru each json file and replace site name and company name
for jsonFile in /tmp/looker/*/*.json; do
filename=$(basename "$jsonFile")
printf " ${CYAN}$filename --> $jsonFile{$NC}\n"
sed -i "" "s/salelines\.site_name/site\.company_name/g" "${jsonFile}"
sed -i "" "s/revenue\.site_name/site\.company_name/g" "${jsonFile}"
sed -i "" "s/salelines\.company_name/company\.company_name/g" "${jsonFile}"
sed -i "" "s/revenue\.company_name/company\.company_name/g" "${jsonFile}"
# Fixme: Remove hardcoded filter for 6
if [[ ${i} == 6 ]]; then
gzr dashboard import "${jsonFile}" ${i} --host kountastaging.au.looker.com --client-id ${looker_client_id} --client-secret ${looker_client_secret} --debug --force
fi
done
rm -rf /tmp/looker && mkdir /tmp/looker && cd /tmp/looker
fi
done
#gzr space export 1 --host kountastaging.au.looker.com --client-id ${looker_client_id} --client-secret ${looker_client_secret} --debug --dir /tmp/looker/
printf "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment