diff --git a/g2p-bridge/development/developer-install/example-bank.md b/g2p-bridge/development/developer-install/example-bank.md index ae9b40e2..8759c33e 100644 --- a/g2p-bridge/development/developer-install/example-bank.md +++ b/g2p-bridge/development/developer-install/example-bank.md @@ -29,17 +29,17 @@ sudo apt upgrade -y ```bash sudo apt install -y python3-pip python3-dev build-essential - ``` 3\. Install and configure PostgreSQL -* G2P Bridge requires PostgreSQL as the database engine. Install PostgreSQL and create a new database user for G2P Bridge. +* G2P Bridge requires PostgreSQL as the database engine. Install PostgreSQL (if not already installed) and create a new database user for G2P Bridge. ```bash sudo apt install -y postgresql sudo su - postgres - createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt bankuser + CREATE ROLE bankuser WITH LOGIN NOSUPERUSER CREATEDB CREATEROLE INHERIT REPLICATION CONNECTION LIMIT -1 PASSWORD 'password'; + CREATE DATABASE bankdb WITH OWNER = bankuser CONNECTION LIMIT = -1; exit ``` @@ -59,7 +59,7 @@ sudo apt install -y python3-pip python3-dev build-essential * Make a new Python virtual environment. - ``` + ```bash cd openg2p-g2p-bridge/openg2p-g2p-bridge-example-bank-api python3 -m venv venv ``` @@ -72,29 +72,29 @@ sudo apt install -y python3-pip python3-dev build-essential ```bash python3 -m pip install \ - openg2p-fastapi-common==1.1.0 \ - openg2p-fastapi-auth==1.1.0 \ + openg2p-fastapi-common==1.1.1 \ + openg2p-fastapi-auth==1.1.1 \ openg2p-g2p-bridge-example-bank-models==1.0.0 \ openg2p-g2p-bridge-example-bank-api==1.0.0 ``` -* Update the .env +* Create a .env file ``` - EXAMPLE_BANK_DB_HOSTNAME: localhost - EXAMPLE_BANK_DB_DBNAME: example_bank_db - EXAMPLE_BANK_DB_USERNAME: bankuser - EXAMPLE_BANK_DB_PASSWORD: password - EXAMPLE_BANK_CELERY_BROKER_URL: redis://127.0.0.1:6379/0 - EXAMPLE_BANK_CELERY_BACKEND_URL: redis://127.0.0.1:6379/0 + EXAMPLE_BANK_DB_HOSTNAME='localhost' + EXAMPLE_BANK_DB_DBNAME='bankdb' + EXAMPLE_BANK_DB_USERNAME='bankuser' + EXAMPLE_BANK_DB_PASSWORD='password' + EXAMPLE_BANK_CELERY_BROKER_URL='redis://127.0.0.1:6379/0' + EXAMPLE_BANK_CELERY_BACKEND_URL='redis://127.0.0.1:6379/0' ``` * Migrate the database schema - ``` + ```bash python3 main.py migrate; ``` * Run the API server on `127.0.0.1:8000` - ``` + ```bash gunicorn "main:app" --workers 1 --worker-class uvicorn.workers.UvicornWorker --bind 127.0.0.1:8000 ``` {% endtab %} @@ -104,7 +104,7 @@ sudo apt install -y python3-pip python3-dev build-essential * Make a new Python virtual environment. - ``` + ```bash cd openg2p-g2p-bridge/openg2p-g2p-bridge-example-bank-celery python3 -m venv venv ``` @@ -117,26 +117,26 @@ sudo apt install -y python3-pip python3-dev build-essential ```bash python3 -m pip install \ - openg2p-fastapi-common==1.1.0 \ - openg2p-fastapi-auth==1.1.0 \ + openg2p-fastapi-common==1.1.1 \ + openg2p-fastapi-auth==1.1.1 \ openg2p-g2p-bridge-example-bank-models==1.0.0 \ openg2p-g2p-bridge-example-bank-celery==1.0.0 ``` -* Run redis-server +* Run redis-server (if not already started) ``` bash sudo systemctl start redis ``` -* Update the .env +* Create a .env file ``` - EXAMPLE_BANK_CELERY_DB_HOSTNAME: localhost - EXAMPLE_BANK_CELERY_DB_DBNAME: example_bank_db - EXAMPLE_BANK_CELERY_DB_USERNAME: bankuser - EXAMPLE_BANK_CELERY_DB_PASSWORD: password - EXAMPLE_BANK_CELERY_CELERY_BROKER_URL: redis://127.0.0.1:6379/0 - EXAMPLE_BANK_CELERY_CELERY_BACKEND_URL: redis://127.0.0.1:6379/0 - EXAMPLE_BANK_CELERY_MT940_STATEMENT_CALLBACK_URL: http://openg2p-g2p-bridge-api/upload_mt940 + EXAMPLE_BANK_CELERY_DB_HOSTNAME='localhost' + EXAMPLE_BANK_CELERY_DB_DBNAME='bankdb' + EXAMPLE_BANK_CELERY_DB_USERNAME='bankuser' + EXAMPLE_BANK_CELERY_DB_PASSWORD='password' + EXAMPLE_BANK_CELERY_CELERY_BROKER_URL='redis://127.0.0.1:6379/0' + EXAMPLE_BANK_CELERY_CELERY_BACKEND_URL='redis://127.0.0.1:6379/0' + EXAMPLE_BANK_CELERY_MT940_STATEMENT_CALLBACK_URL='http://openg2p-g2p-bridge-api/upload_mt940' ``` * Run the celery beat and worker diff --git a/g2p-bridge/development/developer-install/installing-openg2p-bridge-on-linux.md b/g2p-bridge/development/developer-install/installing-openg2p-bridge-on-linux.md index 6f2eefb7..028184bb 100644 --- a/g2p-bridge/development/developer-install/installing-openg2p-bridge-on-linux.md +++ b/g2p-bridge/development/developer-install/installing-openg2p-bridge-on-linux.md @@ -34,12 +34,13 @@ sudo apt install -y python3-pip python3-dev build-essential 3\. Install and configure PostgreSQL -* G2P Bridge requires PostgreSQL as the database engine. Install PostgreSQL and create a new database user for G2P Bridge. +* G2P Bridge requires PostgreSQL as the database engine. Install PostgreSQL (if not already installed) and create a new database user for G2P Bridge. ```bash sudo apt install -y postgresql sudo su - postgres - createuser --createdb --username postgres --no-createrole --no-superuser --pwprompt g2p_bridge_user + CREATE ROLE bridgeuser WITH LOGIN NOSUPERUSER CREATEDB CREATEROLE INHERIT REPLICATION CONNECTION LIMIT -1 PASSWORD 'password'; + CREATE DATABASE bridgedb WITH OWNER = bridgeuser CONNECTION LIMIT = -1; exit ``` @@ -59,7 +60,7 @@ sudo apt install -y python3-pip python3-dev build-essential * Make a new Python virtual environment. - ``` + ```bash cd openg2p-g2p-bridge/openg2p-g2p-bridge-api python3 -m venv venv ``` @@ -72,25 +73,24 @@ sudo apt install -y python3-pip python3-dev build-essential ```bash python3 -m pip install \ - openg2p-fastapi-common==1.1.0 \ - openg2p-fastapi-auth==1.1.0 \ - openg2p-g2pconnect-common-lib==1.1.0 \ + openg2p-fastapi-common==1.1.1 \ + openg2p-fastapi-auth==1.1.1 \ + openg2p-g2pconnect-common-lib==1.0.0 \ openg2p-g2p-bridge-models==1.0.0 \ openg2p-g2p-bridge-api==1.0.0 ``` -* Update the .env +* Create a .env file ``` - G2P_BRIDGE_DB_DBNAME: openg2p_g2p_bridge_db - G2P_BRIDGE_DB_HOSTNAME: localhost - G2P_BRIDGE_DB_PASSWORD: password - G2P_BRIDGE_DB_PORT: 5432 - G2P_BRIDGE_DB_USERNAME: bridgeuser - G2P_BRIDGE_WORKER_TYPE: gunicorn - G2P_BRIDGE_HOST: 0.0.0.0 - G2P_BRIDGE_PORT: '8000' - G2P_BRIDGE_NO_OF_WORKERS: '1' - G2P_BRIDGE_OPENAPI_ROOT_PATH: '/api/g2p-bridge' + G2P_BRIDGE_DB_DBNAME='bridgedb' + G2P_BRIDGE_DB_HOSTNAME='localhost' + G2P_BRIDGE_DB_PASSWORD='password' + G2P_BRIDGE_DB_PORT='5432' + G2P_BRIDGE_DB_USERNAME='bridgeuser' + G2P_BRIDGE_WORKER_TYPE='gunicorn' + G2P_BRIDGE_HOST='0.0.0.0' + G2P_BRIDGE_PORT='8000' + G2P_BRIDGE_NO_OF_WORKERS=1 ``` * Migrate the database schema @@ -109,7 +109,7 @@ sudo apt install -y python3-pip python3-dev build-essential * Make a new Python virtual environment. - ``` + ```bash cd openg2p-g2p-bridge/openg2p-g2p-bridge-celery-beat-producers python3 -m venv venv ``` @@ -122,35 +122,32 @@ sudo apt install -y python3-pip python3-dev build-essential ```bash python3 -m pip install \ - openg2p-fastapi-common==1.1.0 \ - openg2p-fastapi-auth==1.1.0 \ - openg2p-g2pconnect-common-lib==1.1.0 \ + openg2p-fastapi-common==1.1.1 \ + openg2p-fastapi-auth==1.1.1 \ + openg2p-g2pconnect-common-lib==1.0.0 \ openg2p-g2p-bridge-models==1.0.0 \ openg2p-g2p-bridge-bank-connectors==1.0.0 \ openg2p-g2p-bridge-celery-beat-producers==1.0.0 ``` -* Update the .env +* Create a .env file ``` - G2P_BRIDGE_CELERY_BEAT_MAPPER_RESOLVE_API_URL: 'http://spar-mapper-api/sync/resolve' # Update the Spar Mapper Resolve URL - G2P_BRIDGE_CELERY_BEAT_DB_HOSTNAME: localhost - G2P_BRIDGE_CELERY_BEAT_DB_PASSWORD: password - G2P_BRIDGE_CELERY_BEAT_CELERY_BROKER_URL: redis://127.0.0.1:6379/0 - G2P_BRIDGE_CELERY_BEAT_CELERY_BACKEND_URL: redis://127.0.0.1:6379/0 - G2P_BRIDGE_CELERY_BEAT_BANK_FA_DECONSTRUCT_STRATEGY: ^account_number:(?P.*)\.branch_code:(?P.*)\.bank_code:(?P.*)\.fa_type:(?P.*)$ - G2P_BRIDGE_CELERY_BEAT_MOBILE_WALLET_DECONSTRUCT_STRATEGY: ^mobile_number:(?P.*)\.wallet_provider_name:(?P.*)\.wallet_provider_code:(?P.*)\.fa_type:(?P.*)$ - G2P_BRIDGE_CELERY_BEAT_EMAIL_WALLET_DECONSTRUCT_STRATEGY: ^email_address:(?P.*)\.wallet_provider_name:(?P.*)\.wallet_provider_code:(?P.*)\.fa_type:(?P.*)$ - G2P_BRIDGE_CELERY_BEAT_MAPPER_RESOLVE_FREQUENCY: 60 - G2P_BRIDGE_CELERY_BEAT_FUNDS_AVAILABLE_CHECK_FREQUENCY: 60 - G2P_BRIDGE_CELERY_BEAT_FUNDS_BLOCKED_FREQUENCY: 60 - G2P_BRIDGE_CELERY_BEAT_FUNDS_DISBURSEMENT_FREQUENCY: 60 - G2P_BRIDGE_CELERY_BEAT_MT940_PROCESSOR_FREQUENCY: 60 - G2P_BRIDGE_CELERY_BEAT_PROCESS_FUTURE_DISBURSEMENT_SCHEDULES: true + G2P_BRIDGE_CELERY_BEAT_MAPPER_RESOLVE_API_URL='http://spar-mapper-api/sync/resolve' # Update the Spar Mapper Resolve URL + G2P_BRIDGE_CELERY_BEAT_DB_HOSTNAME='localhost' + G2P_BRIDGE_CELERY_BEAT_DB_PASSWORD='password' + G2P_BRIDGE_CELERY_BEAT_CELERY_BROKER_URL='redis://127.0.0.1:6379/0' + G2P_BRIDGE_CELERY_BEAT_CELERY_BACKEND_URL='redis://127.0.0.1:6379/0' + G2P_BRIDGE_CELERY_BEAT_MAPPER_RESOLVE_FREQUENCY=60 + G2P_BRIDGE_CELERY_BEAT_FUNDS_AVAILABLE_CHECK_FREQUENCY=60 + G2P_BRIDGE_CELERY_BEAT_FUNDS_BLOCKED_FREQUENCY=60 + G2P_BRIDGE_CELERY_BEAT_FUNDS_DISBURSEMENT_FREQUENCY=60 + G2P_BRIDGE_CELERY_BEAT_MT940_PROCESSOR_FREQUENCY=60 + G2P_BRIDGE_CELERY_BEAT_PROCESS_FUTURE_DISBURSEMENT_SCHEDULES=true ``` * Run redis-server - ``` - bash sudo systemctl start redis + ```bash + sudo systemctl start redis ``` * Run the celery beat @@ -164,7 +161,7 @@ sudo apt install -y python3-pip python3-dev build-essential * Make a new Python virtual environment. - ``` + ```bash cd openg2p-g2p-bridge/openg2p-g2p-bridge-celery-workers python3 -m venv venv ``` @@ -177,35 +174,35 @@ sudo apt install -y python3-pip python3-dev build-essential ```bash python3 -m pip install \ - openg2p-fastapi-common==1.1.0 \ - openg2p-fastapi-auth==1.1.0 \ - openg2p-g2pconnect-common-lib==1.1.0 \ + openg2p-fastapi-common==1.1.1 \ + openg2p-fastapi-auth==1.1.1 \ + openg2p-g2pconnect-common-lib==1.0.0 \ openg2p-g2p-bridge-models==1.0.0 \ openg2p-g2p-bridge-bank-connectors==1.0.0 \ openg2p-g2p-bridge-celery-workers==1.0.0 ``` -* Update the .env +* Create a .env file ``` - G2P_BRIDGE_CELERY_WORKERS_MAPPER_RESOLVE_API_URL: 'http://mapper/sync/resolve' - G2P_BRIDGE_CELERY_WORKERS_MAPPER_RESOLVE_RETRY_DELAY: 5 - G2P_BRIDGE_CELERY_WORKERS_DB_DBNAME: openg2p_g2p_bridge_db - G2P_BRIDGE_CELERY_WORKERS_DB_USERNAME: bridgeuser - G2P_BRIDGE_CELERY_WORKERS_DB_PASSWORD: password - G2P_BRIDGE_CELERY_WORKERS_DB_HOSTNAME: localhost - G2P_BRIDGE_CELERY_WORKERS_BANK_FA_DECONSTRUCT_STRATEGY: bank_(?P\d+)_(?P\d+)_(?P\d+)_(?P\w+) - G2P_BRIDGE_CELERY_WORKERS_MOBILE_WALLET_DECONSTRUCT_STRATEGY: mobile_(?P\d+)_(?P\w+) - G2P_BRIDGE_CELERY_WORKERS_EMAIL_WALLET_DECONSTRUCT_STRATEGY: email_(?P\w+)_(?P\w+) - G2P_BRIDGE_CELERY_PRODUCERS_FUNDS_AVAILABLE_CHECK_URL_EXAMPLE_BANK: http://127.0.0.1:8003/check_funds" - G2P_BRIDGE_CELERY_PRODUCERS_FUNDS_BLOCK_URL_EXAMPLE_BANK: http://127.0.0.1:8003/block_funds" - G2P_BRIDGE_CELERY_PRODUCERS_FUNDS_DISBURSEMENT_URL_EXAMPLE_BANK: http://127.0.0.1:8003/initiate_payment" - G2P_BRIDGE_CELERY_WORKERS_CELERY_BROKER_URL: redis://127.0.0.1:6379/0 - G2P_BRIDGE_CELERY_WORKERS_CELERY_BACKEND_URL: redis://127.0.0.1:6379/0 + G2P_BRIDGE_CELERY_WORKERS_MAPPER_RESOLVE_API_URL='http://mapper/sync/resolve' + G2P_BRIDGE_CELERY_WORKERS_MAPPER_RESOLVE_RETRY_DELAY=5 + G2P_BRIDGE_CELERY_WORKERS_DB_DBNAME='bridgedb' + G2P_BRIDGE_CELERY_WORKERS_DB_USERNAME='bridgeuser' + G2P_BRIDGE_CELERY_WORKERS_DB_PASSWORD='password' + G2P_BRIDGE_CELERY_WORKERS_DB_HOSTNAME='localhost' + G2P_BRIDGE_CELERY_BEAT_BANK_FA_DECONSTRUCT_STRATEGY='^account_number:(?P.*)\.branch_code:(?P.*)\.bank_code:(?P.*)\.mobile_number:(?P.*)\.email_address:(?P.*)\.fa_type:(?P.*)$' + G2P_BRIDGE_CELERY_BEAT_MOBILE_WALLET_DECONSTRUCT_STRATEGY='^mobile_number:(?P.*)\.wallet_provider_name:(?P.*)\.wallet_provider_code:(?P.*)\.fa_type:(?P.*)$' + G2P_BRIDGE_CELERY_BEAT_EMAIL_WALLET_DECONSTRUCT_STRATEGY='^email_address:(?P.*)\.wallet_provider_name:(?P.*)\.wallet_provider_code:(?P.*)\.fa_type:(?P.*)$' + G2P_BRIDGE_CELERY_PRODUCERS_FUNDS_AVAILABLE_CHECK_URL_EXAMPLE_BANK='http://127.0.0.1:8003/check_funds' + G2P_BRIDGE_CELERY_PRODUCERS_FUNDS_BLOCK_URL_EXAMPLE_BANK='http://127.0.0.1:8003/block_funds' + G2P_BRIDGE_CELERY_PRODUCERS_FUNDS_DISBURSEMENT_URL_EXAMPLE_BANK='http://127.0.0.1:8003/initiate_payment' + G2P_BRIDGE_CELERY_WORKERS_CELERY_BROKER_URL='redis://127.0.0.1:6379/0' + G2P_BRIDGE_CELERY_WORKERS_CELERY_BACKEND_URL='redis://127.0.0.1:6379/0' ``` -* Run redis-server +* Run redis-server (if not already started) - ``` - bash sudo systemctl start redis + ```bash + sudo systemctl start redis ``` * Run the celery beat diff --git a/spar/development/developer-install/spar-mapper-api.md b/spar/development/developer-install/spar-mapper-api.md index 9e35dd7c..f2ed993c 100644 --- a/spar/development/developer-install/spar-mapper-api.md +++ b/spar/development/developer-install/spar-mapper-api.md @@ -21,7 +21,7 @@ description: >- The following dependencies are managed in the installation steps below. -```sh +``` annotated-types==0.6.0 anyio==3.7.1 asyncio==3.4.3 @@ -81,16 +81,22 @@ websockets==12.0 ### Steps to install -* Clone the repository +* Install dependencies + +```bash +sudo apt install -y python3-pip python3-dev build-essential libpq-dev +``` + +* Clone the repository ```sh git clone https://github.com/OpenG2P/openg2p-spar-mapper-api.git ``` -* Navigate to the project root +* Navigate to the project root and switch to branch 1.0.0 ```sh -cd openg2p-spar-mapper-api +cd openg2p-spar-mapper-api && git checkout 1.0.0 ``` * Create a virtual environment with Python 3 @@ -113,8 +119,27 @@ pip install greenlet && pip install -e . ``` -* Configure database credentials and other environment variables in the \`.env\` file - * [See Configuration section below](spar-mapper-api.md#configuration) +* Create a '.env' file and configure database + * Set the following environment variables to configure the \`spar-mapper-api\`: + + ```xml + # Application Port + SPAR_MAPPER_PORT='8007' + + # Database credentials + SPAR_MAPPER_DB_HOSTNAME='localhost' + SPAR_MAPPER_DB_USERNAME='sparuser' + SPAR_MAPPER_DB_PASSWORD='password' + SPAR_MAPPER_DB_DBNAME='spardb' + ``` + * Database setup + + ```sql + CREATE ROLE sparuser WITH LOGIN NOSUPERUSER CREATEDB CREATEROLE INHERIT REPLICATION CONNECTION LIMIT -1 PASSWORD 'password'; + CREATE DATABASE spardb WITH OWNER = sparuser CONNECTION LIMIT = -1; + ``` + + * Run migrations to set up the database: ```sh @@ -132,22 +157,6 @@ python main.py run * Access Swagger API Documentation * [http://localhost:8007/docs](http://localhost:8007/docs) -### Configuration - -#### Environment Variables - -Set the following environment variables to configure the \`spar-mapper-api\`: - -```xml -# Application Port -SPAR_MAPPER_PORT='8007' - -# Database credentials -SPAR_MAPPER_DB_HOSTNAME='localhost' -SPAR_MAPPER_DB_USERNAME='sparuser' -SPAR_MAPPER_DB_DBNAME='spardb' -``` - ### Testing To run unit tests with `pytest`: diff --git a/spar/development/developer-install/spar-self-service-api.md b/spar/development/developer-install/spar-self-service-api.md index d624e4d8..f56df81b 100644 --- a/spar/development/developer-install/spar-self-service-api.md +++ b/spar/development/developer-install/spar-self-service-api.md @@ -36,7 +36,7 @@ This page provides comprehensive documentation for the installation of SPAR Self The following dependencies are managed in the installation steps below. -```sh +``` annotated-types==0.6.0 anyio==3.7.1 asyncio==3.4.3 @@ -101,6 +101,12 @@ websockets==12.0 #### Install from source +* Install dependencies + +```sh +sudo apt install -y python3-pip python3-dev build-essential libpq-dev +``` + * Clone the repository. ```sh @@ -110,7 +116,7 @@ git clone https://github.com/OpenG2P/openg2p-spar-self-service * Navigate to the project root. ```sh -cd openg2p-spar-self-service +cd openg2p-spar-self-service && git checkout 1.0.0 ``` * Create a virtual environment with Python 3. @@ -128,39 +134,63 @@ source venv/bin/activate * Install the necessary dependencies. ```sh -pip install -r ../test-requirements.txt && +pip install -r test-requirements.txt && pip install openg2p-spar-g2pconnect-mapper-connector-lib && -pip install greenlet && -pip install -e . +pip install greenlet && +pip install -e openg2p-spar-g2pconnect-mapper-connector-lib && +pip install -e openg2p-spar-mapper-interface-lib && +pip install -e openg2p-spar-self-service-api ``` -* Configure database credentials and other environment variables in the _**.env**_ file. - * [See Configuration section below](spar-self-service-api.md#configuration) -* Run migrations to set up the database. +* Create a '.env' file and configure database credentials + * Set the following environment variables to configure the _**spar-mapper-api**_. -```sh -python main.py migrate -``` + ```markup + # Database credentials for spar-mapper-api (Update these values as per your installation/setup) + SPAR_SELFSERVICE_DB_DBNAME='spardb' + SPAR_SELFSERVIC_DB_HOSTNAME='localhost' + SPAR_SELFSERVIC_DB_USERNAME='sparuser' + SPAR_SELFSERVICE_DB_PASSWORD='password' -### Seeding the database (optional) + # Auth (Update these values as per your installation/setup) + SPAR_SELFSERVICE_AUTH_DEFAULT_ISSUERS=["https://esignet.dev.openg2p.org"] + SPAR_SELFSERVICE_AUTH_DEFAULT_JWKS_URLS=["https://esignet.dev.openg2p.org/.well-known/jwks.json"] + + # SPAR Mapper API Endpoints (change only if required) + SPAR_SELFSERVICE_MAPPER_API_URL="http://localhost:8007/sync" + SPAR_SELFSERVICE_MAPPER_LINK_PATH="/link" + SPAR_SELFSERVICE_MAPPER_UNLINK_PATH="/unlink" + SPAR_SELFSERVICE_MAPPER_RESOLVE_PATH="/resolve" + SPAR_SELFSERVICE_MAPPER_UPDATE_PATH="/update" -This will seed the database with default values. Make sure to update the eSignet configuration in the DB as per your installation. + SPAR_SELFSERVICE_OPENAPI_ROOT_PATH='/api/selfservice' -#### PostgreSQL DB Setup + # Bypass auth verification for dev purposes + SPAR_SELFSERVICE_PORTAL_AUTH_DEFAULT_ID_TOKEN_VERIFY_AT_HASH="false" + SPAR_SELFSERVICE_AUTH_COOKIE_SECURE="false" + ``` + * Database setup (skip this step if database is already setup) -Create a new role/user called _**sparuser**_ and create a new database called _**spardb**_, with _**sparuser**_ as the owner. No need to run this step, if Postgres was installed through OpenG2P's deployment script. + ```sql + CREATE ROLE sparuser WITH LOGIN NOSUPERUSER CREATEDB CREATEROLE INHERIT REPLICATION CONNECTION LIMIT -1 PASSWORD 'password'; + CREATE DATABASE spardb WITH OWNER = sparuser CONNECTION LIMIT = -1; + ``` -```plsql -CREATE ROLE sparuser WITH LOGIN NOSUPERUSER CREATEDB CREATEROLE INHERIT REPLICATION CONNECTION LIMIT -1 PASSWORD 'xxxxxx'; -CREATE DATABASE spardb WITH OWNER = sparuser CONNECTION LIMIT = -1; + +* Run migrations to set up the database. + +```sh +python main.py migrate ``` -#### Then run the script. +### Seeding the database (optional) + +This will seed the database with default values. ```sh cd db_scripts && -DB_HOST="openg2p.sandbox.net" \ -DB_USER_PASSWORD="xxxxxx" \ +DB_HOST="localhost" \ +DB_USER_PASSWORD="password" \ ./deploy.sh && cd .. ``` @@ -175,42 +205,7 @@ DB_USER_PASSWORD="xxxxxx" \ - `LOG_DB_QUERY="true"` Default is false. Logs all Db queries. ``` -### Quick start - -* Start the development server. - -```sh -python main.py run -``` - -* Access Swagger API Documentation. - * [http://localhost:8000/docs](http://localhost:8000/docs) - -### Configuration - -#### Environment variables - -Set the following environment variables to configure the _**spar-mapper-api**_. - -```markup -# Database credentials for spar-mapper-api (Update these values as per your installation/setup) -SPAR_SELFSERVICE_DB_DBNAME=openg2p_spar_db -SPAR_SELFSERVIC_DB_HOSTNAME='localhost' -SPAR_SELFSERVIC_DB_USERNAME='sparuser' - -# Auth (Update these values as per your installation/setup) -SPAR_SELFSERVICE_AUTH_DEFAULT_ISSUERS=[ "https://esignet.dev.sandbox.net/v1/esignet", "https://keycloak.dev.sandbox.net/realms/sandbox" ] -SPAR_SELFSERVICE_AUTH_DEFAULT_JWKS_URLS=[ "https://esignet.dev.sandbox.net/v1/esignet/oauth/.well-known/jwks.json", "https://keycloak.dev.sandbox.net/realms/sandbox/protocol/openid-connect/certs" ] - -# SPAR Mapper API Endpoints (change only if required) -SPAR_SELFSERVICE_MAPPER_API_URL="http://localhost:8007/sync" -SPAR_SELFSERVICE_MAPPER_LINK_PATH="/link" -SPAR_SELFSERVICE_MAPPER_UNLINK_PATH="/unlink" -SPAR_SELFSERVICE_MAPPER_RESOLVE_PATH="/resolve" -SPAR_SELFSERVICE_MAPPER_UPDATE_PATH="/update" -``` - -#### Authentication +### Authentication The `spar-self-service-api` supports authentication via eSignet. Refer to the deployment documentation for eSignet [here](broken-reference) for setup instructions. @@ -219,12 +214,23 @@ The `spar-self-service-api` supports authentication via eSignet. Refer to the de To integrate the SPAR Self-Service UI with any login provider, you need to add the `redirect_uri` in the authorization\_parameter column. ``` -"redirect_uri": "http://selfservice.qa.openg2p.net/api/selfservice/oauth2/callback" +"redirect_uri": "http://spar.openg2p.my/api/selfservice/oauth2/callback" ``` * This URL needs to be updated in the `login_providers` table, specifically in the `authorization_parameters` column for the eSignet record. * Make sure to replace `selfservice.qa.openg2p.net` with the appropriate domain that matches your eSignet configuration. +### Quick start + +* Start the development server. + +```sh +python main.py run +``` + +* Access Swagger API Documentation. + * [http://localhost:8000/docs](http://localhost:8000/docs) + ### Testing Run the unit tests with `pytest.` diff --git a/spar/development/developer-install/spar-self-service-ui.md b/spar/development/developer-install/spar-self-service-ui.md index 2d86bbaf..8712d50c 100644 --- a/spar/development/developer-install/spar-self-service-ui.md +++ b/spar/development/developer-install/spar-self-service-ui.md @@ -42,9 +42,10 @@ npm install * **Configuration**: Configure Spar UI to connect with the Spar services. This typically involves setting environment variables -
NEXT_PUBLIC_BASE_PATH="/spar/self-service-ui"
-NEXT_PUBLIC_BASE_API_PATH="/spar/self-service-api/"
-
+```shellscript +NEXT_PUBLIC_BASE_PATH="/selfservice" +NEXT_PUBLIC_BASE_API_PATH="/api/selfservice" +``` * **Nginx Configuration**: Configure Nginx to act as a reverse proxy for Spar services. @@ -64,49 +65,48 @@ sudo nano /etc/nginx/sites-available/spar.conf ``` server { - listen 80; - server_name spar.openg2p.my; - location = / { - return 301 /spar/self-service-ui; - } - location /spar/self-service-ui { - proxy_pass http://localhost:3000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header Referer $http_referer; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass_request_headers on; - } - location /spar/self-service-api/ { - proxy_pass http://localhost:8000/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header Referer $http_referer; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass_request_headers on; - } - location /spar/mapper-api/ { - proxy_pass http://localhost:8007/; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header Referer $http_referer; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass_request_headers on; - } + listen 80; + server_name spar.openg2p.my; + location = / { + return 301 /selfservice; + } + location /selfservice { + proxy_pass http://localhost:3000; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header Referer $http_referer; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass_request_headers on; + } + location /api/selfservice/ { + proxy_pass http://localhost:8000/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header Referer $http_referer; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass_request_headers on; + } + location /api/mapper/ { + proxy_pass http://localhost:8007/; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header Referer $http_referer; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass_request_headers on; + } } - ``` * **Enable Configuration**: Enable the Nginx configuration by creating a symbolic link to `sites-enabled` @@ -130,7 +130,7 @@ sudo service nginx restart ``` * **Start Spar Services**: Ensure that Spar-SelfService and Spar-Mapper services are up and running. Refer to the Mapper and Self service documentation. -* **Run Spar UI**: Start the Spar UI application: This command starts the development server for Spar UI. Open a web browser and navigate to the specified URL (usually http://localhost:3000) or a specific domain as per nginx server ,to access the Spar UI interface. +* **Run Spar UI**: Start the Spar UI application: This command starts the development server for Spar UI. Open a web browser and navigate to the specified URL (usually http://localhost:3000) or a specific domain as per nginx server (here http://spar.openg2p.my) to access the Spar UI interface. ```sh npm run dev