From 12af025bd8abe25b2a16727520ee702537b74c16 Mon Sep 17 00:00:00 2001 From: Roberto Gregnanin <128478646+rGregnanin@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:24:54 +0200 Subject: [PATCH 1/3] IMN-864 Fix field kind in enrichAgreement for parsing a Bff AgreementAttribute (#1047) --- .../src/api/agreementApiConverter.ts | 21 ++++++++++++++++++- .../src/services/agreementService.ts | 7 ++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/backend-for-frontend/src/api/agreementApiConverter.ts b/packages/backend-for-frontend/src/api/agreementApiConverter.ts index 8f9e85d236..55fb68d5fe 100644 --- a/packages/backend-for-frontend/src/api/agreementApiConverter.ts +++ b/packages/backend-for-frontend/src/api/agreementApiConverter.ts @@ -1,4 +1,9 @@ -import { agreementApi, bffApi, catalogApi } from "pagopa-interop-api-clients"; +import { + agreementApi, + attributeRegistryApi, + bffApi, + catalogApi, +} from "pagopa-interop-api-clients"; import { isAgreementUpgradable } from "../services/validators.js"; export function toBffCompactOrganization( @@ -41,3 +46,17 @@ export function toBffAgreementConsumerDocument( createdAt: doc.createdAt, }; } + +export function toBffAttribute( + attribute: attributeRegistryApi.Attribute +): + | bffApi.VerifiedAttribute + | bffApi.DeclaredAttribute + | bffApi.CertifiedAttribute { + return { + id: attribute.id, + description: attribute.description, + name: attribute.name, + creationTime: attribute.creationTime, + }; +} diff --git a/packages/backend-for-frontend/src/services/agreementService.ts b/packages/backend-for-frontend/src/services/agreementService.ts index ec4666de3c..cc5e325b11 100644 --- a/packages/backend-for-frontend/src/services/agreementService.ts +++ b/packages/backend-for-frontend/src/services/agreementService.ts @@ -36,6 +36,7 @@ import { } from "../api/catalogApiConverter.js"; import { toBffAgreementConsumerDocument, + toBffAttribute, toBffCompactOrganization, toCompactEserviceLight, } from "../api/agreementApiConverter.js"; @@ -691,9 +692,9 @@ export async function enrichAgreement( : undefined, }, state: agreement.state, - verifiedAttributes: agreementVerifiedAttrs, - certifiedAttributes: agreementCertifiedAttrs, - declaredAttributes: agreementDeclaredAttrs, + verifiedAttributes: agreementVerifiedAttrs.map((a) => toBffAttribute(a)), + certifiedAttributes: agreementCertifiedAttrs.map((a) => toBffAttribute(a)), + declaredAttributes: agreementDeclaredAttrs.map((a) => toBffAttribute(a)), suspendedByConsumer: agreement.suspendedByConsumer, suspendedByProducer: agreement.suspendedByProducer, suspendedByPlatform: agreement.suspendedByPlatform, From 6c5e94aade560583eddf9b12e45dbc6e7be74451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20Taj=C3=A8?= Date: Wed, 2 Oct 2024 12:06:09 +0200 Subject: [PATCH 2/3] Add bruno collections (#1044) --- collections/.gitignore | 1 + collections/bruno.json | 9 ++++ collections/catalog/Activate Descriptor.bru | 27 +++++++++++ .../catalog/Add Descriptors Document.bru | 47 ++++++++++++++++++ collections/catalog/Archive Descriptor.bru | 27 +++++++++++ collections/catalog/Clone Descriptor.bru | 27 +++++++++++ collections/catalog/Create Descriptor.bru | 48 +++++++++++++++++++ collections/catalog/Create Eservice.bru | 44 +++++++++++++++++ collections/catalog/Create Risk Analysis.bru | 39 +++++++++++++++ .../catalog/Delete Descriptor Document.bru | 28 +++++++++++ collections/catalog/Delete Descriptor.bru | 27 +++++++++++ collections/catalog/Delete Eservice.bru | 43 +++++++++++++++++ collections/catalog/Delete Risk Analysis.bru | 40 ++++++++++++++++ .../catalog/Edit Eservice Descriptor.bru | 43 +++++++++++++++++ collections/catalog/Edit Eservice.bru | 30 ++++++++++++ .../catalog/Get eservice consumers.bru | 25 ++++++++++ .../Get eservice descriptor document.bru | 27 +++++++++++ collections/catalog/Get eservice.bru | 29 +++++++++++ collections/catalog/Get eservices.bru | 32 +++++++++++++ collections/catalog/Publish Descriptor.bru | 27 +++++++++++ collections/catalog/Status.bru | 19 ++++++++ collections/catalog/Suspend Descriptor.bru | 27 +++++++++++ .../catalog/Update Descriptor Document.bru | 34 +++++++++++++ .../catalog/Update Eservice Descriptor.bru | 30 ++++++++++++ .../catalog/Update Eservice description.bru | 27 +++++++++++ collections/catalog/Update Risk Analysis.bru | 40 ++++++++++++++++ collections/collection.bru | 0 collections/environments/PagoPA local.bru | 9 ++++ 28 files changed, 806 insertions(+) create mode 100644 collections/.gitignore create mode 100644 collections/bruno.json create mode 100644 collections/catalog/Activate Descriptor.bru create mode 100644 collections/catalog/Add Descriptors Document.bru create mode 100644 collections/catalog/Archive Descriptor.bru create mode 100644 collections/catalog/Clone Descriptor.bru create mode 100644 collections/catalog/Create Descriptor.bru create mode 100644 collections/catalog/Create Eservice.bru create mode 100644 collections/catalog/Create Risk Analysis.bru create mode 100644 collections/catalog/Delete Descriptor Document.bru create mode 100644 collections/catalog/Delete Descriptor.bru create mode 100644 collections/catalog/Delete Eservice.bru create mode 100644 collections/catalog/Delete Risk Analysis.bru create mode 100644 collections/catalog/Edit Eservice Descriptor.bru create mode 100644 collections/catalog/Edit Eservice.bru create mode 100644 collections/catalog/Get eservice consumers.bru create mode 100644 collections/catalog/Get eservice descriptor document.bru create mode 100644 collections/catalog/Get eservice.bru create mode 100644 collections/catalog/Get eservices.bru create mode 100644 collections/catalog/Publish Descriptor.bru create mode 100644 collections/catalog/Status.bru create mode 100644 collections/catalog/Suspend Descriptor.bru create mode 100644 collections/catalog/Update Descriptor Document.bru create mode 100644 collections/catalog/Update Eservice Descriptor.bru create mode 100644 collections/catalog/Update Eservice description.bru create mode 100644 collections/catalog/Update Risk Analysis.bru create mode 100644 collections/collection.bru create mode 100644 collections/environments/PagoPA local.bru diff --git a/collections/.gitignore b/collections/.gitignore new file mode 100644 index 0000000000..4c49bd78f1 --- /dev/null +++ b/collections/.gitignore @@ -0,0 +1 @@ +.env diff --git a/collections/bruno.json b/collections/bruno.json new file mode 100644 index 0000000000..f57905086d --- /dev/null +++ b/collections/bruno.json @@ -0,0 +1,9 @@ +{ + "version": "1", + "name": "PagoPA Interop", + "type": "collection", + "ignore": [ + "node_modules", + ".git" + ] +} \ No newline at end of file diff --git a/collections/catalog/Activate Descriptor.bru b/collections/catalog/Activate Descriptor.bru new file mode 100644 index 0000000000..7943e74d7d --- /dev/null +++ b/collections/catalog/Activate Descriptor.bru @@ -0,0 +1,27 @@ +meta { + name: Activate Descriptor + type: http + seq: 14 +} + +post { + url: {{host-catalog}}/eservices/:eserviceId/descriptors/:descriptorId/activate + body: none + auth: none +} + +params:path { + eserviceId: {{eServiceId}} + descriptorId: {{descriptorId}} +} + +headers { + Cache-Control: no-cache + Content-Length: 0 + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} diff --git a/collections/catalog/Add Descriptors Document.bru b/collections/catalog/Add Descriptors Document.bru new file mode 100644 index 0000000000..7d960e0aa0 --- /dev/null +++ b/collections/catalog/Add Descriptors Document.bru @@ -0,0 +1,47 @@ +meta { + name: Add Descriptors Document + type: http + seq: 18 +} + +post { + url: {{host-catalog}}/eservices/:eserviceId/descriptors/:descriptorId/documents + body: json + auth: none +} + +params:path { + eserviceId: {{eServiceId}} + descriptorId: {{descriptorId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} + +body:json { + { + "documentId": "5d6d2677-f6b3-4c2a-ae25-d9685cb464b0", + "kind": "INTERFACE", + "prettyName": "Test File Name", + "filePath": "eservices/docs/5d6d2677-f6b3-4c2a-ae25-d9685cb464b0/testfile", + "fileName": "testfile", + "contentType": "test", + "checksum": "checksum", + "serverUrls": [ + "server urls 1", + "server urls 2" + ] + } +} + +vars:post-response { + interfaceId: res.body.descriptors[0].interface.id +} diff --git a/collections/catalog/Archive Descriptor.bru b/collections/catalog/Archive Descriptor.bru new file mode 100644 index 0000000000..badd550058 --- /dev/null +++ b/collections/catalog/Archive Descriptor.bru @@ -0,0 +1,27 @@ +meta { + name: Archive Descriptor + type: http + seq: 10 +} + +post { + url: {{host-catalog}}/eservices/:eServiceId/descriptors/:descriptorId/archive + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} + descriptorId: {{descriptorId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} diff --git a/collections/catalog/Clone Descriptor.bru b/collections/catalog/Clone Descriptor.bru new file mode 100644 index 0000000000..59d8e7b0ae --- /dev/null +++ b/collections/catalog/Clone Descriptor.bru @@ -0,0 +1,27 @@ +meta { + name: Clone Descriptor + type: http + seq: 9 +} + +post { + url: {{host-catalog}}/eservices/:eserviceId/descriptors/:descriptorId/clone + body: json + auth: none +} + +params:path { + eserviceId: {{eServiceId}} + descriptorId: {{descriptorId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} diff --git a/collections/catalog/Create Descriptor.bru b/collections/catalog/Create Descriptor.bru new file mode 100644 index 0000000000..9ee429edc0 --- /dev/null +++ b/collections/catalog/Create Descriptor.bru @@ -0,0 +1,48 @@ +meta { + name: Create Descriptor + type: http + seq: 8 +} + +post { + url: {{host-catalog}}/eservices/:eserviceId/descriptors + body: json + auth: none +} + +params:path { + eserviceId: {{eServiceId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} + +body:json { + { + "description": "testone testone", + "audience": [ + "string" + ], + "voucherLifespan": 86400, + "dailyCallsPerConsumer": 100, + "dailyCallsTotal": 100, + "agreementApprovalPolicy": "AUTOMATIC", + "attributes": { + "certified": [ + ], + "declared": [ + ], + "verified": [ + ] + }, + "docs": [] + } +} diff --git a/collections/catalog/Create Eservice.bru b/collections/catalog/Create Eservice.bru new file mode 100644 index 0000000000..ca88197d84 --- /dev/null +++ b/collections/catalog/Create Eservice.bru @@ -0,0 +1,44 @@ +meta { + name: Create Eservice + type: http + seq: 1 +} + +post { + url: {{host-catalog}}/eservices + body: json + auth: none +} + +headers { + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Accept: application/json +} + +body:json { + { + "name": "{{randomName}}", + "description": "this is a test again", + "technology": "REST", + "mode": "DELIVER", + "descriptor": { + "audience": [ "string" ], + "voucherLifespan": 86400, + "dailyCallsPerConsumer": 100, + "dailyCallsTotal": 100, + "agreementApprovalPolicy": "MANUAL" + } + } +} + +vars:post-response { + eServiceId: res.body.id + descriptorId: res.body.descriptors[0].id +} + +script:pre-request { + const random = Math.round(Math.random() * 100) + + bru.setVar("randomName",`test name ${random}`) +} diff --git a/collections/catalog/Create Risk Analysis.bru b/collections/catalog/Create Risk Analysis.bru new file mode 100644 index 0000000000..22a1a5eedc --- /dev/null +++ b/collections/catalog/Create Risk Analysis.bru @@ -0,0 +1,39 @@ +meta { + name: Create Risk Analysis + type: http + seq: 5 +} + +post { + url: {{host-catalog}}/eservices/:eServiceId/riskAnalysis + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} + +body:json { + { + "name": "Test risk analysis", + "riskAnalysisForm": { + "version": "3.0", + "answers": { + "purpose": ["INSTITUTIONAL"], + "institutionalPurpose":["MyPurpose"] + } + } + } +} diff --git a/collections/catalog/Delete Descriptor Document.bru b/collections/catalog/Delete Descriptor Document.bru new file mode 100644 index 0000000000..d6925218e3 --- /dev/null +++ b/collections/catalog/Delete Descriptor Document.bru @@ -0,0 +1,28 @@ +meta { + name: Delete Descriptor Document + type: http + seq: 19 +} + +delete { + url: {{host-catalog}}/eservices/:eServiceId/descriptors/:descriptorId/documents/:documentId + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} + descriptorId: {{descriptorId}} + documentId: {{interfaceId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} diff --git a/collections/catalog/Delete Descriptor.bru b/collections/catalog/Delete Descriptor.bru new file mode 100644 index 0000000000..01172cc773 --- /dev/null +++ b/collections/catalog/Delete Descriptor.bru @@ -0,0 +1,27 @@ +meta { + name: Delete Descriptor + type: http + seq: 11 +} + +delete { + url: {{host-catalog}}/eservices/:eserviceId/descriptors/:descriptorId + body: json + auth: none +} + +params:path { + eserviceId: {{eServiceId}} + descriptorId: {{descriptorId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} diff --git a/collections/catalog/Delete Eservice.bru b/collections/catalog/Delete Eservice.bru new file mode 100644 index 0000000000..30d9ef43fa --- /dev/null +++ b/collections/catalog/Delete Eservice.bru @@ -0,0 +1,43 @@ +meta { + name: Delete Eservice + type: http + seq: 22 +} + +delete { + url: {{host-catalog}}/eservices/:eServiceId + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} +} + +headers { + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Accept: application/json +} + +body:json { + { + "name": "{{name}}", + "description": "this is a test again", + "technology": "REST", + "mode": "DELIVER", + "descriptor": { + "audience": [ "string" ], + "voucherLifespan": 86400, + "dailyCallsPerConsumer": 100, + "dailyCallsTotal": 100, + "agreementApprovalPolicy": "MANUAL" + } + } +} + +script:pre-request { + const random = Math.round(Math.random() * 100) + + bru.setVar("name",`test name ${random}`) +} diff --git a/collections/catalog/Delete Risk Analysis.bru b/collections/catalog/Delete Risk Analysis.bru new file mode 100644 index 0000000000..8305fa90d4 --- /dev/null +++ b/collections/catalog/Delete Risk Analysis.bru @@ -0,0 +1,40 @@ +meta { + name: Delete Risk Analysis + type: http + seq: 7 +} + +delete { + url: {{host-catalog}}/eservices/:eServiceId/riskAnalysis/:riskAnalysisId + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} + riskAnalysisId: {{riskAnalysisId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} + +body:json { + { + "name": "UPDATED RISK ANALYSIS", + "riskAnalysisForm": { + "version": "3.0", + "answers": { + "purpose": ["OTHER"], + "otherPurpose":["another purpose!"] + } + } + } +} diff --git a/collections/catalog/Edit Eservice Descriptor.bru b/collections/catalog/Edit Eservice Descriptor.bru new file mode 100644 index 0000000000..0da7cec1e2 --- /dev/null +++ b/collections/catalog/Edit Eservice Descriptor.bru @@ -0,0 +1,43 @@ +meta { + name: Edit Eservice Descriptor + type: http + seq: 16 +} + +put { + url: {{host-catalog}}/eservices/:eServiceId/descriptors/:descriptorId + body: json + auth: none +} + +params:path { + descriptorId: {{descriptorId}} + eServiceId: {{eServiceId}} +} + +headers { + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Accept: application/json +} + +body:json { + { + "description": "testone testone", + "audience": [ + "string" + ], + "voucherLifespan": 86400, + "dailyCallsPerConsumer": 100, + "dailyCallsTotal": 100, + "agreementApprovalPolicy": "AUTOMATIC", + "attributes": { + "certified": [ + ], + "declared": [ + ], + "verified": [ + ] + } + } +} diff --git a/collections/catalog/Edit Eservice.bru b/collections/catalog/Edit Eservice.bru new file mode 100644 index 0000000000..8178de89b2 --- /dev/null +++ b/collections/catalog/Edit Eservice.bru @@ -0,0 +1,30 @@ +meta { + name: Edit Eservice + type: http + seq: 21 +} + +put { + url: {{host-catalog}}/eservices/:eServiceId + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} +} + +headers { + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Accept: application/json +} + +body:json { + { + "name": "Weber - Ledner", + "description": "this is a test again", + "technology": "REST", + "mode": "DELIVER" + } +} diff --git a/collections/catalog/Get eservice consumers.bru b/collections/catalog/Get eservice consumers.bru new file mode 100644 index 0000000000..e162457b73 --- /dev/null +++ b/collections/catalog/Get eservice consumers.bru @@ -0,0 +1,25 @@ +meta { + name: Get eservice consumers + type: http + seq: 23 +} + +get { + url: {{host-catalog}}/eservices/:eserviceId/consumers + body: json + auth: none +} + +params:path { + eserviceId: {{eServiceId}} +} + +headers { + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json + ~Connection: keep-alive +} diff --git a/collections/catalog/Get eservice descriptor document.bru b/collections/catalog/Get eservice descriptor document.bru new file mode 100644 index 0000000000..320c24499e --- /dev/null +++ b/collections/catalog/Get eservice descriptor document.bru @@ -0,0 +1,27 @@ +meta { + name: Get eservice descriptor document + type: http + seq: 24 +} + +get { + url: {{host-catalog}}/eservices/:eserviceId/descriptors/:descriptorId/documents/:documentId + body: json + auth: none +} + +params:path { + documentId: {{interfaceId}} + descriptorId: {{descriptorId}} + eserviceId: {{eServiceId}} +} + +headers { + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json + ~Connection: keep-alive +} diff --git a/collections/catalog/Get eservice.bru b/collections/catalog/Get eservice.bru new file mode 100644 index 0000000000..39afdc152a --- /dev/null +++ b/collections/catalog/Get eservice.bru @@ -0,0 +1,29 @@ +meta { + name: Get eservice + type: http + seq: 2 +} + +get { + url: {{host-catalog}}/eservices/:eserviceId + body: json + auth: none +} + +params:path { + eserviceId: {{eServiceId}} +} + +headers { + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json + ~Connection: keep-alive +} + +vars:post-response { + riskAnalysisId: res.body.riskAnalysis[0].id +} diff --git a/collections/catalog/Get eservices.bru b/collections/catalog/Get eservices.bru new file mode 100644 index 0000000000..08fd979e11 --- /dev/null +++ b/collections/catalog/Get eservices.bru @@ -0,0 +1,32 @@ +meta { + name: Get eservices + type: http + seq: 4 +} + +get { + url: {{host-catalog}}/eservices?offset=0&limit=50 + body: json + auth: none +} + +params:query { + offset: 0 + limit: 50 + ~attributesIds: ["3fa85f64-5717-4562-b3fc-2c963f66afa6"] + ~producersIds: ["4D55696F-16C0-4968-854B-2B166397FC30"] + ~name: lol + ~agreementStates: ["SUSPENDED"] + ~eservicesIds: ["adb7d6fa-9b8e-4eed-87b0-2b2bf3d95f7a"] + ~states: "PUBLISHED, HELLO" +} + +headers { + Cache-Control: no-cache + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} diff --git a/collections/catalog/Publish Descriptor.bru b/collections/catalog/Publish Descriptor.bru new file mode 100644 index 0000000000..84674b4abc --- /dev/null +++ b/collections/catalog/Publish Descriptor.bru @@ -0,0 +1,27 @@ +meta { + name: Publish Descriptor + type: http + seq: 12 +} + +post { + url: {{host-catalog}}/eservices/:eserviceId/descriptors/:descriptorId/publish + body: none + auth: none +} + +params:path { + eserviceId: {{eServiceId}} + descriptorId: {{descriptorId}} +} + +headers { + Cache-Control: no-cache + Content-Length: 0 + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} diff --git a/collections/catalog/Status.bru b/collections/catalog/Status.bru new file mode 100644 index 0000000000..56c64be572 --- /dev/null +++ b/collections/catalog/Status.bru @@ -0,0 +1,19 @@ +meta { + name: Status + type: http + seq: 3 +} + +get { + url: {{host-catalog}}/status + body: none + auth: none +} + +headers { + Cache-Control: no-cache + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + X-Correlation-Id: {{correlation-id}} +} diff --git a/collections/catalog/Suspend Descriptor.bru b/collections/catalog/Suspend Descriptor.bru new file mode 100644 index 0000000000..2bbdbf7564 --- /dev/null +++ b/collections/catalog/Suspend Descriptor.bru @@ -0,0 +1,27 @@ +meta { + name: Suspend Descriptor + type: http + seq: 13 +} + +post { + url: {{host-catalog}}/eservices/:eserviceId/descriptors/:descriptorId/suspend + body: none + auth: none +} + +params:path { + eserviceId: {{eServiceId}} + descriptorId: {{descriptorId}} +} + +headers { + Cache-Control: no-cache + Content-Length: 0 + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} diff --git a/collections/catalog/Update Descriptor Document.bru b/collections/catalog/Update Descriptor Document.bru new file mode 100644 index 0000000000..07061daf9f --- /dev/null +++ b/collections/catalog/Update Descriptor Document.bru @@ -0,0 +1,34 @@ +meta { + name: Update Descriptor Document + type: http + seq: 20 +} + +post { + url: {{host-catalog}}/eservices/:eServiceId/descriptors/:descriptorId/documents/:documentId/update + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} + descriptorId: {{descriptorId}} + documentId: {{interfaceId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} + +body:json { + { + "prettyName": "UPDATED TEST FILE NAME" + } +} diff --git a/collections/catalog/Update Eservice Descriptor.bru b/collections/catalog/Update Eservice Descriptor.bru new file mode 100644 index 0000000000..8cb64c2787 --- /dev/null +++ b/collections/catalog/Update Eservice Descriptor.bru @@ -0,0 +1,30 @@ +meta { + name: Update Eservice Descriptor + type: http + seq: 17 +} + +post { + url: {{host-catalog}}/eservices/:eServiceId/descriptors/:descriptorId/update + body: json + auth: none +} + +params:path { + descriptorId: {{descriptorId}} + eServiceId: {{eServiceId}} +} + +headers { + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Accept: application/json +} + +body:json { + { + "voucherLifespan": 86400, + "dailyCallsPerConsumer": 100, + "dailyCallsTotal": 100 + } +} diff --git a/collections/catalog/Update Eservice description.bru b/collections/catalog/Update Eservice description.bru new file mode 100644 index 0000000000..59dcd6e26a --- /dev/null +++ b/collections/catalog/Update Eservice description.bru @@ -0,0 +1,27 @@ +meta { + name: Update Eservice description + type: http + seq: 15 +} + +post { + url: {{host-catalog}}/eservices/:eServiceId/update + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} +} + +headers { + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Accept: application/json +} + +body:json { + { + "description": "this is a test again" + } +} diff --git a/collections/catalog/Update Risk Analysis.bru b/collections/catalog/Update Risk Analysis.bru new file mode 100644 index 0000000000..0146d9ee0a --- /dev/null +++ b/collections/catalog/Update Risk Analysis.bru @@ -0,0 +1,40 @@ +meta { + name: Update Risk Analysis + type: http + seq: 6 +} + +post { + url: {{host-catalog}}/eservices/:eServiceId/riskAnalysis/:riskAnalysisId + body: json + auth: none +} + +params:path { + eServiceId: {{eServiceId}} + riskAnalysisId: {{riskAnalysisId}} +} + +headers { + Cache-Control: no-cache + Content-Type: application/json + Accept: */* + Accept-Encoding: gzip, deflate, br + Connection: keep-alive + Authorization: {{JWT}} + X-Correlation-Id: {{correlation-id}} + Content-Type: application/json +} + +body:json { + { + "name": "UPDATED RISK ANALYSIS", + "riskAnalysisForm": { + "version": "3.0", + "answers": { + "purpose": ["OTHER"], + "otherPurpose":["another purpose!"] + } + } + } +} diff --git a/collections/collection.bru b/collections/collection.bru new file mode 100644 index 0000000000..e69de29bb2 diff --git a/collections/environments/PagoPA local.bru b/collections/environments/PagoPA local.bru new file mode 100644 index 0000000000..f8328a7886 --- /dev/null +++ b/collections/environments/PagoPA local.bru @@ -0,0 +1,9 @@ +vars { + host-agreement: http://localhost:3100 + JWT: {{process.env.JWT}} + host-catalog: http://localhost:3000 + correlation-id: 9999 + JWT-Invalid: + host-bff: http://localhost:3600 + host-tenant: http://localhost:3100 +} From f86da4ead87e4bd94841dcb816faa8fe939c00af Mon Sep 17 00:00:00 2001 From: Eric Camellini Date: Wed, 2 Oct 2024 14:41:36 +0200 Subject: [PATCH 3/3] IMN-828 - Parsing API GW responses (#1027) --- .../api-clients/open-api/apiGatewayApi.yml | 4 +- .../api-gateway/src/api/eventsApiConverter.ts | 16 ++++++ .../src/routers/apiGatewayRouter.ts | 56 +++++++++++-------- .../src/services/notifierEventsService.ts | 21 +++++-- .../src/services/readModelService.ts | 5 +- packages/models/src/errors.ts | 8 +++ 6 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 packages/api-gateway/src/api/eventsApiConverter.ts diff --git a/packages/api-clients/open-api/apiGatewayApi.yml b/packages/api-clients/open-api/apiGatewayApi.yml index 28a8caff78..5ae49ade0c 100644 --- a/packages/api-clients/open-api/apiGatewayApi.yml +++ b/packages/api-clients/open-api/apiGatewayApi.yml @@ -2665,7 +2665,7 @@ components: code: type: string description: source identifier - pattern: '[a-z0-9 \-]{,48}' + pattern: '^[a-zA-Z0-9\-_]+$' maxLength: 48 origin: $ref: "#/components/schemas/Origin" @@ -2928,7 +2928,7 @@ components: type: string pattern: '^[a-zA-Z0-9\s\-_]+$' minLength: 2 - maxLength: 16 + maxLength: 24 kind: $ref: "#/components/schemas/AttributeKind" required: diff --git a/packages/api-gateway/src/api/eventsApiConverter.ts b/packages/api-gateway/src/api/eventsApiConverter.ts new file mode 100644 index 0000000000..aa9a7ba7e3 --- /dev/null +++ b/packages/api-gateway/src/api/eventsApiConverter.ts @@ -0,0 +1,16 @@ +import { apiGatewayApi, notifierApi } from "pagopa-interop-api-clients"; + +export function notifierEventsToApiGatewayEvents( + events: notifierApi.Events +): apiGatewayApi.Events { + return { + events: events.events.map( + ({ eventId, eventType, objectType, objectId }) => ({ + eventId, + eventType, + objectType, + objectId, + }) + ), + }; +} diff --git a/packages/api-gateway/src/routers/apiGatewayRouter.ts b/packages/api-gateway/src/routers/apiGatewayRouter.ts index 9640547270..39d075b992 100644 --- a/packages/api-gateway/src/routers/apiGatewayRouter.ts +++ b/packages/api-gateway/src/routers/apiGatewayRouter.ts @@ -103,7 +103,9 @@ const apiGatewayRouter = ( req.query ); - return res.status(200).send(agreements); + return res + .status(200) + .send(apiGatewayApi.Agreements.parse(agreements)); } catch (error) { const errorRes = makeApiProblem( error, @@ -126,7 +128,7 @@ const apiGatewayRouter = ( req.params.agreementId ); - return res.status(200).send(agreement); + return res.status(200).send(apiGatewayApi.Agreement.parse(agreement)); } catch (error) { const errorRes = makeApiProblem( error, @@ -149,7 +151,9 @@ const apiGatewayRouter = ( req.params.agreementId ); - return res.status(200).send(attributes); + return res + .status(200) + .send(apiGatewayApi.Attributes.parse(attributes)); } catch (error) { const errorRes = makeApiProblem( error, @@ -172,7 +176,7 @@ const apiGatewayRouter = ( req.params.agreementId ); - return res.status(200).send(purposes); + return res.status(200).send(apiGatewayApi.Purposes.parse(purposes)); } catch (error) { const errorRes = makeApiProblem( error, @@ -195,7 +199,7 @@ const apiGatewayRouter = ( req.body ); - return res.status(200).send(attribute); + return res.status(200).send(apiGatewayApi.Attribute.parse(attribute)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -214,7 +218,7 @@ const apiGatewayRouter = ( req.params.attributeId ); - return res.status(200).send(attribute); + return res.status(200).send(apiGatewayApi.Attribute.parse(attribute)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -232,7 +236,7 @@ const apiGatewayRouter = ( ctx, req.params.clientId ); - return res.status(200).send(client); + return res.status(200).send(apiGatewayApi.Client.parse(client)); } catch (error) { const errorRes = makeApiProblem( error, @@ -250,7 +254,9 @@ const apiGatewayRouter = ( const ctx = fromApiGatewayAppContext(req.ctx, req.headers); try { const eservices = await catalogService.getEservices(ctx, req.query); - return res.status(200).send(eservices); + return res + .status(200) + .send(apiGatewayApi.CatalogEServices.parse(eservices)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -267,7 +273,7 @@ const apiGatewayRouter = ( ctx, req.params.eserviceId ); - return res.status(200).send(eservice); + return res.status(200).send(apiGatewayApi.EService.parse(eservice)); } catch (error) { const errorRes = makeApiProblem( error, @@ -288,7 +294,9 @@ const apiGatewayRouter = ( ctx, req.params.eserviceId ); - return res.status(200).send(descriptors); + return res + .status(200) + .send(apiGatewayApi.EServiceDescriptors.parse(descriptors)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -306,7 +314,9 @@ const apiGatewayRouter = ( req.params.eserviceId, req.params.descriptorId ); - return res.status(200).send(descriptor); + return res + .status(200) + .send(apiGatewayApi.EServiceDescriptor.parse(descriptor)); } catch (error) { const errorRes = makeApiProblem( error, @@ -327,7 +337,7 @@ const apiGatewayRouter = ( req.query.limit ); - return res.status(200).send(events); + return res.status(200).send(apiGatewayApi.Events.parse(events)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -346,7 +356,7 @@ const apiGatewayRouter = ( req.query.limit ); - return res.status(200).send(events); + return res.status(200).send(apiGatewayApi.Events.parse(events)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -366,7 +376,7 @@ const apiGatewayRouter = ( req.query.limit ); - return res.status(200).send(events); + return res.status(200).send(apiGatewayApi.Events.parse(events)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -386,7 +396,7 @@ const apiGatewayRouter = ( req.query.limit ); - return res.status(200).send(events); + return res.status(200).send(apiGatewayApi.Events.parse(events)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -407,7 +417,7 @@ const apiGatewayRouter = ( req.query.limit ); - return res.status(200).send(events); + return res.status(200).send(apiGatewayApi.Events.parse(events)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -423,7 +433,7 @@ const apiGatewayRouter = ( try { const jwk = await authorizationService.getJWK(ctx, req.params.kid); - return res.status(200).send(jwk); + return res.status(200).send(apiGatewayApi.JWK.parse(jwk)); } catch (error) { const errorRes = makeApiProblem(error, getJWKErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -436,7 +446,7 @@ const apiGatewayRouter = ( try { const purposes = await purposeService.getPurposes(ctx, req.query); - return res.status(200).send(purposes); + return res.status(200).send(apiGatewayApi.Purposes.parse(purposes)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -453,7 +463,7 @@ const apiGatewayRouter = ( req.params.purposeId ); - return res.status(200).send(purpose); + return res.status(200).send(apiGatewayApi.Purpose.parse(purpose)); } catch (error) { const errorRes = makeApiProblem( error, @@ -474,7 +484,7 @@ const apiGatewayRouter = ( ctx, req.params.purposeId ); - return res.status(200).send(agreement); + return res.status(200).send(apiGatewayApi.Agreement.parse(agreement)); } catch (error) { const errorRes = makeApiProblem( error, @@ -497,7 +507,9 @@ const apiGatewayRouter = ( req.params.organizationId ); - return res.status(200).send(organization); + return res + .status(200) + .send(apiGatewayApi.Organization.parse(organization)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); @@ -557,7 +569,7 @@ const apiGatewayRouter = ( attributeCode: req.query.attributeCode, }); - return res.status(200).send(eservices); + return res.status(200).send(apiGatewayApi.EServices.parse(eservices)); } catch (error) { const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger); return res.status(errorRes.status).send(errorRes); diff --git a/packages/api-gateway/src/services/notifierEventsService.ts b/packages/api-gateway/src/services/notifierEventsService.ts index 47ec9438e0..9c3fd08aea 100644 --- a/packages/api-gateway/src/services/notifierEventsService.ts +++ b/packages/api-gateway/src/services/notifierEventsService.ts @@ -2,6 +2,7 @@ import { apiGatewayApi } from "pagopa-interop-api-clients"; import { WithLogger } from "pagopa-interop-commons"; import { NotifierEventsClient } from "../clients/clientsProvider.js"; import { ApiGatewayAppContext } from "../utilities/context.js"; +import { notifierEventsToApiGatewayEvents } from "../api/eventsApiConverter.js"; // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function notifierEventsServiceBuilder( @@ -17,13 +18,15 @@ export function notifierEventsServiceBuilder( `Retrieving Notifier Events - lastEventId: ${lastEventId} - limit ${limit}` ); - return await notifierEventsClient.getEventsFromId({ + const events = await notifierEventsClient.getEventsFromId({ headers, queries: { lastEventId, limit, }, }); + + return notifierEventsToApiGatewayEvents(events); }, getEservicesEventsFromId: async ( { logger, headers }: WithLogger, @@ -34,13 +37,15 @@ export function notifierEventsServiceBuilder( `Retrieving EServices Notifier Events - lastEventId: ${lastEventId} - limit ${limit}` ); - return await notifierEventsClient.getAllEservicesFromId({ + const events = await notifierEventsClient.getAllEservicesFromId({ headers, queries: { lastEventId, limit, }, }); + + return notifierEventsToApiGatewayEvents(events); }, getAgreementsEventsFromId: async ( { logger, headers }: WithLogger, @@ -51,13 +56,15 @@ export function notifierEventsServiceBuilder( `Retrieving Agreements Notifier Events - lastEventId: ${lastEventId} - limit ${limit}` ); - return await notifierEventsClient.getAllAgreementsEventsFromId({ + const events = await notifierEventsClient.getAllAgreementsEventsFromId({ headers, queries: { lastEventId, limit, }, }); + + return notifierEventsToApiGatewayEvents(events); }, getKeysEventsFromId: async ( { logger, headers }: WithLogger, @@ -68,13 +75,15 @@ export function notifierEventsServiceBuilder( `Retrieving Keys Notifier Events - lastEventId: ${lastEventId} - limit ${limit}` ); - return await notifierEventsClient.getKeysEvents({ + const events = await notifierEventsClient.getKeysEvents({ headers, queries: { lastEventId, limit, }, }); + + return notifierEventsToApiGatewayEvents(events); }, getProducerKeysEventsFromId: async ( { logger, headers }: WithLogger, @@ -85,13 +94,15 @@ export function notifierEventsServiceBuilder( `Retrieving Producer Keys Notifier Events - lastEventId: ${lastEventId} - limit ${limit}` ); - return await notifierEventsClient.getProducerKeysEvents({ + const events = await notifierEventsClient.getProducerKeysEvents({ headers, queries: { lastEventId, limit, }, }); + + return notifierEventsToApiGatewayEvents(events); }, }; } diff --git a/packages/api-gateway/src/services/readModelService.ts b/packages/api-gateway/src/services/readModelService.ts index 6b4a61531c..de02bcdcae 100644 --- a/packages/api-gateway/src/services/readModelService.ts +++ b/packages/api-gateway/src/services/readModelService.ts @@ -1,3 +1,4 @@ +import { apiGatewayApi } from "pagopa-interop-api-clients"; import { ReadModelRepository } from "pagopa-interop-commons"; import { genericInternalError, ClientJWKKey } from "pagopa-interop-models"; @@ -9,14 +10,14 @@ export function readModelServiceBuilder( return { getJWKById: async ( kId: ClientJWKKey["kid"] - ): Promise => { + ): Promise => { const data = await keys.findOne( { "data.kid": kId }, { projection: { data: true } } ); if (data) { - const result = ClientJWKKey.safeParse(data.data); + const result = apiGatewayApi.JWK.safeParse(data.data); if (!result.success) { throw genericInternalError( diff --git a/packages/models/src/errors.ts b/packages/models/src/errors.ts index 069281e784..654069c379 100644 --- a/packages/models/src/errors.ts +++ b/packages/models/src/errors.ts @@ -155,6 +155,14 @@ export function makeApiProblemBuilder( } } ) + .with(P.instanceOf(ZodError), (error) => { + // Zod errors shall always be catched and handled throwing + // an ApiError. If a ZodError arrives here we log it and + // return a generic problem + const zodError = fromZodError(error); + logger.error(makeProblemLogString(genericProblem, zodError)); + return genericProblem; + }) .otherwise((error: unknown): Problem => { logger.error(makeProblemLogString(genericProblem, error)); return genericProblem;