Agente https para certificados
This commit is contained in:
@@ -6,6 +6,7 @@ ENVIORMENT=development
|
||||
ALAI_API_URL=https://wsaccess.alaisecure.com/bssrest
|
||||
|
||||
ALAI_CERTIFICATES_DIR=./certificates/
|
||||
ALAI_CERTIFICATE_NAME=wsaccess_alaisecure_com_cert_client_new.p12
|
||||
ALAI_USERNAME=palomaibanez
|
||||
ALAI_PASSWORD=palomaibanez1234
|
||||
ALAI_BRANDID=savefamily
|
||||
|
||||
@@ -89,7 +89,6 @@ export class SimAlaiController {
|
||||
iccid: iccid,
|
||||
correlation_id: correlation_id
|
||||
}))
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { SimAlaiController } from "./SimAlai.controller.js";
|
||||
|
||||
type FuncType = ((m: ConsumeMessage) => Promise<Result<string, any>>)
|
||||
|
||||
export class SimNosRouter {
|
||||
export class SimAlaiRouter {
|
||||
private readonly routes: Map<string, FuncType>;
|
||||
|
||||
constructor(
|
||||
|
||||
@@ -8,23 +8,22 @@
|
||||
* - Control de errores más preciso
|
||||
*
|
||||
*/
|
||||
import { AlaiHttpClient } from "#infrastructure/NosHttpClient.js";
|
||||
import { NosRepository } from "#infrastructure/AlaiRepository.js";
|
||||
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
||||
import { ConsumeMessage } from "amqplib";
|
||||
import { ErrorOrderDTO, FinishOrderDTO, UpdateOrderDTO } from "sim-shared/domain/Order.js";
|
||||
import { Result } from "sim-shared/domain/Result.js";
|
||||
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
||||
import { OrderRepository } from "sim-shared/infrastructure/OrderRepository.js";
|
||||
|
||||
export class SimAlaiUsecases {
|
||||
constructor(
|
||||
private httpClient: NosHttpClient,
|
||||
private nosRepository: NosRepository,
|
||||
private httpClient: HttpClient,
|
||||
private alaiRepository: AlaiRepository,
|
||||
private orderRepository: OrderRepository
|
||||
) {
|
||||
}
|
||||
|
||||
private async setRunning(correlation_id: string) {
|
||||
// En NOS el updateOrder se hace con el correlation_id que viene en la cabecera del
|
||||
// mensaje consumido
|
||||
const updateData: UpdateOrderDTO = {
|
||||
new_status: "running",
|
||||
correlation_id: correlation_id
|
||||
@@ -101,56 +100,33 @@ export class SimAlaiUsecases {
|
||||
|
||||
public activate(args: {
|
||||
iccid: string,
|
||||
correlation_id?: string
|
||||
correlation_id: string | undefined
|
||||
}) {
|
||||
return this.usecaseTemplate(
|
||||
(args) => this.nosRepository.activateSim(args), args.iccid, args.correlation_id)
|
||||
return this.usecaseTemplate(async (args /*iccid*/) => {
|
||||
const order = await this.alaiRepository.createOrder()
|
||||
if (order.error != undefined) {
|
||||
// Falla el crearse un order (problema de servidor, token, etc)
|
||||
console.error(order.error)
|
||||
return order
|
||||
}
|
||||
const reserved = await this.alaiRepository.createReserve(order.data.id, args)
|
||||
return reserved
|
||||
}, args.iccid, args.correlation_id)
|
||||
}
|
||||
|
||||
public suspend(args: {
|
||||
iccid: string,
|
||||
correlation_id?: string
|
||||
correlation_id: string | undefined
|
||||
}) {
|
||||
return this.usecaseTemplate(
|
||||
(args) => this.nosRepository.bar(args), args.iccid, args.correlation_id)
|
||||
return this.usecaseTemplate(async (args /*iccid*/) => {
|
||||
const order = await this.alaiRepository.createOrder()
|
||||
if (order.error != undefined) {
|
||||
// Falla el crearse un order (problema de servidor, token, etc)
|
||||
console.error(order.error)
|
||||
return order
|
||||
}
|
||||
const reserved = await this.alaiRepository.createReserve(order.data.id, args)
|
||||
return reserved
|
||||
}, args.iccid, args.correlation_id)
|
||||
}
|
||||
|
||||
public reactivate(args: {
|
||||
iccid: string,
|
||||
correlation_id?: string
|
||||
}) {
|
||||
return this.usecaseTemplate(
|
||||
(args) => this.nosRepository.unbar(args), args.iccid, args.correlation_id)
|
||||
}
|
||||
|
||||
public terminate(args: { iccid: string }) {
|
||||
throw new Error("No hay termination para NOS")
|
||||
}
|
||||
|
||||
/* Importante: Las operaciones de lectua no dejan registro en orders */
|
||||
|
||||
public async selectOne(args: {
|
||||
iccid: string
|
||||
}) {
|
||||
const res = await this.nosRepository.getLineInfo(args.iccid)
|
||||
return res
|
||||
}
|
||||
|
||||
public async selectPage(args: {
|
||||
offset?: number,
|
||||
limit?: number,
|
||||
filter?: string,
|
||||
orderBy?: string
|
||||
}) {
|
||||
const res = await this.nosRepository.getLinePage(args)
|
||||
return res
|
||||
}
|
||||
|
||||
/**
|
||||
public selectMany(args: {
|
||||
iccid: string[]
|
||||
}) {
|
||||
return {}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
19
packages/sim-consumidor-alai/config/httpsAgent.ts
Normal file
19
packages/sim-consumidor-alai/config/httpsAgent.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import fs from 'fs';
|
||||
import https from 'https';
|
||||
import axios from 'axios';
|
||||
import { env } from './env/env.js';
|
||||
import path from 'path';
|
||||
|
||||
const certificatesDir = env.ALAI_CERTIFICATES_DIR
|
||||
const certificateName = env.ALAI_CERTIFICATE_NAME
|
||||
// ...
|
||||
const httpsAgent = new https.Agent({
|
||||
pfx: fs.readFileSync(path.join(certificatesDir, 'keystore.p12')),
|
||||
passphrase: '<your_keystore_passphrase_here>'
|
||||
});
|
||||
|
||||
// TODO: EJEMPLO, METER EN EL HTTP CLIENT
|
||||
const result = await axios.get('https://myserver.internal.net:9443', { httpsAgent });
|
||||
// do something with the result
|
||||
|
||||
// ...
|
||||
@@ -1,22 +1,41 @@
|
||||
import express from "express"
|
||||
import cors from 'cors';
|
||||
import { env } from "#config/env/env.js"
|
||||
import { pgClient } from "#config/postgreConfig.js";
|
||||
import { startRMQClient } from "#config/eventBus.config.js";
|
||||
import { SimNosRouter } from "#aplication/SimAlai.router.js";
|
||||
import { SimAlaiRouter } from "#aplication/SimAlai.router.js";
|
||||
import { SimAlaiController } from "#aplication/SimAlai.controller.js";
|
||||
import { SimAlaiUsecases } from "#aplication/SimAlai.usecases.js";
|
||||
import { alaiHttp } from "#config/httpClient.config.js";
|
||||
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
||||
import { OrderRepository } from "sim-shared/infrastructure/OrderRepository.js";
|
||||
import { pgClient } from "#config/postgreConfig.js";
|
||||
|
||||
const RMQ_QUEUE = "sim.alai"
|
||||
const NOS_BASE_URL = env.NOS_BASE_URL
|
||||
const PORT = env.APP_PORT
|
||||
const HOSTNAME = env.APP_HOST
|
||||
const PORT = env.ALAI_PORT
|
||||
const HOSTNAME = env.ALAI_HOST
|
||||
|
||||
async function startWorker() {
|
||||
// Instancia de dependencias
|
||||
|
||||
const rmqClient = await startRMQClient()
|
||||
|
||||
const simRouter = new SimNosRouter(
|
||||
simController,
|
||||
const orderRepository = new OrderRepository(pgClient)
|
||||
|
||||
const alaiRepository = new AlaiRepository(alaiHttp)
|
||||
|
||||
const alaiUsecases = new SimAlaiUsecases(
|
||||
alaiHttp,
|
||||
alaiRepository,
|
||||
orderRepository
|
||||
)
|
||||
|
||||
const alaiController = new SimAlaiController(
|
||||
alaiUsecases,
|
||||
rmqClient
|
||||
)
|
||||
|
||||
const simRouter = new SimAlaiRouter(
|
||||
alaiController,
|
||||
rmqClient
|
||||
)
|
||||
|
||||
@@ -31,8 +50,9 @@ async function startWorker() {
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
app.get("/select", simController.selectREST())
|
||||
app.get("/selectPage", simController.selectPageREST())
|
||||
// WIP
|
||||
app.get("/select", alaiController.selectREST())
|
||||
app.get("/selectPage", alaiController.selectPageREST())
|
||||
|
||||
app.listen(PORT, HOSTNAME, (e) => {
|
||||
if (e == undefined) {
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { AlaiAPI } from "#domain/AlaiAPI.js";
|
||||
import axios, { AxiosError, AxiosResponse } from "axios";
|
||||
import { AlaiHttpClient } from "./AlaiHttpClient.js";
|
||||
import { Result } from "sim-shared/domain/Result.js";
|
||||
import { env } from "#config/env/env.js";
|
||||
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
||||
|
||||
export class AlaiRepository {
|
||||
constructor(
|
||||
private httpClient: AlaiHttpClient
|
||||
private httpClient: HttpClient
|
||||
) {
|
||||
}
|
||||
|
||||
private async manageRequest<E, T>(promise: Promise<AxiosResponse<T>>): Promise<Result<string, T>> {
|
||||
private async manageRequest<E, T>(promiseReq: Promise<AxiosResponse<T>>): Promise<Result<string, T>> {
|
||||
try {
|
||||
const res = await promise
|
||||
const res = await promiseReq
|
||||
return {
|
||||
data: res.data
|
||||
}
|
||||
@@ -87,7 +87,7 @@ export class AlaiRepository {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public async createReserve(order: string, iccid: string) {
|
||||
public async createReserve(order: string, iccid: string): Promise<Result<string, string>> {
|
||||
const ENDPOINT = `/v1/sim/${iccid}/order/${order}`
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user