From 9780162eaa747b2aae800a9a8271c792d783ec5a Mon Sep 17 00:00:00 2001 From: Benjamin Sherriff Date: Mon, 23 Dec 2024 08:41:32 -0500 Subject: [PATCH] Added api key script --- .env | 4 ++++ Makefile | 5 ++++- bruno/dice/Track.bru | 2 +- scripts/insert_api_key.sh | 22 ++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 scripts/insert_api_key.sh diff --git a/.env b/.env index eb2e8a8..73e8099 100644 --- a/.env +++ b/.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= diff --git a/Makefile b/Makefile index 9a4834a..eee52aa 100644 --- a/Makefile +++ b/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 \ No newline at end of file + @$(ENV) docker exec -it siren-postgres psql -U ${DATABASE_USER} -P pager=off + +insert-api: + @$(ENV) ./scripts/insert_api_key.sh \ No newline at end of file diff --git a/bruno/dice/Track.bru b/bruno/dice/Track.bru index 9fdcde1..0a5558b 100644 --- a/bruno/dice/Track.bru +++ b/bruno/dice/Track.bru @@ -12,6 +12,6 @@ post { body:json { { - "dice": "1d4" + "dice": "1d6" } } diff --git a/scripts/insert_api_key.sh b/scripts/insert_api_key.sh new file mode 100755 index 0000000..4ea4a3a --- /dev/null +++ b/scripts/insert_api_key.sh @@ -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!" \ No newline at end of file