Skip to content

Commit 2ab7a9e

Browse files
committed
use FACTORIES_DEMO_USERS; rework README with that; Factories and Auth Clients full sections in config.yaml;
1 parent 73dde42 commit 2ab7a9e

File tree

2 files changed

+114
-16
lines changed

2 files changed

+114
-16
lines changed

README.md

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,17 @@ services:
231231
> [!IMPORTANT]
232232
> Copy the `.env.template` file in a new `.env` file, likewise copy `config.template.yaml` in a new `config.yaml`.
233233
234+
```bash
235+
cp .env.template .env && cp config.template.yaml config.yaml
236+
```
237+
234238
> [!TIP]
235239
> These template files were carefully crafted to work for you with minimal personal changes to bring, and some preconfigured services.
236240
237241
For later reference, these settings are documented in [app/core/config.py](./app/core/config.py).
238242
Check this file to know what can and should be set using these two files.
239243

240-
### `.env`
244+
### The `.env` file
241245

242246
The `.env` contains environment variables which need to be accessed by the OS or by other services, such as the database.
243247

@@ -274,7 +278,7 @@ POSTGRES_DB="hyperion"
274278

275279
</details>
276280

277-
### `config.yaml`
281+
### The `config.yaml` file
278282

279283
The `config.yaml` contains environment variables that are internal to the Python runtime _because_ they are only used in the Python code.
280284

@@ -289,7 +293,10 @@ The `config.yaml` contains environment variables that are internal to the Python
289293
- If you use **PostgreSQL**: empty this field.
290294
Hyperion will fallback to PostgreSQL settings.
291295
4. `USE_FACTORIES`: `True` by default, factories seed your database, if empty, with mocked data.
292-
This is useful on SQLite to repopulate your new database after dropping the previous one.
296+
This is useful on SQLite to repopulate your new database after dropping the previous one, of to create automatically your own user with admin privileges (see `FACTORIES_DEMO_USERS` below).
297+
5. `FACTORIES_DEMO_USERS`: **Replace the first user's data with yours**.
298+
These future users will be created automatically when launching Hyperion with an empty database.
299+
Plus, your user will be there with your password and be admin out of the box.
293300

294301
## 5. Launch the API
295302

@@ -311,15 +318,21 @@ fastapi dev
311318

312319
Check that your Hyperion instance is up and running by navigating to http://localhost:8000/information.
313320

314-
## 6. Create your own user
321+
## 6. Create your own user (if not yet the case using factories)
315322

316-
There are many ways to do so, ranked here from easiest (GUI only) to hardest (CLI only).
317-
Note that registration and activation are distinct steps, so for fun you may register one way and activate your account another way.
323+
There are at least 5 distinct ways to do so outside the use of factories, ranked here from easiest (~GUI) to hardest (~CLI).
324+
325+
> [!IMPORTANT]
326+
> Using factories is the recommended way.
327+
> All others methods are legacy and kept here for historical reasons.
328+
> Feel free to create other users other ways for learning purposes.
329+
330+
Note that registration and activation are distinct steps when calling calls to the API, so for fun you may register one way and activate your account another way (if you create your user directly in database, this distinction is not relevant).
318331

319332
<details>
320333
<summary>
321334

322-
### With CalypSSO
335+
### Using CalypSSO
323336

324337
</summary>
325338

@@ -337,7 +350,7 @@ Open it and activate (end the creation of) your account.
337350
<details>
338351
<summary>
339352

340-
### With Titan
353+
### Using Titan
341354

342355
</summary>
343356

@@ -412,17 +425,54 @@ curl --json '{
412425

413426
</details>
414427

415-
## 7. Make the first user admin
428+
<details>
429+
<summary>
430+
431+
### Using a database client in command line
432+
433+
</summary>
416434

417435
> [!WARNING]
418-
> This may not work if you ran the factories
436+
> Work in progress
437+
438+
1. Open a shell connected to your database for Hyperion
439+
- PostgreSQL: see above, generally `psql -U <username> -d hyperion`.
440+
- SQLite: ...
441+
2. Insert your own user into the users' table (for `centrale_lyon` school, generate your own user UUID and salted hash, feel free to add insert values into nullable columns) :
442+
443+
```sql
444+
insert into core_user (id, firstname, name, nickname, email, password_hash, school_id, account_type) values ('01234567-89ab-cdef-0123-456789abcdef', '<Fistname>', '<Name>', '<Nickname>', '<email>', '$2b$<saltlength>$<yourpasswordsaltedhash>', 'd9772da7-1142-4002-8b86-b694b431dfed', 'student');
445+
```
446+
447+
</details>
448+
449+
## 7. Make your user admin (if not yet the case using factories)
450+
451+
> [!IMPORTANT]
452+
> Again, using factories is the recommended way.
453+
454+
### If there is exactly one user in the database
419455

420-
If there is exactly one user in the database, you can make it admin using the following command:
456+
Then you can make it admin using the following command:
421457

422458
```bash
423459
curl -X POST http://localhost:8000/users/make-admin
424460
```
425461

462+
### Using a database client in command line
463+
464+
> [!WARNING]
465+
> Work in progress
466+
467+
1. Open a shell connected to your database for Hyperion
468+
- PostgreSQL: see above, generally `psql -U <username> -d hyperion`.
469+
- SQLite: ...
470+
2. Get the UUID for your own user, then insert it and the UUID for the admin grouptype in the memberships table :
471+
472+
```sql
473+
insert into core_membership (user_id, group_id) values ('<Your user_id>', '0a25cb76-4b63-4fd3-b939-da6d9feabf28');
474+
```
475+
426476
---
427477

428478
<details>

config.template.yaml

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,21 @@ CLIENT_URL: http://127.0.0.1:8000/ # NOTE: A trailing / is required
4949
# - but the docker container should call http://host.docker.internal:8000/auth/token and not your localhost address
5050
#OVERRIDDEN_CLIENT_URL_FOR_OIDC: "http://host.docker.internal:8000/" # NOTE: A trailing / is required
5151

52-
# Configure AuthClients, to allow services to authenticate users using OAuth2 or Openid connect
53-
# The following format should be used in yaml config files:
5452
# Origins for the CORS middleware. `["http://localhost:3000"]` can be used for development.
5553
# See https://fastapi.tiangolo.com/tutorial/cors/
5654
# It should begin with 'http://' or 'https:// and should never end with a '/'
5755
CORS_ORIGINS:
5856
- "*" # For a local instance, using a wildcard "*" is convenient
5957
# - http://localhost:3000
6058
# - http://127.0.0.1:3000
59+
60+
################
61+
# Auth Clients #
62+
################
63+
64+
# Configure AuthClients, to allow services to authenticate users using OAuth2 or OpenID Connect
65+
# The Python-expected type is `dict[str, AuthClientConfig]` where the class `AuthClientConfig` is from `app.core.utils.config`.
66+
# Thus, the following format should be used in yaml config files:
6167
# ```yml
6268
# AUTH_CLIENTS:
6369
# <ClientId>:
@@ -70,10 +76,12 @@ CORS_ORIGINS:
7076
# `AuthClientClassName` should be a class from `app.utils.auth.providers`
7177
AUTH_CLIENTS:
7278
Titan:
73-
secret:
79+
secret: null # PKCE
7480
redirect_uri:
7581
- http://localhost:3000/static.html
7682
- http://127.0.0.1:3000/static.html
83+
- https://myecl.fr/static.html
84+
- "fr.myecl.titan://authorized
7785
auth_client: AppAuthClient
7886
Postman:
7987
secret: PostmanSecret
@@ -91,8 +99,48 @@ AUTH_CLIENTS:
9199
SQLITE_DB: app.db # If set, the application use a SQLite database instead of PostgreSQL, for testing or development purposes (if possible PostgreSQL should be used instead)
92100
DATABASE_DEBUG: False # If True, will print all SQL queries in the console
93101
LOG_DEBUG_MESSAGES: False
94-
# if True and the database is empty, it will be seeded with mocked data
95-
USE_FACTORIES: True
102+
NB_WORKERS: 6 # Not yet used...
103+
104+
#############
105+
# Factories #
106+
#############
107+
108+
USE_FACTORIES: True # if True and the database is empty, it will be seeded with mocked data
109+
110+
# Configure demo users, to populate the db with your users
111+
# The Python-expected type is `list[UserDemoFactoryConfig]` where the class `UserDemoFactoryConfig` is from `app.core.utils.config`.
112+
# Thus, the following format should be used in yaml config files:
113+
# ```yml
114+
# FACTORIES_DEMO_USERS
115+
# - firstname: <Firstname>
116+
# name: <Name>
117+
# nickname: <Nickname> (or <null>)
118+
119+
# password: <password>
120+
# groups:
121+
# - <UUID value 1 of a GroupType>
122+
# - <UUID value 2 of a GroupType>
123+
# ```
124+
# Group UUIDs should be values of the GroupType enum from `app.core.groups.groupe_type.GroupType`
125+
FACTORIES_DEMO_USERS:
126+
- firstname: Your Firstname
127+
name: Your Name
128+
nickname: Your Nickname
129+
130+
password: Your_P@$$w0rd
131+
groups:
132+
- 0a25cb76-4b63-4fd3-b939-da6d9feabf28 # admin
133+
- 45649735-866a-49df-b04b-a13c74fd5886 # AE
134+
- 1f841bd9-00be-41a7-96e1-860a18a46105 # eclair
135+
- firstname: Foucauld
136+
name: Bellanger
137+
nickname: Ñool
138+
139+
password: azerty
140+
groups:
141+
- 1f841bd9-00be-41a7-96e1-860a18a46105
142+
- 45649735-866a-49df-b04b-a13c74fd5886
143+
- 4ec5ae77-f955-4309-96a5-19cc3c8be71c
96144
97145
#####################################
98146
# SMTP configuration using starttls #

0 commit comments

Comments
 (0)