Resource Hub API/backend service
Usage:
# creates new configuration files for customization...
cp -n .env.defaults .env
cp -n data/vault.example.yml data/vault.yml
# Build and start containers
docker-compose build --progress=plain # creates rhub-api docker image
docker-compose up # starts the apiAdditionally, for convenience, there is a Makefile with some useful commands:
$ make init # create new customized .env and vault.yml files
$ make build # build docker image
$ make build-no-cache # build docker image, ignoring the cache
$ make start # start the orchestration using docker-compose
$ make stop # stop orchestration
$ make test # run unit tests (needs PYTHONPATH or virtualenv set)The API requires other services (database, etc) in order to function.
Some of the configuration comes from environment variables. Docker-compose in
this repository is configured to read variables from the customized .env file.
In the PostgreSQL you just need to create database and user, tables and other object are created automatically on first start.
RHUB_DB_DATABASERHUB_DB_HOSTRHUB_DB_PASSWORDRHUB_DB_PORTRHUB_DB_TYPERHUB_DB_USERNAME
In the HashiCorp Vault create AppRole and policy to limit access to secrets.
VAULT_TYPE=hashicorpVAULT_ADDR- URL, withhttps://VAULT_ROLE_ID- AppRolerole_idVAULT_SECRET_ID- AppRolesecret_id
For development, you can use file vault that stores secrets in plain text YAML
file.
VAULT_TYPE=fileVAULT_PATH- path to YAML file with secrets, see example indata/vault.yml
flask create-user [-g <group-name>] <user-name>The API token is printed only once and then it cannot be retrieved again, so
write it down somewhere (eg. to .env as TOKEN variable).
To create admin account, run the following command:
flask create-user -g rhub-admin adminTokens are passed to the API via Authorization: Basic HTTP header. Username is
__token__ and password is the API token.
curl -u __token__:$TOKEN http://localhost:8081/v0/merequests.get(
'http://localhost:8081/v0/me',
auth=('__token__', os.environ['TOKEN']),
)Credentials are required to allow Tower Webhook Notifications to be received by the API.
Create admin account for use from Tower:
flask create-user -g rhub-admin tower- Install development dependencies (create a clean virtual env first, if you don't have one).
$ pip install -U -e .[dev] -r requirements.txt- SonarQube report. A link for the report will be printed on screen.
$ make scan- pip-audit report. Errors will be printed on screen.
$ tox -e pip_audit- OWASP Dependency-Check report. Report will be at
odc-reports/dependency-check-report.html.
$ bash bin/dependency_check.shIf you want to contribute to our project, you are more then welcome - just check our contributing guide.