Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/setup config test #370

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ COPY --from=backend-build /usr/local/bin/uwsgi /usr/local/bin/uwsgi

# Stage 3.2 - Copy source code
WORKDIR /app
COPY ./bin/wait_for_db.sh /wait_for_db.sh
COPY ./bin/docker_start.sh /start.sh
COPY ./bin/setup_configuration.sh /setup_configuration.sh
RUN mkdir /app/log /app/config

# copy frontend build statics
Expand Down
6 changes: 2 additions & 4 deletions bin/docker_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ uwsgi_threads=${UWSGI_THREADS:-2}

mountpoint=${SUBPATH:-/}

until pg_isready; do
>&2 echo "Waiting for database connection..."
sleep 1
done
# wait for required services
${SCRIPTPATH}/wait_for_db.sh

>&2 echo "Database is up."

Expand Down
10 changes: 10 additions & 0 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# setup initial configuration using environment variables
# Run this script from the root of the repository

#set -e
${SCRIPTPATH}/wait_for_db.sh

src/manage.py migrate
src/manage.py setup_configuration --no-selftest
15 changes: 15 additions & 0 deletions bin/wait_for_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e

# Wait for the database container
# See: https://docs.docker.com/compose/startup-order/
export PGHOST=${DB_HOST:-db}
export PGPORT=${DB_PORT:-5432}

until pg_isready; do
>&2 echo "Waiting for database connection..."
sleep 1
done

>&2 echo "Database is up."
94 changes: 94 additions & 0 deletions docker-compose.config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
version: '3'

services:
# OBJECTTYPES API
db_objecttypes:
image: postgres:12-alpine
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
volumes:
- ./docker-init-db-objecttypes.sql:/docker-entrypoint-initdb.d/init_db.sql
command: postgres -c max_connections=300 -c log_min_messages=LOG

objecttypes:
build: ../objecttypes
environment: &objecttypes-env
- DJANGO_SETTINGS_MODULE=objecttypes.conf.docker
- SECRET_KEY=${SECRET_KEY:-fgv=c0hz&tl*8*3m3893@m+1pstrvidc9e^5@fpspmg%cy$15d}
- DB_HOST=db_objecttypes
- IS_HTTPS=no
- ALLOWED_HOSTS=*
- TWO_FACTOR_FORCE_OTP_ADMIN=no
- TWO_FACTOR_PATCH_ADMIN=no
# setup_configuration env vars
- OBJECTTYPES_DOMAIN=objecttypes:8000
- OBJECTTYPES_ORGANIZATION=ObjectTypes
- OBJECTS_OBJECTTYPES_TOKEN=objects-random-string
- OBJECTS_OBJECTTYPES_PERSON=Objects
- [email protected]
- DEMO_CONFIG_ENABLE=yes
- DEMO_TOKEN=demo-random-string
- DEMO_PERSON=Demo
- [email protected]
ports:
- 8001:8000
depends_on:
objecttypes-init:
condition: service_completed_successfully

objecttypes-init:
build: ../objecttypes
environment: *objecttypes-env
command: /setup_configuration.sh
depends_on:
- db_objecttypes

# OBJECTS API
db:
# NOTE: No persistance storage configured.
# See: https://hub.docker.com/_/postgres/
image: postgis/postgis:12-2.5
environment:
- POSTGRES_USER=objects
- POSTGRES_PASSWORD=objects

objects:
build: .
environment: &objects-env
- DJANGO_SETTINGS_MODULE=objects.conf.docker
- SECRET_KEY=${SECRET_KEY:-1(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg}
- DB_HOST=db
- IS_HTTPS=no
- OBJECTS_SUPERUSER_USERNAME=admin
- OBJECTS_SUPERUSER_PASSWORD=admin
- OBJECTS_SUPERUSER_EMAIL=admin@localhost
- ALLOWED_HOSTS=*
- TWO_FACTOR_FORCE_OTP_ADMIN=no
- TWO_FACTOR_PATCH_ADMIN=no
- NOTIFICATIONS_DISABLED=yes
# setup_configuration env vars
- OBJECTS_DOMAIN=objects:8000
- OBJECTS_ORGANIZATION=Objects
- OBJECTTYPES_API_ROOT=http://objecttypes:8000/api/v2/
- OBJECTS_OBJECTTYPES_TOKEN=objects-random-string
- DEMO_CONFIG_ENABLE=yes
- DEMO_TOKEN=demo-random-string
- DEMO_PERSON=Demo
- [email protected]
ports:
- 8000:8000
depends_on:
objects-init:
condition: service_completed_successfully
volumes:
- media:/app/media # Shared media volume to get access to saved OAS files

objects-init:
build: .
environment: *objects-env
command: /setup_configuration.sh
depends_on:
- db

volumes:
media:
21 changes: 19 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,36 @@ services:

web:
build: .
environment:
environment: &app-env
- DJANGO_SETTINGS_MODULE=objects.conf.docker
- SECRET_KEY=${SECRET_KEY:-1(@f(-6s_u(5fd&1sg^uvu2s(c-9sapw)1era8q&)g)h@cwxxg}
- OBJECTS_SUPERUSER_USERNAME=admin
- OBJECTS_SUPERUSER_PASSWORD=admin
- OBJECTS_SUPERUSER_EMAIL=admin@localhost
- ALLOWED_HOSTS=*
# setup_configuration env vars
- OBJECTS_DOMAIN=web:8000
- OBJECTS_ORGANIZATION=Objects
- OBJECTTYPES_API_ROOT=https://objecttypes.example.com/api/v2/
- OBJECTS_OBJECTTYPES_TOKEN=some-random-string
- DEMO_CONFIG_ENABLE=yes
- DEMO_TOKEN=demo-random-string
- DEMO_PERSON=Demo
- [email protected]
ports:
- 8000:8000
depends_on:
- db
web-init:
condition: service_completed_successfully
volumes:
- media:/app/media # Shared media volume to get access to saved OAS files

web-init:
build: .
environment: *app-env
command: /setup_configuration.sh
depends_on:
- db

volumes:
media:
3 changes: 3 additions & 0 deletions docker-init-db-objecttypes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE USER objecttypes;
CREATE DATABASE objecttypes;
GRANT ALL PRIVILEGES ON DATABASE objecttypes TO objecttypes;
16 changes: 16 additions & 0 deletions docs/admin/authorization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@ fields you can submit the form.
Now the client who has this token can access the objects with the "Boom" object type.

If you want to know how to use Objects API you can follow :ref:`api_usage`


Superuser permissions
----------------------

It's possible to set superuser permissions in Objects API. A client with such permissions
is able to request objects for all objecttypes.

In the admin page of the Objects API go to the Token authorizations" resource and click on
a token, which should have superuser permissions. Check "is superuser" field. Now this token
has read and write permissions for all objects.

.. warning::

Tokens with superuser permissions are not recommended for production. They should be used
only for test and development purposes.
2 changes: 2 additions & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pytz # handle timezones
python-dotenv # environment variables for secrets
python-decouple # processing of envvar configs
jsonschema
furl

# Framework libraries
django~=3.2
Expand All @@ -16,6 +17,7 @@ django-rosetta
maykin-django-two-factor-auth
maykin-django-two-factor-auth[phonenumbers]
mozilla-django-oidc-db
git+https://github.com/maykinmedia/django-setup-configuration.git@feature/1-config-command

# API libraries
djangorestframework
Expand Down
9 changes: 9 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ django==3.2.23
# django-rest-framework-condition
# django-rosetta
# django-sendfile2
# django-setup-configuration
# django-simple-certmanager
# django-solo
# djangorestframework
Expand Down Expand Up @@ -101,6 +102,8 @@ django-rosetta==0.9.8
# via -r requirements/base.in
django-sendfile2==0.7.0
# via django-privates
django-setup-configuration @ git+https://github.com/maykinmedia/django-setup-configuration.git@feature/1-config-command
# via -r requirements/base.in
django-simple-certmanager==1.4.1
# via zgw-consumers
django-solo==2.2.0
Expand Down Expand Up @@ -132,6 +135,8 @@ face==20.1.1
# via glom
faker==8.1.0
# via zgw-consumers
furl==2.1.3
# via -r requirements/base.in
gemma-zds-client==1.0.1
# via
# vng-api-common
Expand Down Expand Up @@ -170,6 +175,8 @@ mozilla-django-oidc==4.0.0
# via mozilla-django-oidc-db
mozilla-django-oidc-db==0.14.1
# via -r requirements/base.in
orderedmultidict==1.0.1
# via furl
oyaml==1.0
# via vng-api-common
packaging==23.2
Expand Down Expand Up @@ -235,8 +242,10 @@ sentry-sdk==1.0.0
six==1.15.0
# via
# django-markup
# furl
# isodate
# jsonschema
# orderedmultidict
# python-dateutil
# qrcode
# requests-mock
Expand Down
11 changes: 11 additions & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ django==3.2.23
# django-rest-framework-condition
# django-rosetta
# django-sendfile2
# django-setup-configuration
# django-simple-certmanager
# django-solo
# djangorestframework
Expand Down Expand Up @@ -142,6 +143,8 @@ django-sendfile2==0.7.0
# via
# -r requirements/base.txt
# django-privates
django-setup-configuration @ git+https://github.com/maykinmedia/django-setup-configuration.git@feature/1-config-command
# via -r requirements/base.txt
django-simple-certmanager==1.4.1
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -193,6 +196,8 @@ faker==8.1.0
# zgw-consumers
freezegun==1.1.0
# via -r requirements/test-tools.in
furl==2.1.3
# via -r requirements/base.txt
gemma-zds-client==1.0.1
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -253,6 +258,10 @@ mozilla-django-oidc==4.0.0
# mozilla-django-oidc-db
mozilla-django-oidc-db==0.14.1
# via -r requirements/base.txt
orderedmultidict==1.0.1
# via
# -r requirements/base.txt
# furl
oyaml==1.0
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -348,8 +357,10 @@ six==1.15.0
# via
# -r requirements/base.txt
# django-markup
# furl
# isodate
# jsonschema
# orderedmultidict
# python-dateutil
# qrcode
# requests-mock
Expand Down
11 changes: 11 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ django==3.2.23
# django-rest-framework-condition
# django-rosetta
# django-sendfile2
# django-setup-configuration
# django-simple-certmanager
# django-solo
# djangorestframework
Expand Down Expand Up @@ -170,6 +171,8 @@ django-sendfile2==0.7.0
# via
# -r requirements/ci.txt
# django-privates
django-setup-configuration @ git+https://github.com/maykinmedia/django-setup-configuration.git@feature/1-config-command
# via -r requirements/ci.txt
django-simple-certmanager==1.4.1
# via
# -r requirements/ci.txt
Expand Down Expand Up @@ -229,6 +232,8 @@ flake8==7.0.0
# via -r requirements/dev.in
freezegun==1.1.0
# via -r requirements/ci.txt
furl==2.1.3
# via -r requirements/ci.txt
gemma-zds-client==1.0.1
# via
# -r requirements/ci.txt
Expand Down Expand Up @@ -300,6 +305,10 @@ mozilla-django-oidc-db==0.14.1
# via -r requirements/ci.txt
mypy-extensions==0.4.3
# via black
orderedmultidict==1.0.1
# via
# -r requirements/ci.txt
# furl
oyaml==1.0
# via
# -r requirements/ci.txt
Expand Down Expand Up @@ -417,8 +426,10 @@ six==1.15.0
# via
# -r requirements/ci.txt
# django-markup
# furl
# isodate
# jsonschema
# orderedmultidict
# python-dateutil
# qrcode
# requests-mock
Expand Down
Loading
Loading