Agente https para certificados
This commit is contained in:
@@ -6,6 +6,7 @@ ENVIORMENT=development
|
|||||||
ALAI_API_URL=https://wsaccess.alaisecure.com/bssrest
|
ALAI_API_URL=https://wsaccess.alaisecure.com/bssrest
|
||||||
|
|
||||||
ALAI_CERTIFICATES_DIR=./certificates/
|
ALAI_CERTIFICATES_DIR=./certificates/
|
||||||
|
ALAI_CERTIFICATE_NAME=wsaccess_alaisecure_com_cert_client_new.p12
|
||||||
ALAI_USERNAME=palomaibanez
|
ALAI_USERNAME=palomaibanez
|
||||||
ALAI_PASSWORD=palomaibanez1234
|
ALAI_PASSWORD=palomaibanez1234
|
||||||
ALAI_BRANDID=savefamily
|
ALAI_BRANDID=savefamily
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ export class SimAlaiController {
|
|||||||
iccid: iccid,
|
iccid: iccid,
|
||||||
correlation_id: correlation_id
|
correlation_id: correlation_id
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { SimAlaiController } from "./SimAlai.controller.js";
|
|||||||
|
|
||||||
type FuncType = ((m: ConsumeMessage) => Promise<Result<string, any>>)
|
type FuncType = ((m: ConsumeMessage) => Promise<Result<string, any>>)
|
||||||
|
|
||||||
export class SimNosRouter {
|
export class SimAlaiRouter {
|
||||||
private readonly routes: Map<string, FuncType>;
|
private readonly routes: Map<string, FuncType>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -8,23 +8,22 @@
|
|||||||
* - Control de errores más preciso
|
* - Control de errores más preciso
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { AlaiHttpClient } from "#infrastructure/NosHttpClient.js";
|
import { AlaiRepository } from "#infrastructure/AlaiRepository.js";
|
||||||
import { NosRepository } from "#infrastructure/AlaiRepository.js";
|
import { ConsumeMessage } from "amqplib";
|
||||||
import { ErrorOrderDTO, FinishOrderDTO, UpdateOrderDTO } from "sim-shared/domain/Order.js";
|
import { ErrorOrderDTO, FinishOrderDTO, UpdateOrderDTO } from "sim-shared/domain/Order.js";
|
||||||
import { Result } from "sim-shared/domain/Result.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";
|
import { OrderRepository } from "sim-shared/infrastructure/OrderRepository.js";
|
||||||
|
|
||||||
export class SimAlaiUsecases {
|
export class SimAlaiUsecases {
|
||||||
constructor(
|
constructor(
|
||||||
private httpClient: NosHttpClient,
|
private httpClient: HttpClient,
|
||||||
private nosRepository: NosRepository,
|
private alaiRepository: AlaiRepository,
|
||||||
private orderRepository: OrderRepository
|
private orderRepository: OrderRepository
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private async setRunning(correlation_id: string) {
|
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 = {
|
const updateData: UpdateOrderDTO = {
|
||||||
new_status: "running",
|
new_status: "running",
|
||||||
correlation_id: correlation_id
|
correlation_id: correlation_id
|
||||||
@@ -101,56 +100,33 @@ export class SimAlaiUsecases {
|
|||||||
|
|
||||||
public activate(args: {
|
public activate(args: {
|
||||||
iccid: string,
|
iccid: string,
|
||||||
correlation_id?: string
|
correlation_id: string | undefined
|
||||||
}) {
|
}) {
|
||||||
return this.usecaseTemplate(
|
return this.usecaseTemplate(async (args /*iccid*/) => {
|
||||||
(args) => this.nosRepository.activateSim(args), args.iccid, args.correlation_id)
|
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: {
|
public suspend(args: {
|
||||||
iccid: string,
|
iccid: string,
|
||||||
correlation_id?: string
|
correlation_id: string | undefined
|
||||||
}) {
|
}) {
|
||||||
return this.usecaseTemplate(
|
return this.usecaseTemplate(async (args /*iccid*/) => {
|
||||||
(args) => this.nosRepository.bar(args), args.iccid, args.correlation_id)
|
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 express from "express"
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import { env } from "#config/env/env.js"
|
import { env } from "#config/env/env.js"
|
||||||
import { pgClient } from "#config/postgreConfig.js";
|
|
||||||
import { startRMQClient } from "#config/eventBus.config.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 RMQ_QUEUE = "sim.alai"
|
||||||
const NOS_BASE_URL = env.NOS_BASE_URL
|
const PORT = env.ALAI_PORT
|
||||||
const PORT = env.APP_PORT
|
const HOSTNAME = env.ALAI_HOST
|
||||||
const HOSTNAME = env.APP_HOST
|
|
||||||
|
|
||||||
async function startWorker() {
|
async function startWorker() {
|
||||||
// Instancia de dependencias
|
// Instancia de dependencias
|
||||||
|
|
||||||
const rmqClient = await startRMQClient()
|
const rmqClient = await startRMQClient()
|
||||||
|
|
||||||
const simRouter = new SimNosRouter(
|
const orderRepository = new OrderRepository(pgClient)
|
||||||
simController,
|
|
||||||
|
const alaiRepository = new AlaiRepository(alaiHttp)
|
||||||
|
|
||||||
|
const alaiUsecases = new SimAlaiUsecases(
|
||||||
|
alaiHttp,
|
||||||
|
alaiRepository,
|
||||||
|
orderRepository
|
||||||
|
)
|
||||||
|
|
||||||
|
const alaiController = new SimAlaiController(
|
||||||
|
alaiUsecases,
|
||||||
|
rmqClient
|
||||||
|
)
|
||||||
|
|
||||||
|
const simRouter = new SimAlaiRouter(
|
||||||
|
alaiController,
|
||||||
rmqClient
|
rmqClient
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,8 +50,9 @@ async function startWorker() {
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
app.get("/select", simController.selectREST())
|
// WIP
|
||||||
app.get("/selectPage", simController.selectPageREST())
|
app.get("/select", alaiController.selectREST())
|
||||||
|
app.get("/selectPage", alaiController.selectPageREST())
|
||||||
|
|
||||||
app.listen(PORT, HOSTNAME, (e) => {
|
app.listen(PORT, HOSTNAME, (e) => {
|
||||||
if (e == undefined) {
|
if (e == undefined) {
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import { AlaiAPI } from "#domain/AlaiAPI.js";
|
import { AlaiAPI } from "#domain/AlaiAPI.js";
|
||||||
import axios, { AxiosError, AxiosResponse } from "axios";
|
import axios, { AxiosError, AxiosResponse } from "axios";
|
||||||
import { AlaiHttpClient } from "./AlaiHttpClient.js";
|
|
||||||
import { Result } from "sim-shared/domain/Result.js";
|
import { Result } from "sim-shared/domain/Result.js";
|
||||||
import { env } from "#config/env/env.js";
|
import { env } from "#config/env/env.js";
|
||||||
|
import { HttpClient } from "sim-shared/infrastructure/HTTPClient.js";
|
||||||
|
|
||||||
export class AlaiRepository {
|
export class AlaiRepository {
|
||||||
constructor(
|
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 {
|
try {
|
||||||
const res = await promise
|
const res = await promiseReq
|
||||||
return {
|
return {
|
||||||
data: res.data
|
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}`
|
const ENDPOINT = `/v1/sim/${iccid}/order/${order}`
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user