-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
392dc8e
commit 0fcd41c
Showing
3 changed files
with
120 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,7 @@ GCS_CASE_MANAGER_BUCKET="case-manager-tokyo-country-381508" | |
# The frontend sign | ||
FIREBASE_AUTH_EMULATOR_HOST="localhost:9099" | ||
|
||
# When using firebase emulator, JWT Token are issued for the audience 'tokyo-country-381508'. I don't know why. | ||
# I would like to change this reference to the staging project but I can't right now. | ||
# When using firebase emulator, JWT Token are issued for the audience 'tokyo-country-381508' which is the staging project. | ||
GOOGLE_CLOUD_PROJECT="tokyo-country-381508" | ||
|
||
MARBLE_ADMIN_EMAIL=[email protected] | ||
|
@@ -26,5 +25,5 @@ [email protected] | |
FAKE_AWS_S3=true | ||
FAKE_GCS=true | ||
|
||
SEGMENT_WRITE_KEY=Su1jhgliqOiVqe0G1T0jSOQ09OZlKdDX | ||
SEGMENT_WRITE_KEY= | ||
SENTRY_DSN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
Elastic License 2.0 | ||
|
||
URL: <https://www.elastic.co/licensing/elastic-license> | ||
|
||
## Acceptance | ||
|
||
By using the software, you agree to all of the terms and conditions below. | ||
|
||
## Copyright License | ||
|
||
The licensor grants you a non-exclusive, royalty-free, worldwide, | ||
non-sublicensable, non-transferable license to use, copy, distribute, make | ||
available, and prepare derivative works of the software, in each case subject to | ||
the limitations and conditions below. | ||
|
||
## Limitations | ||
|
||
You may not provide the software to third parties as a hosted or managed | ||
service, where the service provides users with access to any substantial set of | ||
the features or functionality of the software. | ||
|
||
You may not move, change, disable, or circumvent the license key functionality | ||
in the software, and you may not remove or obscure any functionality in the | ||
software that is protected by the license key. | ||
|
||
You may not alter, remove, or obscure any licensing, copyright, or other notices | ||
of the licensor in the software. Any use of the licensor’s trademarks is subject | ||
to applicable law. | ||
|
||
## Patents | ||
|
||
The licensor grants you a license, under any patent claims the licensor can | ||
license, or becomes able to license, to make, have made, use, sell, offer for | ||
sale, import and have imported the software, in each case subject to the | ||
limitations and conditions in this license. This license does not cover any | ||
patent claims that you cause to be infringed by modifications or additions to | ||
the software. If you or your company make any written claim that the software | ||
infringes or contributes to infringement of any patent, your patent license for | ||
the software granted under these terms ends immediately. If your company makes | ||
such a claim, your patent license ends immediately for work on behalf of your | ||
company. | ||
|
||
## Notices | ||
|
||
You must ensure that anyone who gets a copy of any part of the software from you | ||
also gets a copy of these terms. | ||
|
||
If you modify the software, you must include in any modified copies of the | ||
software prominent notices stating that you have modified the software. | ||
|
||
## No Other Rights | ||
|
||
These terms do not imply any licenses other than those expressly granted in | ||
these terms. | ||
|
||
## Termination | ||
|
||
If you use the software in violation of these terms, such use is not licensed, | ||
and your licenses will automatically terminate. If the licensor provides you | ||
with a notice of your violation, and you cease all violation of this license no | ||
later than 30 days after you receive that notice, your licenses will be | ||
reinstated retroactively. However, if you violate these terms after such | ||
reinstatement, any additional violation of these terms will cause your licenses | ||
to terminate automatically and permanently. | ||
|
||
## No Liability | ||
|
||
_As far as the law allows, the software comes as is, without any warranty or | ||
condition, and the licensor will not be liable to you for any damages arising | ||
out of these terms or the use or nature of the software, under any kind of | ||
legal claim._ | ||
|
||
## Definitions | ||
|
||
The **licensor** is the entity offering these terms, and the **software** is the | ||
software the licensor makes available under these terms, including any portion | ||
of it. | ||
|
||
**you** refers to the individual or entity agreeing to these terms. | ||
|
||
**your company** is any legal entity, sole proprietorship, or other kind of | ||
organization that you work for, plus all organizations that have control over, | ||
are under the control of, or are under common control with that | ||
organization. **control** means ownership of substantially all the assets of an | ||
entity, or the power to direct its management and policies by vote, contract, or | ||
otherwise. Control can be direct or indirect. | ||
|
||
**your licenses** are all the licenses granted to you for the software under | ||
these terms. | ||
|
||
**use** means anything you do with the software requiring one of your licenses. | ||
|
||
**trademark** means trademarks, service marks, and similar rights. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,18 @@ This repo is the Marble backend implementation: | |
|
||
- 1 single Go app | ||
- Postgres DB | ||
- PGAdmin (to view the DB content) | ||
|
||
## Getting Started | ||
|
||
### Requirements | ||
|
||
[Install Go](https://go.dev/doc/install) on your laptop. For now, there is no fixed version in the project, but according to `go.mod` we all use a `1.21` version. | ||
[Install Go](https://go.dev/doc/install) on your laptop (see the version in go.mod). | ||
|
||
> NB: To handle different version, you can look at [Managing Go installations](https://go.dev/doc/manage-install) or use a version manager tool like [asdf](https://github.com/kennyp/asdf-golang) | ||
> NB: To handle different versions, you can look at [Managing Go installations](https://go.dev/doc/manage-install) or use a version manager tool like [asdf](https://github.com/kennyp/asdf-golang) | ||
You may also need to [install the gcloud CLI](https://cloud.google.com/sdk/docs/install) in order to interact with deployed environments. | ||
|
||
> NB: the GCP project is `tokyo-country-381508` (you may need to ask for permissions) | ||
> NB: the staging GCP project is `tokyo-country-381508`- you may need to access it to test some features that depend on cloud infrastructure (you may need to ask for permissions). | ||
### Deployment | ||
|
||
|
@@ -39,8 +38,8 @@ Then start it using: | |
firebase --project staging emulators:start --import=./firebase-local-data | ||
``` | ||
|
||
Connect in the backoffice using: `[email protected]` | ||
Connect in the frontend using: `[email protected]` | ||
Connect in the backoffice using: `[email protected]` (marble admin user created by default) | ||
Connect in the frontend using: `[email protected]` (admin of an organization created by default) | ||
|
||
#### How to add data to ./firebase-local-data | ||
|
||
|
@@ -50,81 +49,43 @@ Connect in the frontend using: `[email protected]` | |
- Exit the emulator | ||
- commit | ||
|
||
#### Export local data | ||
|
||
### Lauch the project | ||
|
||
#### Docker | ||
#### Setup the DB | ||
|
||
`docker compose up -d --build` : build the app container, and launches the stack (in deamon mode) | ||
Creates a `marble-backend_postgres-db` volume to store PG data. | ||
You should first start the local DB to run the backend server: | ||
|
||
`docker compose logs -f -t marble-backend db` shows the logs for the app and PG. useful to filter out annoying PGAdmin logs | ||
`docker compose up -d` : launch the postgres DB used by the backend. | ||
Creates a `marble-backend_postgres-db` volume to store PG data. | ||
|
||
`docker volume rm marble-backend_postgres-db` deletes the PG volume, useful to reset the app to a known state | ||
|
||
In practice, this single-line will delete the stack and create a new one: | ||
`docker compose down && docker volume rm marble-backend_postgres-db && docker compose up -d --build && docker compose logs -f -t marble-backend db` | ||
`ctrl-C` to detach from the logs output | ||
`docker compose down && docker volume rm marble-backend_postgres-db && docker compose up -d` | ||
|
||
#### Local (VS Code) | ||
|
||
You can choose to launch the application locally, using the provided debug task (especially usefull to dev, as the task launch a debugger): | ||
The recommended way to run the backend is to run `Migrate and Launch (.env.local)` in the VSCode "Run and debug" tab (especially usefull to dev, as the task launch a debugger): | ||
|
||
- Start a DB using docker compose | ||
- Lauch the debug task `Migrate and Launch (.env.local)` (VS Code) that will migrate the DB and start the server. | ||
- Three other debug tasks exist that execute the actions running as batches on the cloud: batch data ingestion, scheduling of scenarios, execution of scheduled scenarios. | ||
|
||
- Start a DB using docker (you can inspire from the existing docker file) | ||
- Create your local `.env` using the provided `.env.tmpl`. | ||
- To create a `AUTHENTICATION_JWT_SIGNING_KEY` run `openssl genrsa -out signing.pem 2048` and save the value as a one liner using `\n` for line breaks | ||
- Lauch the debug task (VS Code) | ||
You can also run the go service directly in the terminal. | ||
|
||
### DB Seed and reset | ||
- Create your local `.env` using the provided `.env.local`. | ||
- To create a `AUTHENTICATION_JWT_SIGNING_KEY` run `openssl genrsa -out signing.pem 2048` and save the value as a one liner using `\n` for line breaks, or take the one from `.env.local` - you may need to work out how to export multi-line env variables. | ||
- export your `.env` file | ||
- run `go run .` from the root folder | ||
|
||
- execute the program with flags -migrations to run migrations, -wipe to reset the DB to an empty state, -server to start the server | ||
- in dev or staging environments, -server additionally runs the seed script from pg_repository/seed.go. | ||
- in the cloud staging environment, two Cloud Run jobs exist to take the migrations/wipe actions | ||
### DB Seed and migrations | ||
|
||
- execute the program with flags -migrations to run migrations, -server to start the server | ||
- in development environment, -server additionally runs the SeedZorgOrganization usecase script from usecases/seed_usecase. | ||
- in the cloud staging environment, a dedicated Cloud Run jobs exists that runs the migrations on every new deployment | ||
|
||
## API | ||
|
||
The rooting of the application is defined inside `api/routes.go` | ||
|
||
See [our API docs](https://docs.checkmarble.com/reference/introduction-1) for public facing reference or the Open API Specification for internal endpoints on Postman. | ||
|
||
## curl calls | ||
|
||
`POST` a decision. Get TokenID and ScenarioId from startup log (cf `seed.go`). | ||
Token value is hardcoded to `token12345` for convenience. | ||
|
||
```sh | ||
// Initialise variables in your shell | ||
SCENARIO_ID=... | ||
REFRESH_TOKEN="token12345" | ||
``` | ||
|
||
Get an access token by calling | ||
|
||
```sh | ||
TOKEN=$(curl -XPOST -H "Content-type: application/json" -H "X-API-Key: token12345" http://localhost:8080/token) | ||
``` | ||
|
||
Beware that the implementation of getting the different types of access tokens is not finished yet, and you may encounter authorization errors on the various endpoints. | ||
|
||
```sh | ||
curl -XPOST -H "Content-type: application/json" -H "Authorization: Bearer $TOKEN" -d "$(jq -n --arg scenario_id "$SCENARIO_ID" '{"scenario_id": $scenario_id, "trigger_object":{"type": "tx", "amount": 5.0} }')" 'http://localhost:8080/decisions' | ||
``` | ||
|
||
display result, store created id in .last_id file | ||
|
||
```sh | ||
curl -XPOST -H "Content-type: application/json" -H "Authorization: Bearer $TOKEN" -d "$(jq -n --arg scenario_id "$SCENARIO_ID" '{"scenario_id": $scenario_id, "trigger_object":{"type": "tx", "amount": 5.0} }')" 'http://localhost:8080/decisions' | tee >(jq) | jq -r '.id' > .last_id | ||
``` | ||
|
||
`GET` a decision. Replace the Id by one you created. | ||
|
||
```sh | ||
curl -XGET -H "Content-type: application/json" -H "Authorization: Bearer $TOKEN" 'http://localhost:8080/decisions/9a2b5c9d-ac12-45b3-8f52-0eda979d5853' | ||
``` | ||
|
||
use .last_id file to find id just created | ||
|
||
```sh | ||
curl -XGET -H "Content-type: application/json" -H "Authorization: Bearer $TOKEN" "http://localhost:8080/decisions/$(cat .last_id)" | jq | ||
``` |