fiscalia_bo-nest-helpers 0.0.15 → 0.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
@@ -46,16 +46,22 @@ ENV_SERVICE_MS_FILES='https://ms-files.url'
|
|
46
46
|
|
47
47
|
El módulo MsSeguridadModule proporciona una manera fácil de comunicarse con un servicio de seguridad a través de gRPC.
|
48
48
|
|
49
|
-
##
|
49
|
+
## Modulos disponibles
|
50
50
|
|
51
51
|
- MsSeguridadModule
|
52
|
+
|
53
|
+
## Servicios disponibles
|
54
|
+
|
52
55
|
- MsSeguridadService
|
53
56
|
|
57
|
+
para utilizar el servicio de seguridad es necesario importar el modulo `MsSeguridadModule`
|
58
|
+
|
54
59
|
## Configuración
|
55
60
|
|
56
61
|
Antes de utilizar el módulo, asegúrese de tener las siguientes variables de entorno configuradas:
|
57
62
|
|
58
63
|
- `ENV_GRPC_MS_SEGURIDAD`: la URL del servidor de seguridad a través de gRPC.
|
64
|
+
- `ENV_GRPC_MS_REDIS_CACHE`: la URL del servidor de cacheo de redis a través de gRPC.
|
59
65
|
|
60
66
|
## Uso
|
61
67
|
|
@@ -68,7 +74,13 @@ import { MsSeguridadModule } from 'fiscalia_bo-nest-helpers/seguridad';
|
|
68
74
|
@Module({
|
69
75
|
imports: [
|
70
76
|
ConfigModule.forRoot({ isGlobal: true }),
|
71
|
-
|
77
|
+
|
78
|
+
// Register ms-seguridad module global
|
79
|
+
MsSeguridadModule.register({
|
80
|
+
global: true,
|
81
|
+
urlSeguridad: process.env.ENV_GRPC_MS_SEGURIDAD,
|
82
|
+
urlRedisCache: process.env.ENV_GRPC_MS_REDIS_CACHE,
|
83
|
+
}),
|
72
84
|
],
|
73
85
|
controllers: [],
|
74
86
|
providers: [],
|
@@ -76,11 +88,94 @@ import { MsSeguridadModule } from 'fiscalia_bo-nest-helpers/seguridad';
|
|
76
88
|
export class AppModule {}
|
77
89
|
```
|
78
90
|
|
79
|
-
> **NOTA IMPORTANTE:** previo al uso del modulO debe importarse el [`ConfigModule`](https://docs.nestjs.com/techniques/configuration#getting-started
|
91
|
+
> **NOTA IMPORTANTE:** previo al uso del modulO debe importarse el [`ConfigModule`](https://docs.nestjs.com/techniques/configuration#getting-started 'Nestjs Docs') de nestjs y configurarlo para uso global
|
80
92
|
|
81
93
|
En este ejemplo, estamos utilizando el método register para cargar la configuración de forma `síncrona`
|
82
94
|
|
83
|
-
##
|
95
|
+
## decoradores disponibles para controller
|
96
|
+
|
97
|
+
- `@BearerAuthPermision()`, decorador auth que realiza 3 verificaciones antes de entrar a un controller.
|
98
|
+
|
99
|
+
- verifica automaticamente que existe `token bearer` en el header de la peticion
|
100
|
+
- verifica que el token se válido
|
101
|
+
- Si este decorador recibe permisos por parametro entonces verifica que cumpla con todos los permisos indicados por parametro
|
102
|
+
|
103
|
+
- `@VersionDescription(version, descripcion)`, decorador que aplica version y descripcion a un controller.
|
104
|
+
- `@AuthUser()`, decorador para obtener los datos del token como ser:
|
105
|
+
- ci: string;
|
106
|
+
- idAplicacion: number;
|
107
|
+
- idFuncionario: number;
|
108
|
+
- idPersona: number;
|
109
|
+
- usuarioId: number;
|
110
|
+
- `@AuthToken()`, decorador para obtener el token de tipo string
|
111
|
+
|
112
|
+
- `@AuthPermissions()`, decorador para obtener la lista de permisos, devuelve array de string.
|
113
|
+
|
114
|
+
ejempos de uso:
|
115
|
+
|
116
|
+
```js
|
117
|
+
// EJEMPLO 1
|
118
|
+
@Get(':id')
|
119
|
+
@BearerAuthPermision()
|
120
|
+
findOne(@Param('id') id: number) {
|
121
|
+
return this.casosPersonaService.findOne(+id);
|
122
|
+
}
|
123
|
+
|
124
|
+
// EJEMPLO 2
|
125
|
+
@Post('test-seguridad')
|
126
|
+
@BearerAuthPermision(['ALGUN_PERMISOS'])
|
127
|
+
async test(
|
128
|
+
@Body() body: TokenBody,
|
129
|
+
@AuthUser() user: UserPayload, // controlador
|
130
|
+
@AuthToken() token: string,
|
131
|
+
@AuthPermissions() permissions: string[],
|
132
|
+
) {
|
133
|
+
return {
|
134
|
+
some: 'algo',
|
135
|
+
};
|
136
|
+
}
|
137
|
+
```
|
138
|
+
|
139
|
+
# USO DEL SERVICIO `MS-REDIS`
|
140
|
+
Antes de utilizar el módulo, asegúrese de tener las siguientes variables de entorno configuradas:
|
141
|
+
|
142
|
+
- `ENV_GRPC_MS_REDIS_CACHE`: la URL del servidor de cacheo de redis a través de gRPC.
|
143
|
+
|
144
|
+
## Uso
|
145
|
+
|
146
|
+
Para utilizar el módulo, primero importe `MsRedisModule` en su módulo principal:
|
147
|
+
|
148
|
+
```typescript
|
149
|
+
import { Module } from '@nestjs/common';
|
150
|
+
import { MsRedisModule } from 'fiscalia_bo-nest-helpers/seguridad';
|
151
|
+
|
152
|
+
@Module({
|
153
|
+
imports: [
|
154
|
+
ConfigModule.forRoot({ isGlobal: true }),
|
155
|
+
|
156
|
+
// Register ms-seguridad module global
|
157
|
+
MsRedisModule.register({ urlRedisCache: process.env.ENV_GRPC_MS_REDIS_CACHE || '' }),
|
158
|
+
],
|
159
|
+
controllers: [],
|
160
|
+
providers: [],
|
161
|
+
})
|
162
|
+
export class AppModule {}
|
163
|
+
```
|
164
|
+
## Servicios disponibles
|
165
|
+
|
166
|
+
- MsRedisService
|
167
|
+
### Nomenclatura de asignacion de key para redis
|
168
|
+
|
169
|
+
|
170
|
+
```txt
|
171
|
+
aplicacion-name:key_One-key_Two-key_Three-keyAcction
|
172
|
+
```
|
173
|
+
ejemplo de asignacion de key para redis
|
174
|
+
```js
|
175
|
+
const keyCache = `ms-seguridad:usuarioId_${usuarioId}-aplicacionId_${aplicacionId}-permisos`;
|
176
|
+
```
|
177
|
+
|
178
|
+
# Información
|
84
179
|
|
85
180
|
- Author - [UTIC](mailto:informatica@fiscalia.gob.bo)
|
86
181
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ms-seguridad.decorator.js","sourceRoot":"","sources":["../../src/ms-seguridad/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