Skip to content

The safe-config-service is a service that provides configuration information in the context of the Safe clients environment

License

Notifications You must be signed in to change notification settings

telosnetwork/safe-config-service

 
 

Repository files navigation

safe-config-service

Coverage Status

The safe-config-service is a service that provides configuration information in the context of the Safe clients environment (eg.: list of available safe apps and chain metadata).

Requirements

Setup

1. Configuration

The environment variables are set via the .env file. The configuration in .env.example is meant to be used only for development. You can copy it and adjust it to your development needs (refer to the file for the explanation about each environment variable).

cp .env.example .env

Important: It is recommended to set sensitive fields (like passwords) and adjust other parameters for your production environment needs. The .env.sample configuration shouldn't be used for any production deployment.

2. Running the service image

The project relies on nginx and postgres services. If you are running this locally this is already set in the docker-compose.yml file:

docker compose up

The service will then be available under localhost:$NGINX_HOST_PORT.

3. Create an admin user

The admin interface of the service is available under http://<host>:<NGINX_HOST_PORT>/admin but you need to have an admin registered before you are able to access the panel.

To create an admin user (assuming that the name of the web container is safe-config-service-web-1):

docker exec -it safe-config-service-web-1 /bin/bash
python src/manage.py createsuperuser

And then just follow the prompts in order to create an admin user. Further users (admin or not) can be created from the admin interface itself.

Development

If you wish to develop locally without running an image for the Django service you can do the following:

  1. Install the required Python dependencies. Eg.: With a python virtual environment:
python -m venv venv # creates a virtual environment venv in the local directory
source venv/bin/activate
pip install -r requirements-dev.txt
  1. Export the environment variables of .env to the local shell/environment (some shells might require you to allexport before doing that)
source .env
  1. Run a PostgreSQL database locally. Check your .env to see the user, host and port details which are expected by the Django application. You can also run the bundled Postrges image with Docker.
docker-compose up -d db # postgres will be listening on port $POSTGRES_PORT
  1. Launch the service:
python src/manage.py runserver

Development Tools

The project uses a variety of tools to make sure that the styling, health and correctness are validated on each change. These tools are available via requirements-dev.txt so to have them available in your virtual environment run:

pip install -r requirements-dev.txt

Testing

Pytest is used to run the available tests in the project. Some of these tests validate the integration with the database so having one running is required (you can have one running in the background with docker compose up -d db). From the project root:

pytest src

Code Style Formatter and Linter

Black, Flake8 and isort are the tools used to validate the style of the changes being pushed. You can refer to the documentation of these tools to check how to integrate them with your editor/IDE.

isort --profile black src # sorts imports according to the isort spec with a profile compatible with Black
black src # formats the files in the src folder using Black
flake8 src # runs flake8 Linter in the src folder

There's also a pre-commit hook that you can install locally via pre-commit so that it formats the files changed on each commit automatically:

pre-commit install # installs commit hook under .git/hooks/pre-commit
git commit # Initially this can take a couple minutes to setup the environment (which will be reused in following commits)

About

The safe-config-service is a service that provides configuration information in the context of the Safe clients environment

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 96.6%
  • Shell 3.0%
  • Dockerfile 0.4%