Metadata-Version: 2.1
Name: threat-db
Version: 0.2.0
Summary: A graphql server for vulnerabilities powered by dgraph
License: Apache-2.0
Author: Team ngcloudsec
Author-email: cloud@ngcloud.io
Requires-Python: >=3.7,<3.11
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Security
Classifier: Topic :: Utilities
Requires-Dist: flask (>=2.2.2,<3.0.0)
Requires-Dist: flask-jwt-extended (>=4.4.4,<5.0.0)
Requires-Dist: gql[all] (>=3.4.0,<4.0.0)
Requires-Dist: grpcio (>=1.51.1,<2.0.0)
Requires-Dist: itsdangerous (>=2.1.2,<3.0.0)
Requires-Dist: orjson (>=3.8.3,<4.0.0)
Requires-Dist: packageurl-python (>=0.10.4,<0.11.0)
Requires-Dist: protobuf (==3.20.1)
Requires-Dist: pydgraph (>=21.3.2,<22.0.0)
Requires-Dist: rich (>=12.6.0,<13.0.0)
Requires-Dist: uwsgi (>=2.0.21,<3.0.0)
Description-Content-Type: text/markdown

# Introduction

## Development setup

```
git clone https://github.com/ngcloudsec/threat-db.git
cd threat-db
mkdir -p $HOME/dgraph $HOME/threatdb_data_dir
docker compose up
```

This would start a threat db api server (PORT: 9000) and an instance of [dgraph](https://dgraph.io) standalone (PORTS: 8080, 9080).

## Create schemas

To create the schemas and the first administrator user.

```
git clone https://github.com/ngcloudsec/threat-db.git
pip install poetry
poetry install
poetry run threat_db_admin --init --dgraph-host localhost:9080 --graphql-host http://localhost:8080/graphql
poetry run threat_db_admin --create-root-user --dgraph-host localhost:9080 --graphql-host http://localhost:8080/graphql
```

Copy the user id and password from the logs.

## Import data

```
threat_db --data-dir
```

When invoked with docker compose, any json file present in the directory `THREATDB_DATA_DIR` would be imported automatically.

## Rest API

### Generate access token

```
curl -X POST http://0.0.0.0:9000/login -d "username=user id&password=password" -H "Content-Type: application/json"
```

Useful one-liner for automation

```
export ACCESS_TOKEN=$(curl -X POST http://0.0.0.0:9000/login -d '{"username":"username","password":"password"}' -H "Content-Type: application/json" | jq -r '.access_token')
```

```
curl http://0.0.0.0:9000/healthcheck
```

### whoami

```
curl http://0.0.0.0:9000/whoami -H "Authorization: Bearer $ACCESS_TOKEN"
```

### Import data

```
curl -F 'file=@/tmp/bom.json' http://0.0.0.0:9000/import -H "Authorization: Bearer $ACCESS_TOKEN"
```

