Skip to content

Commit

Permalink
fix: Windows support (#61)
Browse files Browse the repository at this point in the history
Added *.cmd scripts for Windows
  • Loading branch information
alexander-esser authored Nov 13, 2024
1 parent b21ae8e commit 09fe4a2
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions download-certificates.cmd
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions keygen-generic.cmd
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions keygen-premium.cmd
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions keygen-psd2.cmd
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions run-java.cmd
Original file line number Diff line number Diff line change
@@ -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%"
8 changes: 8 additions & 0 deletions scripts/getAllLatestSwaggerVersion.cmd
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions scripts/getLatestSwaggerVersion.cmd
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 09fe4a2

Please sign in to comment.