Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FWF-3730:- Script to support Single domain installation by auto retrieving redash api key. #145

Merged
merged 21 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions scripts/get_redash_api_key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Ensure namespace is provided
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 <namespace> <domain_name> <analytics_subdomain>"
exit 1
fi

NAMESPACE="$1"
DOMAIN_NAME="$2"
ANALYTICS_SUBDOMAIN="$3"

# Check if forms-flow-analytics is installed
if helm status "forms-flow-analytics" -n "$NAMESPACE" > /dev/null 2>&1; then
echo "forms-flow-analytics is already installed."
else
echo "forms-flow-analytics does not exist. Installing now."
helm install "forms-flow-analytics" ./forms-flow-analytics-chart -n "$NAMESPACE"
fi

REDASH_URL="https://$ANALYTICS_SUBDOMAIN-$NAMESPACE.$DOMAIN_NAME/redash"

# Prompt for credentials
echo "Redash URL: $REDASH_URL"
read -p "Enter your Redash username: " USERNAME
read -s -p "Enter your Redash password: " PASSWORD
echo

# Authenticate and retrieve API key
LOGIN_RESPONSE=$(curl -s -X POST "$REDASH_URL/login" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "email=$USERNAME" \
--data-urlencode "password=$PASSWORD" \
-c cookies.txt)

if ! echo "$LOGIN_RESPONSE" | grep -q 'Redirecting'; then
echo "Login failed! Verify your credentials or URL."
rm cookies.txt
exit 1
fi

API_RESPONSE=$(curl -s -X GET "$REDASH_URL/api/users/me" -b cookies.txt)
API_KEY=$(echo "$API_RESPONSE" | jq -r '.api_key')

if [ -z "$API_KEY" ]; then
echo "Failed to retrieve API key!"
rm cookies.txt
exit 1
fi

echo "Redash API Key: $API_KEY"

# Cleanup
rm cookies.txt
Loading
Loading