Skip to content

Commit

Permalink
Add /scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
franco-lombardo committed Jan 9, 2025
1 parent 5b40395 commit 35502d6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copy this file in .env.local and change values as needed
COMMON_LOGIN_URL=https://common-sandbox.api.acubeapi.com
COMMON_LOGIN_EMAIL=[email protected]
COMMON_LOGIN_PASSWORD=SomePassword
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules/
/.idea/
/dist/
/.env.local
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Example of a A-CUBE webhook server written in Typescript
# Examples of an A-CUBE webhook server written in Typescript and bash scripts to use A-CUBE APIs

## A-CUBE webhook server
This project is a sample implementation of a webhook that [checks the validity of A-Cube signature](https://docs.acubeapi.com/documentation/common/http-signature/#python).

To run it, first install dependencies with
Expand All @@ -15,3 +16,8 @@ Then start the server with
npm start
```
The server should now be running on port 3000.

## Sample scripts
In the [/scripts](/scripts) folder you can find some bash scripts to connect to A-CUBE APIs.
To use them copy [.env](.env) file into `.env.local` and change the values as needed.
To run most of these scripts you need to install [jq](https://jqlang.github.io/jq/).
22 changes: 22 additions & 0 deletions scripts/getJWT.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

########################################################################################################################
# This script get a JWT token from common sandbox and it is executed also from other scripts
# It requires jq
# You need to add COMMON_LOGIN_URL, COMMON_LOGIN_EMAIL and COMMON_LOGIN_PASSWORD in env.local as well
########################################################################################################################


DIR="$(dirname "${BASH_SOURCE[0]}")"
DIR="$(readlink -f "${DIR}")"

source "${DIR}"/../.env.local

JSON_REQUEST=$( jq -n \
--arg em "$COMMON_LOGIN_EMAIL" \
--arg pw "$COMMON_LOGIN_PASSWORD" \
'{email: $em, password: $pw}' )

curl -s --location --request POST "$COMMON_LOGIN_URL/login" \
--header 'Content-Type: application/json' \
--data-raw "$JSON_REQUEST" | jq -r '.token'
26 changes: 26 additions & 0 deletions scripts/verifyCompany.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

########################################################################################################################
# Use this script to verify a company
########################################################################################################################

if [ "$#" -lt 1 ];
then
echo "Use this script to verify a company"
echo "One parameter is needed, which indicates fiscal ID of the company."
echo "Change .env.local and the REMOTE_HOST variable to connect to prod or sanbdox."
echo "$0 123456789"
exit 1
fi

DIR="$(dirname "${BASH_SOURCE[0]}")"
DIR="$(readlink -f "${DIR}")"

REMOTE_HOST=https://api-sandbox.acubeapi.com

DIR="$(dirname "${BASH_SOURCE[0]}")"
DIR="$(readlink -f "${DIR}")"

export JWT=$("${DIR}"/getJWT.sh)

curl -X GET -k --no-progress-meter -H "Authorization: bearer $JWT" -H 'Accept: application/json' -H 'Content-Type: application/json' $REMOTE_HOST/verify/company/${1} | jq

0 comments on commit 35502d6

Please sign in to comment.