From 09fe4a26c8482bf748428a0a8b7dd50943c55c66 Mon Sep 17 00:00:00 2001 From: Alexander Esser Date: Wed, 13 Nov 2024 15:32:38 +0100 Subject: [PATCH] fix: Windows support (#61) Added *.cmd scripts for Windows --- README.md | 23 +++++++++ download-certificates.cmd | 21 +++++++++ keygen-generic.cmd | 52 +++++++++++++++++++++ keygen-premium.cmd | 18 ++++++++ keygen-psd2.cmd | 18 ++++++++ run-java.cmd | 15 ++++++ scripts/getAllLatestSwaggerVersion.cmd | 8 ++++ scripts/getLatestSwaggerVersion.cmd | 64 ++++++++++++++++++++++++++ 8 files changed, 219 insertions(+) create mode 100644 download-certificates.cmd create mode 100644 keygen-generic.cmd create mode 100644 keygen-premium.cmd create mode 100644 keygen-psd2.cmd create mode 100644 run-java.cmd create mode 100644 scripts/getAllLatestSwaggerVersion.cmd create mode 100644 scripts/getLatestSwaggerVersion.cmd diff --git a/README.md b/README.md index 22bf307..ca6939f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,10 @@ You can use this SDK to generate drivers for both Premium and PSD2 APIs. Read ou * CURL ## Quick Start (*nix) + +### Unix +On *nix systems (Unix, Linux, macOS etc.): + * Run `./download-certificates.sh` * Run `./keygen-premium.sh` and set `secret` as password. * Run `./keygen-psd2.sh` and set `secret2` as password. @@ -28,6 +32,25 @@ You can use this SDK to generate drivers for both Premium and PSD2 APIs. Read ou * You are redirected back to `localhost` and see the customer token displayed. * Click the link to view the test profile accounts. +### Windows + +On Windows: + +* Ensure that *openssl* (e.g. Win64OpenSSL) is installed and in your PATH. +* Run `./download-certificates.cmd` +* Run `./keygen-premium.cmd` and set `secret` as password. +* Run `./keygen-psd2.cmd` and set `secret2` as password. +* Run `mvn clean install` +* Run `./run-java.cmd` +* Go to `http://localhost:8080` +* Click the link you get back and is displayed. +* Select the top profile and click next. +* You are redirected back to `localhost` and see the customer token displayed. +* Click the link to view the test profile accounts. + + + + ## Slightly Slower Start ### Folder structure In this repository you can find api descriptions in swagger json format in the `api` directory. In addition, you can find the `open-banking-driver-generator` folder containing the modified Java [Open API Generator](https://github.com/OpenAPITools/openapi-generator) to generate drivers. Moreover, you can find a demo app, modules to generate Open Banking Drivers using the modified generator, and some wrapper classes in the `java` folder. diff --git a/download-certificates.cmd b/download-certificates.cmd new file mode 100644 index 0000000..7edb945 --- /dev/null +++ b/download-certificates.cmd @@ -0,0 +1,21 @@ +@echo off + +REM Create 'certs' directory (if not exists) +mkdir certs +cd certs || exit /b + +REM Download the example_client_tls.pem and example_client_signing.pem files +curl -O https://raw.githubusercontent.com/ing-bank/ing-open-banking-cli/master/apps/sandbox/certificates/example_client_tls.pem +curl -O https://raw.githubusercontent.com/ing-bank/ing-open-banking-cli/master/apps/sandbox/certificates/example_client_signing.pem +curl -O https://raw.githubusercontent.com/ing-bank/ing-open-banking-cli/master/apps/sandbox/certificates/example_client_tls.key +curl -O https://raw.githubusercontent.com/ing-bank/ing-open-banking-cli/master/apps/sandbox/certificates/example_client_signing.key + +REM Create the 'psd2' directory (if not exists) +mkdir psd2 +cd psd2 || exit /b + +REM Download the PSD2 example_client_tls.pem and example_client_signing.pem files +curl -O https://raw.githubusercontent.com/ing-bank/ing-open-banking-cli/master/apps/sandbox/certificates/psd2/example_client_tls.pem +curl -O https://raw.githubusercontent.com/ing-bank/ing-open-banking-cli/master/apps/sandbox/certificates/psd2/example_client_signing.pem +curl -O https://raw.githubusercontent.com/ing-bank/ing-open-banking-cli/master/apps/sandbox/certificates/psd2/example_client_tls.key +curl -O https://raw.githubusercontent.com/ing-bank/ing-open-banking-cli/master/apps/sandbox/certificates/psd2/example_client_signing.key diff --git a/keygen-generic.cmd b/keygen-generic.cmd new file mode 100644 index 0000000..ea7bccc --- /dev/null +++ b/keygen-generic.cmd @@ -0,0 +1,52 @@ +@echo off +setlocal + +REM Check if the required arguments are provided +if "%1"=="" ( + echo Usage: %0 SRC_DIR TLS SIGN DESTINATION FILENAME + echo Example: %0 certs\ example_client_tls example_client_signing java\open-banking-demo-app\src\main\resources\ keystore-premium.jks + exit /b 1 +) + +REM Variables passed as arguments +set SRC_DIR=%1 +set TLS=%2 +set SIGN=%3 +set DESTINATION=%4 +set FILENAME=%5 + +set TEMP_KEYSTORE_NAME=store-open.keys + +REM Check if destination directory exists +if not exist "%DESTINATION%" ( + echo. + echo Directory %DESTINATION% DOES NOT exist. + echo. + exit /b +) + +REM Prompt for password +echo. +echo Please provide a password of at least 6 characters. +echo This password should be used in your application to retrieve your certificates and keys. +echo. +set /p PASSWORD=Enter password: + +REM Suppress password input by using the choice command in Windows (or PowerShell for more control if needed) +REM Create tls.p12 and sign.p12 with OpenSSL +openssl pkcs12 -export -in "%SRC_DIR%%TLS%.pem" -inkey "%SRC_DIR%%TLS%.key" -name tls -password pass:%PASSWORD% -out tls.p12 +openssl pkcs12 -export -in "%SRC_DIR%%SIGN%.pem" -inkey "%SRC_DIR%%SIGN%.key" -name sign -password pass:%PASSWORD% -out sign.p12 + +REM Import into keystore with keytool +keytool -importkeystore -srckeystore tls.p12 -destkeystore "%TEMP_KEYSTORE_NAME%" -srcstoretype pkcs12 -alias tls -srcstorepass %PASSWORD% -deststorepass %PASSWORD% +keytool -importkeystore -srckeystore sign.p12 -destkeystore "%TEMP_KEYSTORE_NAME%" -srcstoretype pkcs12 -alias sign -srcstorepass %PASSWORD% -deststorepass %PASSWORD% + +REM Copy the keystore file to the destination with the specified filename +copy "%TEMP_KEYSTORE_NAME%" "%DESTINATION%%FILENAME%" + +REM Clean up temporary files +del "%TEMP_KEYSTORE_NAME%" +del tls.p12 +del sign.p12 + +endlocal diff --git a/keygen-premium.cmd b/keygen-premium.cmd new file mode 100644 index 0000000..8d58dc8 --- /dev/null +++ b/keygen-premium.cmd @@ -0,0 +1,18 @@ +@echo off +setlocal + +REM Set variables +set SRC_DIR=certs/ +set TLS=example_client_tls +set SIGN=example_client_signing +set DESTINATION=java\open-banking-demo-app\src\main\resources\ +set FILENAME=keystore-premium.jks +set SIMPLE_DESTINATION=java\open-banking-simple-app\src\main\resources\ + +REM Run the key generation script with parameters +call keygen-generic.cmd %SRC_DIR% %TLS% %SIGN% %DESTINATION% %FILENAME% + +REM Copy the generated keystore file to the simple app destination +copy "%DESTINATION%%FILENAME%" "%SIMPLE_DESTINATION%%FILENAME%" + +endlocal diff --git a/keygen-psd2.cmd b/keygen-psd2.cmd new file mode 100644 index 0000000..b8f700e --- /dev/null +++ b/keygen-psd2.cmd @@ -0,0 +1,18 @@ +@echo off +setlocal + +REM Set variables +set SRC_DIR=certs\psd2\ +set TLS=example_client_tls +set SIGN=example_client_signing +set DESTINATION=java\open-banking-demo-app\src\main\resources\ +set FILENAME=keystore-psd2.jks +set SIMPLE_DESTINATION=java\open-banking-simple-app\src\main\resources\ + +REM Run the key generation script with parameters +call keygen-generic.cmd %SRC_DIR% %TLS% %SIGN% %DESTINATION% %FILENAME% + +REM Copy the generated keystore file to the simple app destination +copy "%DESTINATION%%FILENAME%" "%SIMPLE_DESTINATION%%FILENAME%" + +endlocal diff --git a/run-java.cmd b/run-java.cmd new file mode 100644 index 0000000..34b344c --- /dev/null +++ b/run-java.cmd @@ -0,0 +1,15 @@ +@echo off + +set BASE_URL=https://api.sandbox.ing.com + +REM Find the JAR file in the target directory +for %%f in (java\open-banking-demo-app\target\open-banking-demo-app-*.jar) do ( + set JAR_FILE=%%f +) +if not defined JAR_FILE ( + echo Error: No JAR file found matching pattern java\open-banking-demo-app\target\open-banking-demo-app-*.jar + exit /b 1 +) + +REM Run the Java application +java -jar "%JAR_FILE%" diff --git a/scripts/getAllLatestSwaggerVersion.cmd b/scripts/getAllLatestSwaggerVersion.cmd new file mode 100644 index 0000000..e9a57dc --- /dev/null +++ b/scripts/getAllLatestSwaggerVersion.cmd @@ -0,0 +1,8 @@ +@echo off + +REM Run the getLatestSwaggerVersion script with different parameters +call getLatestSwaggerVersion.cmd 2d00fd5f-88cd-4416-bbca-f309ebb03bfe oauth2 +call getLatestSwaggerVersion.cmd b6d5093d-626e-41e9-b9e8-ff287bbe2c07 account/information +call getLatestSwaggerVersion.cmd 6aa25087-d05d-428e-b7c6-d9131cb46498 payment/initiation +call getLatestSwaggerVersion.cmd 01199464-4247-4770-8ab8-c3371052e9e5 payment/request +call getLatestSwaggerVersion.cmd 5f5106c4-3413-4b3c-890a-bb4cfa165dba showcase diff --git a/scripts/getLatestSwaggerVersion.cmd b/scripts/getLatestSwaggerVersion.cmd new file mode 100644 index 0000000..6c3ed16 --- /dev/null +++ b/scripts/getLatestSwaggerVersion.cmd @@ -0,0 +1,64 @@ +@echo off +setlocal + +REM Set variables from arguments +set API_ID=%1 +set SWAGGER_DIR=%2 + +echo apiId: %API_ID% +echo swaggerDir: %SWAGGER_DIR% +set prefix=)]}', + +REM Function to decode base64 and apply jq filter +set "_jq=" +for /f "tokens=*" %%A in ('powershell -Command "[Convert]::FromBase64String((Get-Content -Raw) -replace '\n', '') | % { $_ | ForEach-Object { [System.Text.Encoding]::UTF8.GetString($_) } }"' ) do set "_jq=%%A" + +REM Fetch versions +for /f "tokens=*" %%A in ('curl "https://api.developer.ing.com/apis/%API_ID%/versions"') do set "raw_versions=%%A" + +REM Remove prefix from raw_versions +set "cleaned_versions=%raw_versions:%prefix%=%" + +echo %cleaned_versions% + +REM Parse versions +for /f %%A in ('echo %cleaned_versions% ^| jq -r ".apis[] | @base64"') do ( + set "row=%%A" + for /f %%B in ('echo %row% ^| base64 --decode ^| jq -r ".api.name"') do set "name=%%B" + for /f %%C in ('echo %row% ^| base64 --decode ^| jq -r ".versionNumber"') do set "versionNumber=%%C" + for /f %%D in ('echo %row% ^| base64 --decode ^| jq -r ".versionId"') do set "versionId=%%D" + for /f %%E in ('echo %row% ^| base64 --decode ^| jq -r ".status"') do set "status=%%E" + + echo -------------- + echo Name: %name% + echo Version Number: %versionNumber% + echo Version ID: %versionId% + echo Status: %status% + + if "%status%"=="LIVE" ( + set "file_name=..\api\%SWAGGER_DIR%\%name%.json" + set "file_name=%file_name: =-%" + + if not exist "%file_name%" ( + echo %file_name% does not exist. Downloading... + curl "https://api.touchpoint.ing.net/apis/%API_ID%/versions/%versionId%/specification/download?format=json&pretty=true" -o "%file_name%" + git add "%file_name%" + ) else ( + echo %file_name% exists. + for /f "tokens=*" %%F in ('jq -r ".info.version" "%file_name%"') do set "currentVersion=%%F" + echo Current version: %currentVersion% + if "%versionNumber%"=="%currentVersion%" ( + echo VERSION MATCH + ) else ( + echo DOWNLOAD NEW VERSION + curl "https://api.touchpoint.ing.net/apis/%API_ID%/versions/%versionId%/specification/download?format=json&pretty=true" -o "%file_name%" + git add "%file_name%" + ) + ) + goto :break + ) + echo -------------- +) + +:break +endlocal