-
Notifications
You must be signed in to change notification settings - Fork 17
feat: implement control plane #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './logger-stub-adapter'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { ForMonitoring } from "../../ports/drivens"; | ||
//es un stub que es basicamente un MOCK donde simulamos que solicitamos algo a otro hexagono | ||
//esto se hace para probarlo | ||
export class LoggerStubAdapter implements ForMonitoring { | ||
log(event: string, message: string) { | ||
console.log(event, message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './managing-authentication-proxy-adapter'; |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||
import { ControlPlane } from '../../app/control-plane'; | ||||||||
import { AuthDetails,Permissions } from '../../app/schemas'; | ||||||||
import { ForManagerAuthentication } from '../../ports/drivers'; | ||||||||
|
||||||||
export class ManagerAuthenticationProxyAdapter implements ForManagerAuthentication{ | ||||||||
constructor(private readonly controlPlane: ControlPlane){} | ||||||||
async getAuthDetails(email: string, password: string): Promise<AuthDetails>{ | ||||||||
return this.controlPlane.getAuthDetails(email,password); | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agregar espacios entre unidades lógicas
Suggested change
|
||||||||
async getPermissions(email: string, password: string): Promise<Permissions>{ | ||||||||
return this.controlPlane.getPermissions(email,password); | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Aqui se crea la instancia del hexagono que le da todo lo que necesita para funcionar | ||
//habilita la posibilidad de utilizarlo en forma de mock | ||
|
||
import { ControlPlane } from "./control-plane" | ||
import { LoggerStubAdapter } from '../../repository/adapters/drivens/logger-stub-adapter'; | ||
import { ForManagerAuthentication } from '../ports/drivers'; | ||
import { ManagerAuthenticationProxyAdapter } from "../adapters/drivers/managing-authentication-proxy-adapter"; | ||
|
||
const compositionMock =()=>{ | ||
const loggerStubAdapter = new LoggerStubAdapter(); | ||
const controlPlaneMock = new ControlPlane(loggerStubAdapter);//aqui se ocupa el STUB | ||
|
||
const managerAuthenticationProxy = new ManagerAuthenticationProxyAdapter(controlPlaneMock) | ||
//el driveR del adaptador es el que se utiliza para poder manejar el hexagono y asi poder control los accesos a sus metodos | ||
//NUNCA se se pasa el hexagono | ||
return { | ||
managerAuthenticationProxy | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { describe, it,expect } from "vitest"; | ||
import { LoggerStubAdapter } from "../adapters/drivens"; | ||
import { ControlPlane } from "./control-plane"; | ||
import { ManagerAuthenticationProxyAdapter } from "../adapters/drivers"; | ||
|
||
describe("ControlPlane",()=>{ | ||
const loggerStubAdapter = new LoggerStubAdapter(); | ||
const controlPlaneMock = new ControlPlane(loggerStubAdapter);//aqui se ocupa el STUB | ||
|
||
// const managerAuthenticationProxy = new ManagerAuthenticationProxyAdapter(controlPlaneMock) | ||
|
||
it.concurrent("should get auth description", async()=>{ | ||
const mockedUser = {email:"[email protected]",password:"123"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agregar los // GIVEN |
||
const expectedResult={token:"123", refreshToken:"1234"} | ||
//TODO | ||
//Cambia este resultado, di que se espera recibir un objeto que contec | ||
|
||
const result = await controlPlaneMock.getAuthDetails(mockedUser.email,mockedUser.password); | ||
expect(result).toEqual(expectedResult) | ||
}) | ||
|
||
it.concurrent("should get permissions", async()=>{ | ||
const mockedUser = {email:"[email protected]",password:"123"} | ||
const expectedResult={admin:true, user:true} | ||
//TODO | ||
//Cambia este resultado, di que se espera recibir un objeto que contec | ||
|
||
const result = await controlPlaneMock.getPermissions(mockedUser.email,mockedUser.password); | ||
expect(result).toEqual(expectedResult) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||
import { ForManagerAuthentication } from "../ports/drivers"; | ||||||||
import { ForMonitoring } from '../ports/drivens/for-monitoring'; | ||||||||
import { AuthDetails,Permissions } from "./schemas"; | ||||||||
//Mi hexagono que tiene implementado los puertos de los driveR, en este caso es solo uno pero podrian ser mas | ||||||||
export class ControlPlane implements ForManagerAuthentication{ | ||||||||
//el Constructor los DriverN del puerto, osea que son los recurson necesario para que mi hexagono funcione | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ojo con los errores de ortografía en los comments y siempre en inglés |
||||||||
constructor(private readonly forMonitoring: ForMonitoring){} | ||||||||
|
||||||||
//Los metodos de mi hexagono que vienen de los driveR de los pruertos | ||||||||
async getAuthDetails(email: string, password: string): Promise<AuthDetails> { | ||||||||
|
||||||||
// const authDetails = await this. | ||||||||
return Promise.resolve({token:"123", refreshToken:"1234"}) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aquí te faltan los adapters que te resuelven la authentication, normalmente utilizarías una tecnología como jwt o similares y para comunicarte con la misma necesitas de un adapter, así de esta manera la información que entra en la app y la que sale hacia afuera siguen útiles y sin conflictos There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahora mismo solo tienes los puertos de entrada al hexágono, que no esta mal, pero faltarían los puertos driven que se comunican con otros hexágonos o herramientas a nivel interno para obtener los recursos. La lógica que guardas en el servicio en sí, en tu caso el control plane, siempre es de negocio. Por ejemplo y fuera de este contexto, si la persona esta logueada generar un log, guardar en una base de datos aparte y devolver esta informacion al usuario es parte de la lógica de negocios; Pero cómo se realiza el log, cómo se guarda en la base de datos, es algo externo a la lógica de negocios, y es responsabilidad de otro servicio o herramienta aparte, en nuestro caso el logger es una herramienta y el manejo en la base de datos lo haría el servicio repository que ya tenemos hecho. Y para cada uno de estos casos deberíamos de tener un adapter que comunique la información |
||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agregar espacios entre unidades lógicas
Suggested change
|
||||||||
async getPermissions(email: string, password: string): Promise<Permissions> { | ||||||||
return Promise.resolve({admin:true,user:true}) | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||||||
export interface AuthDetails{ | ||||||||
token:string; | ||||||||
refreshToken:string; | ||||||||
} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agregar espacios entre unidades lógicas
Suggested change
|
||||||||
export interface Permissions{ | ||||||||
admin: boolean; | ||||||||
user: boolean; | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './auth'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//Los driverN del puerto describer los recursos que necesito de otros hexagonos en este caso | ||
//el hexagono de control plane no necesita nada de otro hexagono | ||
//por lo cual el driveN se va a encargar de hacer el monitoreo | ||
|
||
export interface ForMonitoring { | ||
log(event:string,message:string):void | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './for-monitoring'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AuthDetails,Permissions } from "../../app/schemas"; | ||
|
||
//Los driveR de los Puertos son los que describen mi hexagono, mis CONTRATOS | ||
//en este caso el hexagono de control plane tiene dar detalles de autenticacion y los permisos de los usuarios | ||
export interface ForManagerAuthentication{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debería de ser igual al nombre del file, "ForMangingAuthentication" |
||
getAuthDetails(email: string, password: string): Promise<AuthDetails>; | ||
getPermissions(email: string, password: string): Promise<Permissions>; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './for-managing-authentication'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agregar espacios entre unidades lógicas