kych

OAuth 2.0 API for Swiyu to enable Taler integration of Swiyu for KYC (experimental)
Log | Files | Refs

commit 176308aa56ee13ecd22325f5a9af22ad231d2a45
parent a5436336f53f8c1dc8951e0269e926571374bb51
Author: Henrique Chan Carvalho Machado <henriqueccmachado@tecnico.ulisboa.pt>
Date:   Tue, 25 Nov 2025 22:35:30 +0100

oauth2_gateway: move db un/install scripts

Diffstat:
Moauth2_gateway/Cargo.toml | 3+--
Aoauth2_gateway/oauth2_gatewaydb/install_db.sh | 33+++++++++++++++++++++++++++++++++
Aoauth2_gateway/oauth2_gatewaydb/uninstall_db.sh | 7+++++++
3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/oauth2_gateway/Cargo.toml b/oauth2_gateway/Cargo.toml @@ -63,4 +63,4 @@ sqlx = { version = "0.8", features = ["runtime-tokio", "postgres", "uuid", "chro [dev-dependencies] tempfile = "3.8" wiremock = "0.6" -serial_test = "3.2.0" -\ No newline at end of file +serial_test = "3.2.0" diff --git a/oauth2_gateway/oauth2_gatewaydb/install_db.sh b/oauth2_gateway/oauth2_gatewaydb/install_db.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# install/setup the database of the oauth2_gateway with this script + +if [ -f .env ]; then + export $(grep -v '^#' .env | xargs) +else + echo ".env file not found" + echo "" + echo "Using default DB config" + echo "" +fi + +DB_PORT=${DB_PORT:-5432} +DB_NAME=${DB_NAME:-oauth2gw} +DB_USER=${DB_USER:-oauth2gw} +DB_PASS=${DB_PASS:-password} + +psql -d postgres -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASS';" +psql -d postgres -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;" + +psql -d $DB_NAME -f oauth2_gatewaydb/versioning.sql +psql -d $DB_NAME -f oauth2_gatewaydb/oauth2gw-0001.sql + +psql -d $DB_NAME -c "GRANT USAGE ON SCHEMA oauth2gw TO $DB_USER;" +psql -d $DB_NAME -c "GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA oauth2gw TO $DB_USER;" +psql -d $DB_NAME -c "GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA oauth2gw TO $DB_USER;" +psql -d $DB_NAME -c "ALTER DEFAULT PRIVILEGES IN SCHEMA oauth2gw GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO $DB_USER;" +psql -d $DB_NAME -c "ALTER DEFAULT PRIVILEGES IN SCHEMA oauth2gw GRANT USAGE, SELECT ON SEQUENCES TO $DB_USER;" + +# insert test data +psql -d $DB_NAME -c "INSERT INTO oauth2gw.clients (client_id, secret_hash, webhook_url, verifier_url, verifier_management_api_path) VALUES ('test-exchange', 'test-secret-hash', 'http://localhost:9090/kyc/webhook', 'http://localhost:8080', '/management/api/verifications');" + diff --git a/oauth2_gateway/oauth2_gatewaydb/uninstall_db.sh b/oauth2_gateway/oauth2_gatewaydb/uninstall_db.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +DB_NAME=${DB_NAME:-oauth2gw} +DB_USER=${DB_USER:-oauth2gw} + +dropdb $DB_NAME +dropuser $DB_USER