Setup user app in other service
Requirements
You need to add the following to your requirements.txt
file:
txt
git+https://github.com/MATHEMATIC-STD/django_user_app.git
git+https://github.com/MATHEMATIC-STD/django_exchange_app.git@1.1.0
Keep the frozen version of the
django_exchange_app
.
Exchange is used to consume events, of the users, like login, create, update etc.
bash
pip install -r requirements.txt
Settings
Add the following to your settings.py
file:
python
INSTALLED_APPS = [
...
"django.contrib.auth",
"graphql_jwt",
'user_app',
'exchange_app',
...
]
...
USER = {
"USER_INTERFACES": [],
}
SSO_URL = config("SSO_URL")
SSO_USERNAME = config("SSO_USERNAME")
SSO_PASSWORD = config("SSO_PASSWORD")
HEALTH_CHECK = {
"CHECKS": [
"user_app.health_check.sso.SSOCheck",
"user_app.health_check.user_synch.UsersSyncCheck",
"user_app.health_check.user_synch.GroupsSyncCheck",
"user_app.health_check.user_synch.AssignationsSyncCheck",
"exchange_app.health_check.rabbitmq.RabbitmqPikaCheck",
],
"SSO_URL": SSO_URL,
"SSO_USERNAME": SSO_USERNAME,
"SSO_PASSWORD": SSO_PASSWORD,
}
AUTHENTICATION_BACKENDS = [
"user_app.backends.AuthTokenBackend",
"django.contrib.auth.backends.ModelBackend",
]
...
GRAPHENE = {
"ATOMIC_MUTATIONS": True,
"RELAY_CONNECTION_MAX_LIMIT": None,
"SCHEMA": "api.schema.schema",
"EXECUTION_CONTEXT": "graphql_framework.execution_context.ExecutionContext",
"MIDDLEWARE": (
(["graphene_django.debug.DjangoDebugMiddleware"] if DEBUG else [])
+ [
"user_app.middlewares.UserLoaderMiddleware",
"api.middlewares.LoaderMiddleware",
"graphql_jwt.middleware.JSONWebTokenMiddleware",
]
),
}
GRAPHQL_JWT = {}
SIMPLE_JWT = {
"AUTH_HEADER_TYPES": ("Bearer", "JWT"),
}
Register query and mutation
Add the following to your schema.py
file:
python
from graphene import ObjectType
...
from user_app.schema_relay import Mutation as UserMutation
from user_app.schema_relay import Query as UserQuery
class Query(UserQuery, ObjectType):
pass
class Mutation(UserMutation, ObjectType):
pass
Make migrations and migrate
bash
python manage.py makemigrations
python manage.py migrate
First synchronization of user data
bash
python manage.py synch_auth
Add config to kubernetes deployment
./backend/your_service/values.yaml
yaml
...
exchange:
consumer:
enabled: true
common:
...
extraConfigs:
...
- auth-configmap
- exchange-configmap
extraSecrets:
...
- exchange-secret
- auth-secret
Rebuild and deploy
sh
docker system prune -a -f;
docker build -t registry.mtc.wtf/library_service:local . --build-arg GIT_ACCESS_TOKEN=$env:GITHUB_ACCESS_TOKEN
kubectl rollout restart deploy library-backend-consumer library-backend -n backend