Skip to content
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

[IOPAY-402] update node 14 & fp-ts #320

Merged
merged 39 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
80ad603
[IOPAY-402] update node version and necessary dependency
infantesimone Dec 21, 2021
08d50b8
[IOPAY-402] update to eslint
infantesimone Dec 22, 2021
cbaa0e3
lint app.ts
infantesimone Dec 22, 2021
3350575
lint & fix configuration.ts
infantesimone Dec 22, 2021
ada2eec
Update imports and fix old `fp-ts` usages
giovanniberti Dec 22, 2021
2fde682
Update imports and refactor code using `fp-ts`
giovanniberti Dec 22, 2021
78950bc
[IOPAY-402] update fp-ts & linting
infantesimone Dec 22, 2021
c3462e4
Finish fixing source tree `fp-ts` usages
giovanniberti Dec 23, 2021
bd7445a
[IOPAY--402] fix payment converter
infantesimone Dec 23, 2021
f6d9c8a
Update `fp-ts` usages in `MockedData.ts`
giovanniberti Dec 23, 2021
7ff3ca3
[IOPAY-402] fix fake data for integration tests
infantesimone Dec 23, 2021
7020ed1
Update `fp-ts` usages in `PaymentController.test.ts`
giovanniberti Dec 23, 2021
d7cae9f
[IOPAY-402] new pagopa.ts custom
infantesimone Dec 23, 2021
cdbc9bd
[IOPAY-402] fix integrations tests
infantesimone Dec 23, 2021
7504ed7
Update comment regarding type conversion inside `PaymentsConverter.ts`
giovanniberti Dec 23, 2021
5255244
Update `node` version inside Docker images
giovanniberti Dec 23, 2021
7d83ff9
Fix wrong app source path in Dockerfile for eslint config
giovanniberti Dec 23, 2021
674aa38
Fix parameter name in `/payment-requests` controller route
giovanniberti Dec 23, 2021
fa5bc0d
Update node version in code review pipeline
giovanniberti Dec 31, 2021
7eb685f
Add test stage in deploy pipeline
giovanniberti Dec 31, 2021
5923023
Add yaml pipelines under pagopa subscription
giovanniberti Jan 3, 2022
40ac0f8
[IOPAY-402] rename api tests folder
infantesimone Jan 3, 2022
b4421d6
[IOPAY-402] delete old pipelines
infantesimone Jan 3, 2022
5660591
disable detectOpenHandles
infantesimone Jan 3, 2022
7be7c0b
enable pipeline only for dev env
infantesimone Jan 3, 2022
ee52e47
[IOPAY-402] fix endpoint for pagopaCommons yml templates
infantesimone Jan 3, 2022
d7a487c
[IOPAY-402] fix deploy pipeline
infantesimone Jan 3, 2022
f7d9655
fix resourceGroupName in deploy pipeline
infantesimone Jan 4, 2022
bf0bba3
Fix tests working directory
giovanniberti Jan 4, 2022
5036605
Fix redis client config for non-cluster connection
giovanniberti Jan 5, 2022
0a7f486
Refactor API test script to accept arbitrary env files
giovanniberti Jan 5, 2022
33e5e0d
Enable TLS on redis single instance only when redis password is supplied
giovanniberti Jan 7, 2022
4584671
Fix wrong return value in cdInfoWisp service `setActivationStatus` fu…
giovanniberti Jan 10, 2022
7f7fed5
[IOPAY-402] Separate ws endpoint for nodoPerPsp, nodeForPsp and nodeF…
infantesimone Jan 11, 2022
49ff741
fix dispalyName in Deploy_DEV_pagoPA stage
infantesimone Jan 11, 2022
9db7035
Add postman environment to test deployed proxy API
giovanniberti Jan 5, 2022
eacbf0a
update deploy pipeline in order to UAT deploy
infantesimone Jan 12, 2022
bf487e0
fix dependensOn for uat deploy pipeline
infantesimone Jan 12, 2022
cfd95ce
[IOPAY-402] Add check branch in release stage
infantesimone Jan 14, 2022
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
2 changes: 1 addition & 1 deletion .devops/code-review-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#

variables:
NODE_VERSION: '8.9.4'
NODE_VERSION: '14.16.0'
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn

# Automatically triggered on PR
Expand Down
37 changes: 35 additions & 2 deletions .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ parameters:
- prod

variables:
NODE_VERSION: '8.9.4'
NODE_VERSION: '14.16.0'
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
ENV: ${{ parameters.ENV }}

Expand Down Expand Up @@ -154,7 +154,40 @@ stages:
package: '$(Pipeline.Workspace)/Bundle'
deploymentMethod: 'auto'
displayName: Deploy to production slot


- stage: Api_test
dependsOn:
- Deploy_test
jobs:
- job: 'TestAPI'
steps:
- checkout: none

- download: current
artifact: Bundle

- job: waitStartup
Copy link
Contributor

Choose a reason for hiding this comment

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

is this necessary to wait proxy get up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right, thanks

steps:
- task: Delay@1
inputs:
delayForMinutes: '5'

- job: integrationTests
dependsOn: waitStartup
steps:
- script: |
yarn global add newman
displayName: 'newman installation'

- task: Bash@3
inputs:
targetType: filePath
filePath: k6example/ws.sh
arguments: postman
workingDirectory: k6example
Copy link
Contributor

Choose a reason for hiding this comment

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

could be better to rename k6example folder in to api-test

failOnStdErr: true
displayName: Run API tests

- stage: Deploy_production
dependsOn:
- Prepare_artifact
Expand Down
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
"env": {
"es6": true,
"node": true
},
"ignorePatterns": [
"node_modules",
"generated",
"**/__tests__/*",
"**/__mocks__/*",
"*.d.ts",
"*.js",
"Dangerfile.ts",
"**/__integration__/*"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"sourceType": "module"
},
"extends": [
"@pagopa/eslint-config/strong",
],
"rules": {}
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ generated
.env
.DS_Store
k6example/libs
.eslintcache
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.9.4
14.16.0
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM circleci/node:8.9.4 as builder
FROM circleci/node:14.16.0 as builder

RUN sudo apt-get -y install --no-install-recommends libunwind8=1.1-3.2
RUN sudo apt-get -y install --no-install-recommends libunwind8=1.1-4.1

WORKDIR /usr/src/app

Expand All @@ -10,12 +10,13 @@ COPY /package.json /usr/src/app/package.json
COPY /tsconfig.json /usr/src/app/tsconfig.json
COPY /yarn.lock /usr/src/app/yarn.lock
COPY /api_pagopa.yaml /usr/src/app/api_pagopa.yaml
COPY /.eslintrc.js /usr/src/app/.eslintrc.js

RUN sudo chmod -R 777 /usr/src/app \
&& yarn install \
&& yarn build

FROM node:8.9.4-alpine
FROM node:14.16.0-alpine
LABEL maintainer="https://teamdigitale.governo.it"

# Install major CA certificates to cover
Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@
"generate:ts-from-yaml:nodeNm3psp": "shx mkdir -p generated/nodeNm3psp && rimraf generated/nodeNm3psp/* && gen-api-models --strict 0 --api-spec generated/yaml-file/nodeForPsp_Service.yaml --out-dir generated/nodeNm3psp",
"generate:ts-from-yaml:nodeNm3io": "shx mkdir -p generated/nodeNm3io && rimraf generated/nodeNm3io/* && gen-api-models --strict 0 --api-spec generated/yaml-file/nodeForIO_Service.yaml --out-dir generated/nodeNm3io",
"generate:yaml-from-wsdl": "shx mkdir -p generated/yaml-file && rimraf generated/yaml-file/* && node pagopa_api/YamlGenerator.js",
"generate:proxy-api-models": "shx mkdir -p generated/api && rimraf generated/api/* && gen-api-models --api-spec ./api_pagopa.yaml --out-dir generated/api --ts-spec-file generated/api/public_api_pagopa.ts --request-types",
"generate:proxy-api-models": "shx mkdir -p generated/api && rimraf generated/api/* && gen-api-models --api-spec ./api_pagopa.yaml --out-dir generated/api --request-types",
"prettify": "prettier --write \"./**/*.ts\"",
"start": "node dist/src/index.js",
"test:coverage": "jest --runInBand --coverage",
"test:integration": "jest --config=jest.integration.js --runInBand",
"test:coverage": "jest --runInBand --coverage --detectOpenHandles",
Copy link
Contributor

Choose a reason for hiding this comment

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

with --detectOpenHandles option , when i runs test i retrieve the following nasty warning message

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  TCPWRAP

is it correct to display it? or is there a way to disable it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added for some debugging, but we can disable, thanks

"test:integration": "jest --config=jest.integration.js --runInBand --detectOpenHandles",
"test": "npm-run-all -s test:*",
"lint": "tslint --project .",
"lint": "eslint . -c .eslintrc.js --ext .ts,.tsx --cache",
"postversion": "git push && git push --tags",
"dist:modules": "modclean -r -n default:safe",
"predeploy": "npm-run-all build dist:modules",
"preversion": "auto-changelog --config .auto-changelog.json --unreleased --commit-limit false --stdout --template preview.hbs",
"version": "auto-changelog -p --config .auto-changelog.json --unreleased && git add CHANGELOG.md"
},
"devDependencies": {
"@pagopa/eslint-config": "^1.3.1",
"@types/bluebird": "^3.5.24",
"@types/debug": "0.0.30",
"@types/express": "^4.11.1",
"@types/jest": "^23.3.2",
"@types/jest": "^27.0.3",
"@types/morgan": "^1.7.35",
"@types/node": "^8.9.4",
"@types/node-fetch": "^2.1.1",
Expand All @@ -51,27 +52,26 @@
"auto-changelog": "^2.2.1",
"danger": "^7.1.4",
"danger-plugin-digitalcitizenship": "^0.3.1",
"italia-tslint-rules": "^1.1.3",
"italia-utils": "^4.0.1",
"jest": "^23.6.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.4.5",
"jest-xml-matcher": "^1.1.1",
"js-yaml": "^3.13.1",
"modclean": "^3.0.0-beta.1",
"npm-run-all": "^4.1.3",
"prettier": "^1.14.3",
"rimraf": "^2.6.3",
"shx": "^0.3.2",
"shx": "^0.3.3",
"supertest": "^3.3.0",
"ts-jest": "^23.10.4",
"tslint": "^5.10.0",
"typescript": "^3.4.5"
"ts-jest": "^27.1.2",
"typescript": "^4.3.5"
},
"dependencies": {
"@pagopa/openapi-codegen-ts": "^10.0.6",
"@pagopa/ts-commons": "^10.2.0",
"express": "^4.17.1",
"fast-memoize": "^2.5.1",
"io-ts": "1.8.5",
"italia-pagopa-commons": "^1.0.0",
"italia-ts-commons": "^8.6.0",
"io-ts": "^2.2.16",
"fp-ts": "^2.11.1",
"morgan": "^1.9.1",
"node-forge": "^0.9.1",
"redis": "^2.8.0",
Expand Down
45 changes: 22 additions & 23 deletions src/App.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/* eslint-disable prefer-arrow/prefer-arrow-functions */
/**
* App
* Define a Restful and a SOAP Webservice and routes incoming requests to controllers
*/

import * as http from "http";
import * as appInsights from "applicationinsights";
import * as bodyParser from "body-parser";
import * as express from "express";
import * as core from "express-serve-static-core";
import * as http from "http";
import { toExpressHandler } from "italia-ts-commons/lib/express";
import { toExpressHandler } from "@pagopa/ts-commons/lib/express";
import * as morgan from "morgan";
import * as redis from "redis";
import RedisClustr = require("redis-clustr");
import * as soap from "soap";

import { specs as publicApiV1Specs } from "../generated/api/public_api_pagopa";
// import { specs as publicApiV1Specs } from "../generated/api/public_api_pagopa";
import { Configuration } from "./Configuration";
import { GetOpenapi } from "./controllers/openapi";
import * as PaymentController from "./controllers/restful/PaymentController";
import { requireClientCertificateFingerprint } from "./middlewares/requireClientCertificateFingerprint";
import * as FespCdServer from "./services/pagopa_api/FespCdServer";
Expand All @@ -33,6 +33,7 @@ import { logger } from "./utils/Logger";
/**
* Define a Service Handler for FespCdService SOAP service
* It's an endpoint for PagoPA to confirm a payment activation result
*
* @param {redis.RedisClient} redisClient - Redis Client to store persistente paymentId into DB
* @param {number} redisTimeoutSecs - Timeout set for information stored into DB
* @return {IFespCdPortTypeSoap} An object containing the service handler
Expand All @@ -41,18 +42,15 @@ const getFespCdServiceHandler = (
redisClient: redis.RedisClient,
redisTimeoutSecs: number
): soap.IServicePort => ({
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
cdInfoWisp: (input, cb) => {
logger.info(
`idpayment=${input.idPagamento}|contesto=${
input.codiceContestoPagamento
}|dominio=${input.identificativoDominio}|versamento=${
input.identificativoUnivocoVersamento
}`
`idpayment=${input.idPagamento}|contesto=${input.codiceContestoPagamento}|dominio=${input.identificativoDominio}|versamento=${input.identificativoUnivocoVersamento}`
);
const aiEventProps = {
idpayment: input.idPagamento,
ccp: input.codiceContestoPagamento,
iddominio: input.identificativoDominio,
idpayment: input.idPagamento,
iuv: input.identificativoUnivocoVersamento
};
PaymentController.setActivationStatus(
Expand All @@ -68,7 +66,7 @@ const getFespCdServiceHandler = (
if (cb) {
// we need to cast the callback to any as the type definition doesn't
// include all the actual parameters
// tslint:disable-next-line: no-any no-useless-cast
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(cb as any)(undefined, iCdInfoWispOutput);
}
},
Expand All @@ -81,7 +79,7 @@ const getFespCdServiceHandler = (
if (cb) {
// we need to cast the callback to any as the type definition doesn't
// include all the actual parameters
// tslint:disable-next-line: no-any no-useless-cast
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(cb as any)(undefined, { esito: "KO" });
}
}
Expand All @@ -92,6 +90,7 @@ const getFespCdServiceHandler = (
/**
* Define and start an express Server
* to expose RESTful and SOAP endpoints for BackendApp and Proxy requests.
*
* @param {Configuration} config - The server configuration to use
* @return {Promise<http.Server>} The express server defined and started
*/
Expand All @@ -103,9 +102,7 @@ export async function startApp(config: Configuration): Promise<http.Server> {
const pagoPAClient = new PPTPortClient.PagamentiTelematiciPspNodoAsyncClient(
await PPTPortClient.createPagamentiTelematiciPspNodoClient(
{
endpoint: `${config.PAGOPA.HOST}:${config.PAGOPA.PORT}${
config.PAGOPA.WS_SERVICES.PAGAMENTI
}`,
endpoint: `${config.PAGOPA.HOST}:${config.PAGOPA.PORT}${config.PAGOPA.WS_SERVICES.PAGAMENTI}`,
wsdl_options: {
timeout: config.PAGOPA.CLIENT_TIMEOUT_MSEC
}
Expand All @@ -119,9 +116,7 @@ export async function startApp(config: Configuration): Promise<http.Server> {
const pagoPANm3PspClient = new NodoNM3PortClient.PagamentiTelematiciPspNm3NodoAsyncClient(
await NodoNM3PortClient.createNm3NodoPspClient(
{
endpoint: `${config.PAGOPA.HOST}:${config.PAGOPA.PORT}${
config.PAGOPA.WS_SERVICES.PAGAMENTI
}`,
endpoint: `${config.PAGOPA.HOST}:${config.PAGOPA.PORT}${config.PAGOPA.WS_SERVICES.PAGAMENTI}`,
wsdl_options: {
timeout: config.PAGOPA.CLIENT_TIMEOUT_MSEC
}
Expand All @@ -135,9 +130,7 @@ export async function startApp(config: Configuration): Promise<http.Server> {
const pagoPANm3IoClient = new NodoNM3PortClient.PagamentiTelematiciPspNm3NodoAsyncClient(
await NodoNM3PortClient.createNm3NodoIoClient(
{
endpoint: `${config.PAGOPA.HOST}:${config.PAGOPA.PORT}${
config.PAGOPA.WS_SERVICES.PAGAMENTI
}`,
endpoint: `${config.PAGOPA.HOST}:${config.PAGOPA.PORT}${config.PAGOPA.WS_SERVICES.PAGAMENTI}`,
wsdl_options: {
timeout: config.PAGOPA.CLIENT_TIMEOUT_MSEC
}
Expand All @@ -150,6 +143,7 @@ export async function startApp(config: Configuration): Promise<http.Server> {

// Define a redis client necessary to handle persistent data
// for async payment activation process
// eslint-disable-next-line @typescript-eslint/no-use-before-define
const redisClient = getRedisClient(config);

// Define RESTful endpoints
Expand All @@ -166,6 +160,7 @@ export async function startApp(config: Configuration): Promise<http.Server> {
app.use(requireClientCertificateFingerprint(clientCertificateFingerprint));
}

// eslint-disable-next-line @typescript-eslint/no-use-before-define
setRestfulRoutes(
app,
config,
Expand Down Expand Up @@ -202,11 +197,13 @@ export function stopServer(server: http.Server): void {

/**
* Set RESTful WS endpoints
*
* @param {core.Express} app - Express server to set
* @param {Configuration} config - PagoPa proxy configuration
* @param {redis.RedisClient} redisClient - The redis client used to store information sent by PagoPA
* @param {PagamentiTelematiciPspNodoAsyncClient} pagoPAClient - PagoPa SOAP client to call verificaRPT and attivaRPT services
*/
// eslint-disable-next-line max-params
function setRestfulRoutes(
app: core.Express,
config: Configuration,
Expand Down Expand Up @@ -256,7 +253,8 @@ function setRestfulRoutes(
);

// Endpoint for OpenAPI handler
app.get("/api/v1/swagger.json", GetOpenapi(publicApiV1Specs));
// eslint-disable-next-line extra-rules/no-commented-out-code
// app.get("/api/v1/swagger.json", GetOpenapi(publicApiV1Specs));

// Liveness probe for Kubernetes.
// @see
Expand All @@ -268,11 +266,12 @@ function setRestfulRoutes(

/**
* Define a redis client necessary to handle persistent data
*
* @param {Configuration} config - Server Configuration
* @return {(app: core.Express) => soap.Server} A method to execute for start server listening
*/
function getRedisClient(config: Configuration): redis.RedisClient {
const redisClient = (() => {
const redisClient = ((): redis.RedisClient => {
if (config.REDIS_DB.USE_CLUSTER) {
logger.debug("Creating a REDIS client using cluster...");
return new RedisClustr({
Expand Down
Loading