Files
wevads-platform/scripts/config-api-keys.sh
2026-02-26 04:53:11 +01:00

93 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
# Quick API Keys Configuration
PSQL="psql -U admin -d adx_system -t -c"
echo "============================================"
echo "🔑 DELIVERADS API KEYS CONFIGURATION"
echo "============================================"
echo ""
# Function to set key
set_key() {
provider=$1
category=$2
api_key=$3
api_secret=$4
$PSQL "INSERT INTO admin.api_keys (provider, category, api_key, api_secret) VALUES ('$provider', '$category', '$api_key', '$api_secret') ON CONFLICT (provider) DO UPDATE SET api_key = '$api_key', api_secret = '$api_secret', updated_at = NOW();"
echo "$provider configured"
}
# Check arguments
case "$1" in
huawei)
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 huawei <AK> <SK> [region]"
exit 1
fi
set_key "Huawei" "cloud" "$2" "$3"
# Also add to huawei_accounts
region=${4:-"af-south-1"}
$PSQL "INSERT INTO admin.huawei_accounts (name, ak, sk, region, is_active) VALUES ('Main', '$2', '$3', '$region', true) ON CONFLICT DO NOTHING;"
echo " Region: $region"
;;
scaleway)
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 scaleway <API_KEY> <ORG_ID>"
exit 1
fi
set_key "Scaleway" "cloud" "$2" "$3"
$PSQL "INSERT INTO admin.scaleway_accounts (name, api_key, organization_id, is_active) VALUES ('Main', '$2', '$3', true) ON CONFLICT DO NOTHING;"
;;
ai)
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 ai <PROVIDER> <API_KEY>"
echo "Providers: groq, cerebras, deepseek, mistral, openai, claude, gemini, cohere"
exit 1
fi
provider=$(echo "$2" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}')
set_key "$provider" "ai" "$3" ""
# Update hamid_providers
$PSQL "UPDATE admin.hamid_providers SET api_key = '$3' WHERE LOWER(name) = LOWER('$2');"
;;
telegram)
if [ -z "$2" ] || [ -z "$3" ]; then
echo "Usage: $0 telegram <BOT_TOKEN> <CHAT_ID>"
exit 1
fi
set_key "Telegram" "notification" "$2" "$3"
$PSQL "INSERT INTO admin.telegram_config (bot_token, chat_id, is_active) VALUES ('$2', '$3', true) ON CONFLICT DO NOTHING;"
;;
cloudflare)
if [ -z "$2" ]; then
echo "Usage: $0 cloudflare <API_TOKEN>"
exit 1
fi
set_key "Cloudflare" "dns" "$2" ""
;;
list)
echo "Configured API Keys:"
$PSQL "SELECT provider, category, CASE WHEN api_key IS NOT NULL AND api_key != '' THEN '✓ Configured' ELSE '✗ Missing' END as status FROM admin.api_keys ORDER BY category, provider;"
;;
*)
echo "Usage: $0 <command> [args]"
echo ""
echo "Commands:"
echo " huawei <AK> <SK> [region] - Configure Huawei Cloud"
echo " scaleway <API_KEY> <ORG_ID> - Configure Scaleway"
echo " ai <provider> <API_KEY> - Configure AI provider"
echo " telegram <TOKEN> <CHAT_ID> - Configure Telegram alerts"
echo " cloudflare <API_TOKEN> - Configure Cloudflare"
echo " list - Show configured keys"
echo ""
echo "AI Providers: groq, cerebras, deepseek, mistral, openai, claude, gemini, cohere"
;;
esac