Skip to content

Commit 7d22ab6

Browse files
authored
Merge pull request #12 from Libertech-FR/9-implmentation-du-systme-dauthentification
9 implmentation du systme dauthentification
2 parents 6c6f891 + d9f3a67 commit 7d22ab6

File tree

75 files changed

+2035
-878
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2035
-878
lines changed

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
yarn lint:fix
2+
#yarn test

.yarnclean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!**/yaml/dist/**/doc
2+
!yaml/**/doc/*

Dockerfile

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
1-
FROM node:18-bookworm-slim
2-
LABEL description="Libertech Dev" \
3-
maintainer="Libertech <aide@libertech.fr>" \
4-
vendor=Libertech \
5-
name="sesame-orchestrator"
1+
FROM node:18-bookworm-slim as builder
62

73
ENV TIMEZONE=Europe/Paris \
84
LANGUAGE=fr_FR.UTF-8 \
95
LANG=fr_FR.UTF-8 \
10-
DEBIAN_FRONTEND=noninteractive \
11-
SUPERVISOR_VERSION=4.0.1 \
12-
GOSU_VERSION=1.11 \
136
TERM=xterm \
14-
BRANCHNAME=master
7+
DEBIAN_FRONTEND=noninteractive
8+
9+
WORKDIR /data
10+
11+
COPY . .
12+
13+
RUN yarn install \
14+
--prefer-offline \
15+
--frozen-lockfile \
16+
--non-interactive \
17+
--production=false
18+
19+
RUN yarn run build
20+
21+
FROM node:18-bookworm-slim AS production
22+
23+
ENV TIMEZONE=Europe/Paris \
24+
LANGUAGE=fr_FR.UTF-8 \
25+
LANG=fr_FR.UTF-8 \
26+
TERM=xterm \
27+
DEBIAN_FRONTEND=noninteractive
28+
29+
ARG NODE_ENV=production
30+
ENV NODE_ENV=${NODE_ENV}
31+
32+
WORKDIR /data
33+
34+
ADD package.json .
35+
ADD *.lock .
1536

1637
RUN apt clean -y \
1738
&& apt update -y \
@@ -22,14 +43,23 @@ RUN apt clean -y \
2243
&& export LC_ALL=${LC_ALL} \
2344
&& locale-gen ${LANG} \
2445
&& dpkg-reconfigure --frontend ${DEBIAN_FRONTEND} locales \
25-
&& apt install --no-install-recommends -yq procps supervisor
26-
27-
WORKDIR /data
28-
#RUN npm i -g @nestjs/cli
29-
#RUN npm install --save @nestjs/swagger
30-
COPY ./rootfs /
31-
EXPOSE 4000
46+
&& apt install --no-install-recommends -yq \
47+
git \
48+
jq \
49+
nano \
50+
openssl
3251

33-
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
52+
RUN yarn install \
53+
--prefer-offline \
54+
--pure-lockfile \
55+
--non-interactive \
56+
--production=true \
57+
&& yarn cache clean \
58+
&& yarn autoclean --init \
59+
&& yarn autoclean --force
3460

61+
COPY --from=builder /data/dist ./dist
62+
63+
EXPOSE 4000
3564

65+
CMD ["yarn", "start:prod"]

Makefile

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,89 @@
11
include .env
2-
DEV_CONTAINER_NAME = "sesame-orchestrator"
3-
APPNAME = "sesame"
2+
APP_PORT = 4002
3+
IMG_NAME = "ghcr.io/libertech-fr/sesame-orchestrator"
4+
APP_NAME = "sesame-orchestrator"
5+
PLATFORM = "linux/amd64"
46

57
.DEFAULT_GOAL := help
68
help:
79
@printf "\033[33mUsage:\033[0m\n make [target] [arg=\"val\"...]\n\n\033[33mTargets:\033[0m\n"
810
@grep -E '^[-a-zA-Z0-9_\.\/]+:.*?## .*$$' $(MAKEFILE_LIST) \
911
| sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-15s\033[0m %s\n", $$1, $$2}'
1012

11-
dev: ## Run development server
12-
@docker compose --project-directory docker run -d --rm \
13-
--service-ports \
14-
--use-aliases \
15-
--name $(DEV_CONTAINER_NAME) \
16-
$(DEV_CONTAINER_NAME) yarn start:dev
17-
@docker logs -f $(DEV_CONTAINER_NAME)
13+
build: ## Build the container
14+
@docker build --platform $(PLATFORM) -t $(IMG_NAME) .
1815

19-
exec: ## Execute a command in the development container
20-
@docker compose --project-directory docker run -it --rm $(DEV_CONTAINER_NAME) bash
16+
dev: ## Start development environment
17+
@docker run --rm -it \
18+
-e NODE_ENV=development \
19+
-e NODE_TLS_REJECT_UNAUTHORIZED=0 \
20+
--add-host host.docker.internal:host-gateway \
21+
--network dev \
22+
--platform $(PLATFORM) \
23+
--name $(APP_NAME) \
24+
-p $(APP_PORT):4000 \
25+
-v $(CURDIR):/data \
26+
$(IMG_NAME) yarn start:dev
2127

22-
run-docs: ## Execute a command in the development container
23-
@docker compose --project-directory docker run -p 8080:8080 -it --rm $(DEV_CONTAINER_NAME) yarn generate:docServer
28+
install: ## Install dependencies
29+
@docker run -it --rm \
30+
-e NODE_ENV=development \
31+
-e NODE_TLS_REJECT_UNAUTHORIZED=0 \
32+
--add-host host.docker.internal:host-gateway \
33+
--platform $(PLATFORM) \
34+
--network dev \
35+
-v $(CURDIR):/data \
36+
$(IMG_NAME) yarn install
2437

25-
install: ## Execute a command in the development container
26-
@docker compose --project-directory docker run -it --rm $(DEV_CONTAINER_NAME) yarn install
38+
exec: ## Run a shell in the container
39+
@docker run -it --rm \
40+
-e NODE_ENV=development \
41+
-e NODE_TLS_REJECT_UNAUTHORIZED=0 \
42+
--add-host host.docker.internal:host-gateway \
43+
--platform $(PLATFORM) \
44+
--network dev \
45+
-v $(CURDIR):/data \
46+
$(IMG_NAME) sh
2747

28-
dbs: ## Run dependencies for development
29-
@docker volume create $(APPNAME)-mongo
30-
@docker compose --project-directory docker up -d $(APPNAME)-redis
31-
@docker compose --project-directory docker up -d $(APPNAME)-mongo
32-
@docker exec -it $(APPNAME)-mongo mongo --eval "rs.initiate({_id: 'rs0', members: [{_id: 0, host: '127.0.0.1:27017'}]})" || true
48+
dbs: ## Start databases
49+
@docker volume create $(APP_NAME)-mongodb
50+
@docker run -d --rm \
51+
--name $(APP_NAME)-mongodb \
52+
-v $(APP_NAME)-mongodb:/data/db \
53+
-p 27017:27017 \
54+
-e MONGODB_REPLICA_SET_MODE=primary \
55+
-e MONGODB_REPLICA_SET_NAME=rs0 \
56+
-e ALLOW_EMPTY_PASSWORD=yes \
57+
--platform $(PLATFORM) \
58+
--network dev \
59+
--health-interval=5s \
60+
--health-timeout=3s \
61+
--health-start-period=5s \
62+
--health-retries=3 \
63+
--health-cmd="mongo --eval \"db.stats().ok\" || exit 1" \
64+
mongo:7.0 --replSet rs0 --wiredTigerCacheSizeGB 1.5 || true
65+
@docker volume create $(APP_NAME)-redis
66+
@docker run -d --rm \
67+
--name $(APP_NAME)-redis \
68+
-v $(APP_NAME)-redis:/data \
69+
--platform $(PLATFORM) \
70+
--network dev \
71+
-p 6379:6379 \
72+
--health-interval=5s \
73+
--health-timeout=3s \
74+
--health-start-period=5s \
75+
--health-retries=3 \
76+
--health-cmd="redis-cli ping || exit 1" \
77+
redis || true
78+
@docker exec -it $(APP_NAME)-mongodb mongo --eval "rs.initiate({_id: 'rs0', members: [{_id: 0, host: '127.0.0.1:27017'}]})" || true
3379

34-
stop: ## Stop all containers
35-
@docker compose --project-directory docker down $(DEV_CONTAINER_NAME) $(APPNAME)-redis $(APPNAME)-mongo --remove-orphans
36-
@docker compose --project-directory rm -f
37-
38-
stop-dev: ## Stop development container
39-
@docker compose --project-directory docker down $(DEV_CONTAINER_NAME) --remove-orphans
40-
@docker compose --project-directory rm -f $(DEV_CONTAINER_NAME)
41-
42-
stop-dbs: ## Stop dependencies for development
43-
@docker compose --project-directory docker down $(APPNAME)-redis $(APPNAME)-mongo --remove-orphans
44-
@docker compose --project-directory docker rm -f $(APPNAME)-redis $(APPNAME)-mongo
80+
stop: ## Stop the container
81+
@docker stop $(APP_NAME) || true
82+
@docker stop $(APP_NAME)-mongodb || true
83+
@docker stop $(APP_NAME)-redis || true
4584

4685
run-test: ## Run tests
4786
act --container-architecture="linux/arm64" -j test
4887

4988
gen-doc:
50-
npx @compodoc/compodoc -p tsconfig.json -s -d docs --includes ./markdowns -n "Sesame Orchestrator"
89+
@npx @compodoc/compodoc -p tsconfig.json -s -d docs --includes ./markdowns -n "Sesame Orchestrator"

docker/Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
include .env
2+
DEV_CONTAINER_NAME = "sesame-orchestrator"
3+
APPNAME = "sesame"
4+
5+
.DEFAULT_GOAL := help
6+
help:
7+
@printf "\033[33mUsage:\033[0m\n make [target] [arg=\"val\"...]\n\n\033[33mTargets:\033[0m\n"
8+
@grep -E '^[-a-zA-Z0-9_\.\/]+:.*?## .*$$' $(MAKEFILE_LIST) \
9+
| sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[32m%-15s\033[0m %s\n", $$1, $$2}'
10+
11+
dev: ## Run development server
12+
@docker compose run -d --rm \
13+
--service-ports \
14+
--use-aliases \
15+
--name $(DEV_CONTAINER_NAME) \
16+
$(DEV_CONTAINER_NAME) yarn start:dev
17+
@docker logs -f $(DEV_CONTAINER_NAME)
18+
19+
exec: ## Execute a command in the development container
20+
@docker compose run -it --rm $(DEV_CONTAINER_NAME) bash
21+
22+
run-docs: ## Execute a command in the development container
23+
@docker compose run -p 8080:8080 -it --rm $(DEV_CONTAINER_NAME) yarn generate:docServer
24+
25+
install: ## Execute a command in the development container
26+
@docker compose run -it --rm $(DEV_CONTAINER_NAME) yarn install
27+
28+
dbs: ## Run dependencies for development
29+
@docker volume create $(APPNAME)-mongo
30+
@docker compose up -d $(APPNAME)-redis
31+
@docker compose up -d $(APPNAME)-mongo
32+
@docker exec -it $(APPNAME)-mongo mongo --eval "rs.initiate({_id: 'rs0', members: [{_id: 0, host: '127.0.0.1:27017'}]})" || true
33+
34+
stop: ## Stop all containers
35+
@docker compose down $(DEV_CONTAINER_NAME) $(APPNAME)-redis $(APPNAME)-mongo --remove-orphans
36+
@docker compose rm -f
37+
38+
stop-dev: ## Stop development container
39+
@docker compose down $(DEV_CONTAINER_NAME) --remove-orphans
40+
@docker compose rm -f $(DEV_CONTAINER_NAME)
41+
42+
stop-dbs: ## Stop dependencies for development
43+
@docker compose down $(APPNAME)-redis $(APPNAME)-mongo --remove-orphans
44+
@docker compose rm -f $(APPNAME)-redis $(APPNAME)-mongo
45+
46+
run-test: ## Run tests
47+
act --container-architecture="linux/arm64"
48+
49+
gen-doc:
50+
npx @compodoc/compodoc -p tsconfig.json -s -d docs --includes ./markdowns -n "Sesame Orchestrator"

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"test:e2e": "jest --config ./test/jest-e2e.json",
4242
"schematics:inherit": "nest generate -c @kradihsoy/lt-schematics inherit",
4343
"generate:doc": "npx @compodoc/compodoc -c .compodocrc",
44-
"generate:docServer": "npx @compodoc/compodoc -s -c .compodocrc -d ./documentation"
44+
"generate:docServer": "npx @compodoc/compodoc -s -c .compodocrc -d ./documentation",
45+
"prepare": "husky"
4546
},
4647
"dependencies": {
4748
"@kradihsoy/lt-schematics": "^1.0.13",
@@ -51,12 +52,14 @@
5152
"@nestjs/config": "^3.1.1",
5253
"@nestjs/core": "^10.1.3",
5354
"@nestjs/event-emitter": "^2.0.3",
55+
"@nestjs/jwt": "^10.2.0",
5456
"@nestjs/mongoose": "^10.0.2",
55-
"@nestjs/passport": "^10.0.2",
56-
"@nestjs/platform-express": "^10.0.0",
57+
"@nestjs/passport": "^10.0.3",
58+
"@nestjs/platform-express": "^10.3.1",
5759
"@streamkits/nestjs_module_scrud": "^0.0.16",
5860
"ajv": "^8.12.0",
5961
"ajv-errors": "^3.0.0",
62+
"argon2": "^0.31.2",
6063
"bullmq": "^4.14.0",
6164
"class-transformer": "^0.5.1",
6265
"class-validator": "^0.14.0",
@@ -66,12 +69,14 @@
6669
"nest-winston": "^1.9.4",
6770
"nestjs-request-context": "^3.0.0",
6871
"passport": "^0.6.0",
69-
"passport-headerapikey": "^1.2.2",
72+
"passport-jwt": "^4.0.1",
73+
"passport-local": "^1.0.0",
7074
"radash": "^11.0.0",
7175
"reflect-metadata": "^0.1.13",
7276
"request-ip": "^3.3.0",
7377
"rxjs": "^7.8.1",
7478
"schema-to-yup": "^1.12.18",
79+
"types-package-json": "^2.0.39",
7580
"winston": "^3.11.0",
7681
"winston-mongodb": "^5.1.1",
7782
"winston-transport": "^4.6.0",
@@ -89,14 +94,17 @@
8994
"@types/express": "^4.17.17",
9095
"@types/jest": "^29.5.2",
9196
"@types/node": "^18.0.0",
92-
"@types/passport": "^1.0.15",
97+
"@types/passport": "^1.0.16",
9398
"@types/passport-http": "^0.3.11",
99+
"@types/passport-jwt": "^4.0.1",
100+
"@types/passport-local": "^1.0.38",
94101
"@types/supertest": "^2.0.12",
95102
"@typescript-eslint/eslint-plugin": "^6.0.0",
96103
"@typescript-eslint/parser": "^6.0.0",
97104
"eslint": "^8.42.0",
98105
"eslint-config-prettier": "^9.0.0",
99106
"eslint-plugin-prettier": "^5.0.0",
107+
"husky": "^9.0.11",
100108
"jest": "^29.5.0",
101109
"mockingoose": "^2.16.2",
102110
"mongodb-memory-server": "^9.1.3",

src/_common/abstracts/abstract.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ export abstract class AbstractService {
3535

3636
public get moduleName(): string {
3737
//TODO: change modulename from module ref ?
38-
if (!this.request)
39-
throw new Error('Request is not defined in ' + this.constructor.name);
38+
if (!this.request) throw new Error('Request is not defined in ' + this.constructor.name);
4039
const moduleName = this.request.path.split('/').slice(1).shift();
4140
return moduleName.charAt(0).toUpperCase() + moduleName.slice(1);
4241
}

src/_common/data/console-session.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { Types } from 'mongoose';
33
export class ConsoleSession {
44
public readonly _id: string = '000000000000000000000000';
55
public readonly username: string = 'console';
6-
public readonly entityId: Types.ObjectId = new Types.ObjectId(
7-
'000000000000000000000000',
8-
);
6+
public readonly entityId: Types.ObjectId = new Types.ObjectId('000000000000000000000000');
97
public readonly displayName: string = 'Console';
108
public constructor() {}
119
}

src/_common/decorators/api-body.decorator.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { applyDecorators, Type } from '@nestjs/common';
2-
import {
3-
ApiBody,
4-
ApiBodyOptions,
5-
ApiExtraModels,
6-
getSchemaPath,
7-
} from '@nestjs/swagger';
2+
import { ApiBody, ApiBodyOptions, ApiExtraModels, getSchemaPath } from '@nestjs/swagger';
83

94
export const ApiBodyDecorator = <TModel extends Type<NonNullable<unknown>>>(
105
model: TModel,

0 commit comments

Comments
 (0)