Skip to content

Commit 82a84dd

Browse files
committed
move web dev scripts in this repo (#28)
* add conf and tools add doc add policy add doc add keycloak conf revert translations change move keycloak and wiremock to element-demo repo * update docs * remove binary * remove useless env * move comments * add policy generation * change port * create tmp if deleted * edit doc * add placeholder create env var for HOMESERVER_SECRET move template check fi start script
1 parent 4ef68b5 commit 82a84dd

File tree

11 files changed

+598
-8
lines changed

11 files changed

+598
-8
lines changed

tchap/.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#Copy synapse secret from `element-docker-demo/data/mas/config.yaml`
2+
HOMESERVER_SECRET=

tchap/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tmp
2+
3+
.env

tchap/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ Tchap custom React components are located in a [subdirectory](../frontend/tchap)
2323

2424
For building the Docker image, the [`build` github action](../.github/workflows/build.yaml) packages all MAS resources enhanced with Tchap customizations.
2525

26+
## Web dev
27+
28+
- start your docker engine, on Macos Docker Desktop
29+
30+
- [install rust](https://www.rust-lang.org/tools/install) : curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
31+
32+
- on MacOs install `brew install fswatch`
33+
34+
- run `start.sh`, if you work on templates: `start-with-hot-reload.sh`
35+
36+
- edit templates in `./tchap/resources/templates`
37+
38+
If Synapse integration is needed, install the environment from element-docker-demo and run it (see README.md)
39+
40+
Copy synapse secret from `element-docker-demo/data/mas/config.yaml` to .env file : HOMESERVER_SECRET=
41+
2642

2743
# Important knowledge
2844

tchap/build_conf.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
echo "Starting configuration build process..."
6+
7+
# Get the directory where this script is located
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
10+
# Set MAS_HOME to the parent directory (project root)
11+
export MAS_HOME="$(dirname "$SCRIPT_DIR")"
12+
export MAS_TCHAP_HOME=$SCRIPT_DIR
13+
14+
echo "Step 1/7: Loading environment variables..."
15+
# Source the .env file to load environment variables
16+
if [ -f $MAS_TCHAP_HOME/.env ]; then
17+
source $MAS_TCHAP_HOME/.env
18+
else
19+
echo "Error: .env file not found. Please create a $MAS_TCHAP_HOME/.env file with the required environment variables."
20+
exit 1
21+
fi
22+
23+
echo "Step 2/7: Preparing template directories..."
24+
# New template directory
25+
MAS_TCHAP_DATA="$MAS_TCHAP_HOME/tmp"
26+
27+
# Create tmp directory
28+
if [ ! -d "$MAS_TCHAP_DATA" ]; then
29+
echo "Creating MAS tchap temp folder..."
30+
mkdir -p "$MAS_TCHAP_DATA"
31+
fi
32+
33+
echo "Step 3/7: Copying MAS templates..."
34+
cp -r "$MAS_HOME/templates" "$MAS_TCHAP_DATA"
35+
36+
echo "Step 4/7: Overriding with custom Tchap templates..."
37+
cp -r "$MAS_HOME/tchap/resources/templates" "$MAS_TCHAP_DATA"
38+
39+
echo "Step 5/7: Building MAS config file..."
40+
template_yaml_file="$MAS_TCHAP_HOME/conf/config.template.yaml"
41+
yaml_file="$MAS_TCHAP_DATA/config.local.dev.yaml"
42+
cp $template_yaml_file $yaml_file
43+
MAS_TCHAP_TEMPLATES="$MAS_TCHAP_DATA/templates"
44+
sed -i '' -E "/^templates:/,/^[^[:space:]]/ s|^[[:space:]]*path:.*| path: \"$MAS_TCHAP_TEMPLATES\"|" "$yaml_file"
45+
46+
echo "Step 6/7: Updating translations..."
47+
MAS_TCHAP_TRANSLATIONS="$MAS_HOME/tchap/resources/translations"
48+
cargo run -p mas-i18n-scan -- --update "${MAS_TCHAP_TEMPLATES}" "${MAS_TCHAP_TRANSLATIONS}/en.json"
49+
sed -i '' -E "/^templates:/,/^[^[:space:]]/ s|^[[:space:]]*translations_path:.*| translations_path: \"$MAS_TCHAP_TRANSLATIONS\"|" "$yaml_file"
50+
51+
echo "Step 7/7: Updating matrix secret..."
52+
# Replace the placeholder secret value with the environment variable or warning message
53+
if [ -n "${HOMESERVER_SECRET+x}" ] && [ -n "$HOMESERVER_SECRET" ]; then
54+
# HOMESERVER_SECRET is defined and not empty
55+
sed -i '' -E "s|secret: 'TO BE COPY'|secret: '$HOMESERVER_SECRET'|" "$yaml_file"
56+
else
57+
sed -i '' -E "s|secret: 'TO BE COPY'|secret: 'WARNING NO HOMESERVER SECRET DEFINED'|" "$yaml_file"
58+
echo "WARNING: HOMESERVER_SECRET is not defined or empty. Using warning message instead."
59+
fi
60+
61+
echo "Configuration build completed successfully!"

tchap/clean.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
echo "Starting cleanup process..."
4+
5+
echo "Step 1/6: Stopping Docker containers..."
6+
docker compose down
7+
8+
echo "Step 2/6: Removing policy WASM file..."
9+
rm -rf ../policies/policy.wasm
10+
11+
#echo "Step 3/6: Removing Rust build artifacts..."
12+
#rm -rf ../target/
13+
14+
echo "Step 4/6: Removing temporary files..."
15+
rm -rf tmp/
16+
17+
echo "Step 5/6: Removing frontend dependencies..."
18+
rm -rf ../frontend/node_modules/
19+
20+
echo "Step 6/6: Removing frontend build files..."
21+
rm -rf ../frontend/dist/
22+
23+
echo "Cleanup completed successfully!"

tchap/conf/config.template.yaml

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
http:
2+
listeners:
3+
- name: web
4+
resources:
5+
- name: discovery
6+
- name: human
7+
- name: oauth
8+
- name: compat
9+
- name: graphql
10+
- name: assets
11+
# for api admin calls
12+
- name: adminapi
13+
binds:
14+
- address: '[::]:8080'
15+
proxy_protocol: false
16+
- name: internal
17+
resources:
18+
- name: health
19+
# for api admin calls
20+
- name: adminapi
21+
binds:
22+
- host: localhost
23+
port: 8081
24+
proxy_protocol: false
25+
trusted_proxies:
26+
- 192.168.0.0/16
27+
- 172.16.0.0/12
28+
- 10.0.0.0/10
29+
- 127.0.0.1/8
30+
- fd00::/8
31+
- ::1/128
32+
# public_base: http://[::]:8080/
33+
# issuer: http://[::]:8080/
34+
public_base: https://auth.tchapgouv.com/
35+
issuer: https://auth.tchapgouv.com/
36+
database:
37+
uri: postgresql://postgres:postgres@localhost:5439/postgres
38+
max_connections: 10
39+
min_connections: 0
40+
connect_timeout: 30
41+
idle_timeout: 600
42+
max_lifetime: 1800
43+
email:
44+
from: '"Authentication Service" <[email protected]>'
45+
reply_to: '"Authentication Service" <[email protected]>'
46+
transport: smtp
47+
mode: plain
48+
hostname: 127.0.0.1
49+
port: 1025
50+
51+
secrets:
52+
encryption: eb38b8b9087842b3345269f3c6ca92b2a8d6aa63e3a773d23ed1c9cb45c5ef83
53+
keys:
54+
- kid: dyrZtIyXSA
55+
key: |
56+
-----BEGIN RSA PRIVATE KEY-----
57+
MIIEogIBAAKCAQEAukLyWSv9KOeBsmIG4ntL/BP+wj5L4GbOyAOEzRBBO0ZbBYVn
58+
1L/aYQ65cQpQKK0MzH5cn7TvIY0JBh/ZsSm3e7DdhGJzoqPrW6E0/6QqXEl4gN1q
59+
DUCMj2CwAcT9OX1Wt6cNq70+gbqp6+yT+Nn++KPylHa/V9wRxkaV3fyM+XYVeddB
60+
amDR+fBjHgVXQ3xk2ezUBS3AmyKBgETnHufKCkxJ5mXdU9HT0ewg8J2PrgiRBwDj
61+
XP7C5Zif/+NfYPO2mM/b0Y91pl9aXuUHX+/zlqtpcwX/WprEsCaRUa9qWHuiftMf
62+
uelsflCgZ0KumZjzr3wPDEfu8n7WbVEObNxF+QIDAQABAoIBAEl82mNGUMbPuEMq
63+
G+9FmDAnr27x5zvtNA6EHORPUn1Rf94IyXOOEloS1iV8XS3/QLp57I9ycpq5K2NI
64+
M7qLbAIYQP3XXipAJD7ttpxaKABrWGj3cr0xx4NWMXsxPnttMUaaWXF14/CJNjuI
65+
BsW7NLb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tChg1pepuJcOEuWez3o3Ard9oZ4Z9sm7VJzmuoY=
82+
-----END RSA PRIVATE KEY-----
83+
- kid: O1hkajPW2v
84+
key: |
85+
-----BEGIN EC PRIVATE KEY-----
86+
MHcCAQEEINsgMBFDIrIzqOIWuR94TCi5MTH1FS8wfgatu9BsO2jVoAoGCCqGSM49
87+
AwEHoUQDQgAEldEtvZaXtblpUdHpKKQiH7z9ADC55H0yrCYyQsLXbt14lI2NuseX
88+
MWsvSLBzkbEetDxkmKh0bhOfrdwv9x5SwA==
89+
-----END EC PRIVATE KEY-----
90+
- kid: 2nhe3z2925
91+
key: |
92+
-----BEGIN EC PRIVATE KEY-----
93+
MIGkAgEBBDDTVngHypOwUnPOGXeskQJhdSLLPBCM+mkSvzr2SZ7Kjm3hftvs2s7J
94+
gZBOZwXyoaKgBwYFK4EEACKhZANiAAQ3WGOQs3EqO2x4X7PBWs6Lw3qdmRLHqblc
95+
Zplh3wYPDOoUMvD99Snxz43t5sK6kphLBL262/srx/UPT1McLUxBMlBvBUbBEKHX
96+
a8icrL13yIwflquj0EHrE7czFJw1txs=
97+
-----END EC PRIVATE KEY-----
98+
- kid: 50aRR3QVqx
99+
key: |
100+
-----BEGIN EC PRIVATE KEY-----
101+
MHQCAQEEIN8bErXY1sWEJ1y9KoYcpcUImIjpS/ay3pEugYPfr3Y/oAcGBSuBBAAK
102+
oUQDQgAEMHcshHVFbMSEyyt3ptIdAhnrg+XlQskZ33hZvdtzm6I0wW8H8zslMp+I
103+
t0KYCeIQ7HTPtgJAOsKxEPBfmVXZmA==
104+
-----END EC PRIVATE KEY-----
105+
passwords:
106+
enabled: true
107+
schemes:
108+
- version: 1
109+
algorithm: bcrypt
110+
secret: "secret01"
111+
- version: 2
112+
algorithm: argon2id
113+
minimum_complexity: 3
114+
matrix:
115+
homeserver: tchapgouv.com
116+
#TODO copy from element-docker-demo/data/mas/config.yaml
117+
secret: 'TO BE COPY'
118+
endpoint: https://matrix.tchapgouv.com/
119+
120+
clients:
121+
- client_id: 0000000000000000000SYNAPSE
122+
client_auth_method: client_secret_basic
123+
client_secret: '/DjWc4D3yyqgjYN8tum65g'
124+
125+
# for api admin calls
126+
- client_id: 01J44RKQYM4G3TNVANTMTDYTX6
127+
client_auth_method: client_secret_basic
128+
client_secret: phoo8ahneir3ohY2eigh4xuu6Oodaewi
129+
130+
131+
policy:
132+
data:
133+
admin_clients:
134+
# for api admin calls
135+
- 01J44RKQYM4G3TNVANTMTDYTX6
136+
client_registration:
137+
allow_insecure_uris: true
138+
allow_host_mismatch: true
139+
140+
account:
141+
# Whether users are allowed to change their email addresses.
142+
#
143+
# Defaults to `true`.
144+
email_change_allowed: false
145+
146+
# Whether users are allowed to change their display names
147+
#
148+
# Defaults to `true`.
149+
# This should be in sync with the policy in the homeserver configuration.
150+
displayname_change_allowed: false
151+
152+
# Whether to enable self-service password registration
153+
#
154+
# Defaults to `false`.
155+
# This has no effect if password login is disabled.
156+
password_registration_enabled: true
157+
158+
# Whether users are allowed to change their passwords
159+
#
160+
# Defaults to `true`.
161+
# This has no effect if password login is disabled.
162+
password_change_allowed: true
163+
164+
# Whether email-based password recovery is enabled
165+
#
166+
# Defaults to `false`.
167+
# This has no effect if password login is disabled.
168+
password_recovery_enabled: true
169+
170+
# Whether users can log in with their email address.
171+
#
172+
# Defaults to `false`.
173+
# This has no effect if password login is disabled.
174+
login_with_email_allowed: true
175+
176+
templates:
177+
# From where to load the templates
178+
# This is relative to the current working directory, *not* the config file
179+
path: "WILL BE REPLACED BY build_conf.sh"
180+
181+
# Path to the frontend assets manifest file
182+
# assets_manifest: "/to/manifest.json"
183+
184+
# # From where to load the translation files
185+
# # Default in Docker distribution: `/usr/local/share/mas-cli/translations/`
186+
# # Default in pre-built binaries: `./share/translations/`
187+
# # Default in locally-built binaries: `./translations/`
188+
translations_path: "WILL BE REPLACED BY build_conf.sh"
189+
190+
upstream_oauth2:
191+
providers:
192+
- id: "01JK5MR1SD21MAQY4PWMFG283W"
193+
human_name: Proconnect (mock)
194+
issuer: "https://sso.tchapgouv.com/realms/proconnect-mock"
195+
token_endpoint_auth_method: client_secret_basic
196+
client_id: "matrix-authentication-service"
197+
client_secret: "HrJ1NZ0AbkHuWWjyRHh7X2lzn3S8eagt"
198+
scope: "openid profile email"
199+
claims_imports:
200+
localpart:
201+
action: force
202+
#template: "{{ user.preferred_username }}"
203+
on_conflict: add
204+
#action: require
205+
template: "{{ user.email | email_to_mxid_localpart }}"
206+
displayname:
207+
action: require
208+
#template: "{{ user.name }}"
209+
template: "{{ user.email | email_to_display_name }}"
210+
email:
211+
action: require
212+
template: "{{ user.email }}"
213+
set_email_verification: always
214+
215+
telemetry:
216+
tracing:
217+
# # List of propagators to use for extracting and injecting trace contexts
218+
# propagators:
219+
# # Propagate according to the W3C Trace Context specification
220+
# - tracecontext
221+
# # Propagate according to the W3C Baggage specification
222+
# - baggage
223+
# # Propagate trace context with Jaeger compatible headers
224+
# - jaeger
225+
226+
# # The default: don't export traces
227+
exporter: none
228+
229+
# Export traces to an OTLP-compatible endpoint
230+
#exporter: otlp
231+
#endpoint: https://localhost:4318
232+
metrics:
233+
# The default: don't export metrics
234+
exporter: none
235+
236+
# Export metrics to an OTLP-compatible endpoint
237+
#exporter: otlp
238+
#endpoint: https://localhost:4317
239+
240+
# Export metrics by exposing a Prometheus endpoint
241+
# This requires mounting the `prometheus` resource to an HTTP listener
242+
#exporter: prometheus
243+
244+
# sentry:
245+
# # DSN to use for sending errors and crashes to Sentry
246+
# dsn: https://public@host:port/1
247+
248+
tchap:
249+
identity_server_url: "http://localhost:8083"
250+
email_lookup_fallback_rules:
251+
# match : the new email pattern
252+
# search : the old email pattern
253+
# old email in mail.numerique.gouv.fr
254+
- match_with : '@numerique.gouv.fr'
255+
search: '@beta.gouv.fr'

0 commit comments

Comments
 (0)