Skip to content

Commit

Permalink
Issue/django setup configuration tokens (#135)
Browse files Browse the repository at this point in the history
* [maykinmedia/objects-api#481] Fix requirements

* [maykinmedia/objects-api#481] Move config folder in setup_configuration

* [maykinmedia/objects-api#481] Config in settings

* [maykinmedia/objects-api#481] Update model with migrations

* [maykinmedia/objects-api#481] Black

* [maykinmedia/objects-api#481] Create test_authenticaton tests

* [maykinmedia/objects-api#481] Create test_validators

* [maykinmedia/objects-api#481] Fix models and migrations

* [maykinmedia/objects-api#481] Fix tests

* [maykinmedia/objects-api#481] Delete utils

* [maykinmedia/objects-api#481] Add factory

* [maykinmedia/objects-api#481] Create step and model

* [maykinmedia/objects-api#481] Create tests

* [maykinmedia/objects-api#481] Fix old tests

* [maykinmedia/objects-api#481] Update command line

* [maykinmedia/objects-api#481] Remove old settings

* [maykinmedia/objects-api#481] Add configuration file for docker

* [maykinmedia/objects-api#481] Fix docker-compose

* [maykinmedia/objects-api#481] Flake8

* [maykinmedia/objects-api#481] Create command tests and delete old tests

* [maykinmedia/objects-api#481] Fix setup_configuration

* [maykinmedia/objects-api#481] Fix requirements

* [maykinmedia/objects-api#481] Fix requirements

* [maykinmedia/objects-api#481] Fix data.yaml

* [maykinmedia/objects-api#481] Fix base settings

* [maykinmedia/objects-api#481] Fix docker-compose file

* [maykinmedia/objects-api#481] Replace build_step_config_from_sources with execute_single_step

* [maykinmedia/objects-api#481] Fix Sites tests

* [maykinmedia/objects-api#481] Improve Site tests

* [maykinmedia/objects-api#481] Improve Token tests

* [maykinmedia/objects-api#481] Black

* [maykinmedia/objects-api#481] Add test for empty token

* [maykinmedia/objects-api#481] Copy migration test

* [maykinmedia/objects-api#481] Fix migration tests

* [maykinmedia/objects-api#481] Fix django-setup-configuration version in base.in

* [maykinmedia/objects-api#481] Fix docstring

* [maykinmedia/objects-api#481] Change file_name

* [maykinmedia/objects-api#481] Fix name objecttypes_sites_config_enable

* [maykinmedia/objects-api#481] Fix name objecttypes_sites_config_enable 2

* [maykinmedia/objects-api#481] Remove tests for call_command

* [maykinmedia/objects-api#481] Change env variables in docker-compose

* [maykinmedia/objects-api#481] Split in directories

* [maykinmedia/objects-api#481] Fix paths

* [maykinmedia/objects-api#481] Update name for SitesConfiguration

* [maykinmedia/objects-api#481] Update namespace for Site

* [maykinmedia/objects-api#481] Update namespace for TokenAuthConfiguration

* [maykinmedia/objects-api#481] Remove Field from ConfigurationModel

* [maykinmedia/objects-api#481] Update INSTALL.rst

* [maykinmedia/objects-api#481] Fix tests

* [maykinmedia/objects-api#481] Remove unnecessary volumes in docker

* [maykinmedia/objects-api#481] Change namespace

* [maykinmedia/objects-api#481] Change namespace in file

* [maykinmedia/objects-api#481] Change namespace zgw_tokens_tokenauth

* Revert "[maykinmedia/objects-api#481] Change namespace zgw_tokens_tokenauth"

This reverts commit a2c9c59.

* [maykinmedia/objects-api#481] Fix unnecessary "loop" for one element

* [maykinmedia/objects-api#481] Fix INSTALL.rst

* [maykinmedia/objects-api#481] Add link to repo in INSTALL.rst

* [maykinmedia/objects-api#481] Fix token tests

* [maykinmedia/objects-api#481] Change name validate_no_whitespace

* [maykinmedia/objects-api#481] Remove unused validation control

* [maykinmedia/objects-api#481] Black

* [maykinmedia/objects-api#481] Add warning if list is empty

* [maykinmedia/objects-api#481] Add validate_no_empty + tests
  • Loading branch information
danielmursa-dev authored Dec 13, 2024
1 parent b3958cd commit 6fb512e
Show file tree
Hide file tree
Showing 41 changed files with 1,094 additions and 534 deletions.
13 changes: 13 additions & 0 deletions INSTALL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,16 @@ There are no specific commands for the project. See
``python src/manage.py --help``.

.. _Django framework commands: https://docs.djangoproject.com/en/dev/ref/django-admin/#available-commands

Configuration (CLI)
===================

After deploying Objecttypes API, they need to be configured to be fully functional.
The command line tool ``setup_configuration`` assist with this configuration.

You can get the full command documentation with:

See `Django Setup Configuration`_ for all documentation, or type
``python src/manage.py setup_configuration --help``.

.. _Django Setup Configuration: https://github.com/maykinmedia/django-setup-configuration
11 changes: 7 additions & 4 deletions bin/setup_configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
# setup initial configuration using environment variables
# Run this script from the root of the repository

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

src/manage.py migrate
if [[ "${RUN_SETUP_CONFIG,,}" =~ ^(true|1|yes)$ ]]; then
# wait for required services
${SCRIPTPATH}/wait_for_db.sh

src/manage.py setup_configuration --no-selftest
src/manage.py migrate
src/manage.py setup_configuration --yaml-file setup_configuration/data.yaml
fi
48 changes: 26 additions & 22 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ services:
db:
image: postgres:12-alpine
environment:
- POSTGRES_USER=objecttypes
- POSTGRES_PASSWORD=objecttypes
POSTGRES_USER: objecttypes
POSTGRES_PASSWORD: objecttypes
command: postgres -c max_connections=300 -c log_min_messages=LOG

redis:
Expand All @@ -13,33 +13,37 @@ services:
image: maykinmedia/objecttypes-api:latest
build: .
environment: &app-env
- DB_USER=objecttypes
- DB_PASSWORD=objecttypes
- DJANGO_SETTINGS_MODULE=objecttypes.conf.docker
- SECRET_KEY=${SECRET_KEY:-fgv=c0hz&tl*8*3m3893@m+1pstrvidc9e^5@fpspmg%cyf15d}
- ALLOWED_HOSTS=*
- CACHE_DEFAULT=redis:6379/0
- CACHE_AXES=redis:6379/0
- DISABLE_2FA=yes
- SUBPATH=${SUBPATH:-/}
# setup_configuration env vars
- SITES_CONFIG_ENABLE=yes
- OBJECTTYPES_DOMAIN=web:8000
- OBJECTTYPES_ORGANIZATION=ObjectTypes
- OBJECTS_OBJECTTYPES_CONFIG_ENABLE=yes
- OBJECTS_OBJECTTYPES_TOKEN=some-random-string
- OBJECTS_OBJECTTYPES_PERSON=Some Person
- [email protected]
DB_USER: objecttypes
DB_PASSWORD: objecttypes
DJANGO_SETTINGS_MODULE: objecttypes.conf.docker
SECRET_KEY: ${SECRET_KEY:-fgv=c0hz&tl*8*3m3893@m+1pstrvidc9e^5@fpspmg%cyf15d}
ALLOWED_HOSTS: '*'
CACHE_DEFAULT: redis:6379/0
CACHE_AXES: redis:6379/0
DISABLE_2FA: yes
SUBPATH: ${SUBPATH:-/}
volumes:
- log:/app/log
ports:
- 8000:8000
depends_on:
web-init:
condition: service_completed_successfully

web-init:
image: maykinmedia/objecttypes-api:latest
build: .
environment: *app-env
environment:
<<: *app-env
#
# Django-setup-configuration
RUN_SETUP_CONFIG: ${RUN_SETUP_CONFIG:-true}
command: /setup_configuration.sh
volumes:
- log:/app/log
- ./docker/setup_configuration:/app/setup_configuration
depends_on:
- db
- db

volumes:
db:
log:
16 changes: 16 additions & 0 deletions docker/setup_configuration/data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
tokenauth_config_enable: true
tokenauth:
items:
- identifier: token-1
token: 18b2b74ef994314b84021d47b9422e82b685d82f
contact_person: Person 1
email: [email protected]
organization: Organization 1
application: Application 1
administration: Administration 1

sites_config_enable: true
sites_config:
items:
- domain: example.com
name: example
2 changes: 1 addition & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ furl
# Framework libraries
django-jsonsuit
sharing-configs
django-setup-configuration
django-setup-configuration>=0.4.0

# API libraries
drf-nested-routers
25 changes: 19 additions & 6 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
amqp==5.1.1
# via kombu
annotated-types==0.7.0
# via pydantic
ape-pie==0.1.0
# via
# commonground-api-common
Expand Down Expand Up @@ -154,7 +156,7 @@ django-sendfile2==0.7.0
# via django-privates
django-sessionprofile==3.0.0
# via open-api-framework
django-setup-configuration==0.1.0
django-setup-configuration==0.4.0
# via
# -r requirements/base.in
# open-api-framework
Expand Down Expand Up @@ -193,9 +195,7 @@ drf-nested-routers==0.94.1
# -r requirements/base.in
# commonground-api-common
drf-spectacular[sidecar]==0.27.2
# via
# drf-spectacular
# open-api-framework
# via open-api-framework
drf-spectacular-sidecar==2024.7.1
# via drf-spectacular
drf-yasg==1.21.7
Expand Down Expand Up @@ -266,6 +266,14 @@ psycopg2==2.9.9
# via open-api-framework
pycparser==2.21
# via cffi
pydantic==2.9.2
# via
# django-setup-configuration
# pydantic-settings
pydantic-core==2.23.4
# via pydantic
pydantic-settings[yaml]==2.6.1
# via django-setup-configuration
pyjwt==2.7.0
# via
# commonground-api-common
Expand All @@ -283,16 +291,19 @@ python-dateutil==2.8.2
python-decouple==3.8
# via open-api-framework
python-dotenv==1.0.0
# via open-api-framework
# via
# open-api-framework
# pydantic-settings
pytz==2023.3
# via
# drf-yasg
# flower
pyyaml==6.0
pyyaml==6.0.2
# via
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
qrcode==6.1
# via django-two-factor-auth
redis==4.5.5
Expand Down Expand Up @@ -330,6 +341,8 @@ tornado==6.4.1
typing-extensions==4.11.0
# via
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# zgw-consumers
tzdata==2024.1
# via celery
Expand Down
27 changes: 23 additions & 4 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ amqp==5.1.1
# via
# -r requirements/base.txt
# kombu
annotated-types==0.7.0
# via
# -r requirements/base.txt
# pydantic
ape-pie==0.1.0
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -238,7 +242,7 @@ django-sessionprofile==3.0.0
# via
# -r requirements/base.txt
# open-api-framework
django-setup-configuration==0.1.0
django-setup-configuration==0.4.0
# via
# -r requirements/base.txt
# open-api-framework
Expand All @@ -258,7 +262,6 @@ django-solo==2.0.0
django-two-factor-auth[phonenumberslite,webauthn]==1.16.0
# via
# -r requirements/base.txt
# django-two-factor-auth
# maykin-2fa
django-webtest==1.9.10
# via -r requirements/test-tools.in
Expand Down Expand Up @@ -293,7 +296,6 @@ drf-nested-routers==0.94.1
drf-spectacular[sidecar]==0.27.2
# via
# -r requirements/base.txt
# drf-spectacular
# open-api-framework
drf-spectacular-sidecar==2024.7.1
# via
Expand Down Expand Up @@ -448,6 +450,19 @@ pycparser==2.21
# via
# -r requirements/base.txt
# cffi
pydantic==2.9.2
# via
# -r requirements/base.txt
# django-setup-configuration
# pydantic-settings
pydantic-core==2.23.4
# via
# -r requirements/base.txt
# pydantic
pydantic-settings[yaml]==2.6.1
# via
# -r requirements/base.txt
# django-setup-configuration
pyflakes==3.2.0
# via flake8
pyjwt==2.7.0
Expand Down Expand Up @@ -481,17 +496,19 @@ python-dotenv==1.0.0
# via
# -r requirements/base.txt
# open-api-framework
# pydantic-settings
pytz==2023.3
# via
# -r requirements/base.txt
# drf-yasg
# flower
pyyaml==6.0
pyyaml==6.0.2
# via
# -r requirements/base.txt
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
# vcrpy
qrcode==6.1
# via
Expand Down Expand Up @@ -551,6 +568,8 @@ typing-extensions==4.11.0
# via
# -r requirements/base.txt
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# zgw-consumers
tzdata==2024.1
# via
Expand Down
27 changes: 23 additions & 4 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ amqp==5.1.1
# via
# -r requirements/base.txt
# kombu
annotated-types==0.7.0
# via
# -r requirements/base.txt
# pydantic
ape-pie==0.1.0
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -249,7 +253,7 @@ django-sessionprofile==3.0.0
# via
# -r requirements/base.txt
# open-api-framework
django-setup-configuration==0.1.0
django-setup-configuration==0.4.0
# via
# -r requirements/base.txt
# open-api-framework
Expand All @@ -269,7 +273,6 @@ django-solo==2.0.0
django-two-factor-auth[phonenumberslite,webauthn]==1.16.0
# via
# -r requirements/base.txt
# django-two-factor-auth
# maykin-2fa
django-webtest==1.9.10
# via -r requirements/test-tools.in
Expand Down Expand Up @@ -308,7 +311,6 @@ drf-nested-routers==0.94.1
drf-spectacular[sidecar]==0.27.2
# via
# -r requirements/base.txt
# drf-spectacular
# open-api-framework
drf-spectacular-sidecar==2024.7.1
# via
Expand Down Expand Up @@ -470,6 +472,19 @@ pycparser==2.21
# via
# -r requirements/base.txt
# cffi
pydantic==2.9.2
# via
# -r requirements/base.txt
# django-setup-configuration
# pydantic-settings
pydantic-core==2.23.4
# via
# -r requirements/base.txt
# pydantic
pydantic-settings[yaml]==2.6.1
# via
# -r requirements/base.txt
# django-setup-configuration
pyflakes==3.0.1
# via flake8
pygments==2.15.1
Expand Down Expand Up @@ -507,17 +522,19 @@ python-dotenv==1.0.0
# via
# -r requirements/base.txt
# open-api-framework
# pydantic-settings
pytz==2023.3
# via
# -r requirements/base.txt
# drf-yasg
# flower
pyyaml==6.0
pyyaml==6.0.2
# via
# -r requirements/base.txt
# drf-spectacular
# drf-yasg
# oyaml
# pydantic-settings
# vcrpy
qrcode==6.1
# via
Expand Down Expand Up @@ -601,6 +618,8 @@ typing-extensions==4.11.0
# via
# -r requirements/base.txt
# mozilla-django-oidc-db
# pydantic
# pydantic-core
# zgw-consumers
tzdata==2024.1
# via
Expand Down
Loading

0 comments on commit 6fb512e

Please sign in to comment.