Added api key script
This commit is contained in:
4
.env
4
.env
@@ -31,3 +31,7 @@ DATA_DIR_PATH= # Optional
|
||||
OPENAI_TOKEN= # Optional
|
||||
OPENAI_BASE_URL=https://api.openai.com/v1
|
||||
OPENAI_MODEL=gpt-4o-mini
|
||||
|
||||
DEFAULT_API_KEY=test_api_key
|
||||
DEFAULT_SERVER=
|
||||
DEFAULT_USER=
|
||||
|
||||
5
Makefile
5
Makefile
@@ -53,4 +53,7 @@ docker-clean: ## Stop the docker containers and remove volumes
|
||||
docker-refresh: docker-clean backend-up ## Refresh the docker containers
|
||||
|
||||
psql: ## Connect to the database
|
||||
@$(ENV) docker exec -it siren-postgres psql -U ${DATABASE_USER} -P pager=off
|
||||
@$(ENV) docker exec -it siren-postgres psql -U ${DATABASE_USER} -P pager=off
|
||||
|
||||
insert-api:
|
||||
@$(ENV) ./scripts/insert_api_key.sh
|
||||
@@ -12,6 +12,6 @@ post {
|
||||
|
||||
body:json {
|
||||
{
|
||||
"dice": "1d4"
|
||||
"dice": "1d6"
|
||||
}
|
||||
}
|
||||
|
||||
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