Skip to content

Instantly share code, notes, and snippets.

@markcurtis1970
Created November 7, 2022 17:13
Show Gist options
  • Save markcurtis1970/5799b0ff105a33306000b2f9f4fb4aaa to your computer and use it in GitHub Desktop.
Save markcurtis1970/5799b0ff105a33306000b2f9f4fb4aaa to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# For connecting to the DremioREST API
# Getting a list of Catalogs and then
# doing some other things with it
# https://docs.dremio.com/rest-api/catalog/get-catalog/
function check_creds {
if [ $DREMIO_USER"x" = "x" ] || [ $DREMIO_PASS"x" = "x" ]
then
echo "Please ensure DREMIO_USER and DREMIO_PASS are both set"
fi
}
function login {
RESP=$(curl -s -H "Content-Type: application/json" -X POST "$TARGET/apiv2/login" \
-d '{
"userName":"'$DREMIO_USER'",
"password":"'$DREMIO_PASS'"
}' \
)
TOKEN=$(echo $RESP | jq -r '.token')
}
function output {
echo -e "\nRun a curl to get all catalog objects\n"
echo "curl -s -H 'Content-Type: application/json' -H \"Authorization: _dremio$TOKEN\" -X GET \"$TARGET/api/v3/catalog?pretty\""
curl -s -H 'Content-Type: application/json' -H "Authorization: _dremio$TOKEN" -X GET "$TARGET/api/v3/catalog?pretty"
}
# Setup
RESP=""
TOKEN=""
TARGET=$1
# Run
check_creds
login
output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment