Added api key script
This commit is contained in:
22
scripts/insert_api_key.sh
Executable file
22
scripts/insert_api_key.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Ensure required environment variables are set
|
||||
if [[ -z "$DATABASE_HOST" || -z "$DATABASE_PORT" || -z "$DATABASE_USER" || -z "$DATABASE_PASSWORD" || -z "$DATABASE_NAME" ]]; then
|
||||
echo "Error: One or more required environment variables are not set."
|
||||
echo "Required variables: DATABASE_HOST, DATABASE_PORT, DATABASE_USER, DATABASE_PASSWORD, DATABASE_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run the SQL query
|
||||
SQL_QUERY="insert into api_keys (key, user_id, user_name, access_mask, created_at) values (
|
||||
'$DEFAULT_API_KEY',
|
||||
$DEFAULT_SERVER,
|
||||
'$DEFAULT_USER',
|
||||
0,
|
||||
now()
|
||||
);"
|
||||
|
||||
# Execute the query using psql
|
||||
PGPASSWORD="$DATABASE_PASSWORD" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" -d "$DATABASE_NAME" -c "$SQL_QUERY"
|
||||
|
||||
echo "Insert completed successfully!"
|
||||
Reference in New Issue
Block a user