Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/services/control-plane/adapters/drivens/index.ts
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);
}
}
1 change: 1 addition & 0 deletions src/services/control-plane/adapters/drivers/index.ts
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){}

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

Suggested change
constructor(private readonly controlPlane: ControlPlane){}
constructor(private readonly controlPlane: ControlPlane){}

async getAuthDetails(email: string, password: string): Promise<AuthDetails>{
return this.controlPlane.getAuthDetails(email,password);
}

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

Suggested change
}
}

async getPermissions(email: string, password: string): Promise<Permissions>{
return this.controlPlane.getPermissions(email,password);
}
}
20 changes: 20 additions & 0 deletions src/services/control-plane/app/composition-root.ts
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
}
}

31 changes: 31 additions & 0 deletions src/services/control-plane/app/control-plane.test.ts
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"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agregar los

// GIVEN
// WHEN
// THEN

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)
})
})
18 changes: 18 additions & 0 deletions src/services/control-plane/app/control-plane.ts
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

Choose a reason for hiding this comment

The 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"})

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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.
En tu caso te faltaría un for-authenticating al que luego le generarás un adapter que lo implemente de tipo stub y que este devuelva si está o no authenticado el user.

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

}

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

Suggested change
}
}

async getPermissions(email: string, password: string): Promise<Permissions> {
return Promise.resolve({admin:true,user:true})
}
}
8 changes: 8 additions & 0 deletions src/services/control-plane/app/schemas/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface AuthDetails{
token:string;
refreshToken:string;
}

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

Suggested change
}
}

export interface Permissions{
admin: boolean;
user: boolean;
}
1 change: 1 addition & 0 deletions src/services/control-plane/app/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './auth';
7 changes: 7 additions & 0 deletions src/services/control-plane/ports/drivens/for-monitoring.ts
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
}
1 change: 1 addition & 0 deletions src/services/control-plane/ports/drivens/index.ts
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{

Choose a reason for hiding this comment

The 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>;
}
1 change: 1 addition & 0 deletions src/services/control-plane/ports/drivers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './for-managing-authentication';