A small Python-based example of how to create a Badrap app that:
- Offers an UI to display the state of an installation.
- Updates the state of an installation based on UI input.
- Collects the assets of the owner of the installation (i.e. the user that has installed the app).
Note: The development environment works on MacOS and Linux. You may encounter problems with Windows.
Launch the development server that will restart on each code change. Docker Compose will also launch the API emulator that acts as a frontend to the Python service.
$ docker-compose up --build
If everything went well, open the API emulator frontend by directing your browser to http://localhost:4004. This creates a new installation (with the name 0
) and redirects the browser to show the app UI for the newly created installation. Note that the installation id that the app sees is a random UUID, separate from the installation name visible in the browser.
docker-compose run --rm app python -m app.collector
You can use the /i/{name}/external_assets
endpoints to feed external assets
for an installation ({name}
is the installation name visible in your
browser location bar, e.g. 0
).
"External assets" in this context mean assets that the app itself hasn't created - e.g. assets that a Badrap user would have manually claimed. External assets aren't currently visible in the emulator, and they're only accessible & modifiable through APIs.
Add an external asset while the emulator is running for the installation name 0
:
curl -H "Content-Type: application/json" -d '{ "type": "ip", "value": "1.2.3.4" }' http://localhost:4004/i/0/external_assets
Possible values for key "type"
are "ip"
, "domain"
and "email"
. The value for key "value"
has to be an IPv4/6 address, a domain name or an email address, respectively.
To list all external assets:
curl http://localhost:4004/i/0/external_assets
To delete a certain external asset with the id {id}
:
curl -X DELETE http://localhost:4004/i/0/external_assets/{id}
$ docker build -t app .
API_URL
should point to the Badrap API endpoint that the app talks with.API_TOKEN
should be the Badrap API token that has been generated for the app.
$ docker run --rm -e API_URL=https://badrap.io/api -e API_TOKEN=123456789 -p 5000:5000 app
$ docker run --rm -e API_URL=https://badrap.io/api -e API_TOKEN=123456789 app python -m app.collector