Skip to content

Commit

Permalink
IMN-739 import eservices (#940)
Browse files Browse the repository at this point in the history
Co-authored-by: Vittorio Caprio <[email protected]>
  • Loading branch information
sandrotaje and Viktor-K authored Sep 13, 2024
1 parent 317395a commit 46010f0
Show file tree
Hide file tree
Showing 13 changed files with 441 additions and 60 deletions.
10 changes: 4 additions & 6 deletions packages/bff/.env
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ PRIVACY_NOTICES_TOS_UUID="6bf8412a-41a7-41a0-82dc-26286ce61b1a"
PRIVACY_NOTICES_PP_UUID="0df21ff6-3e8f-4320-af8f-23dea9135d57"
PRIVACY_NOTICES_DYNAMO_TABLE_NAME="privacy-notice"
PRIVACY_NOTICES_USERS_DYNAMO_TABLE_NAME="privacy-notice-acceptances"
S3_BUCKET=interop-local-bucket
ESERVICE_DOCUMENTS_PATH="interop-eservice-documents"

CONSUMER_DOCUMENTS_PATH="interop-consumer-documents"
Expand All @@ -67,12 +66,11 @@ RATE_LIMITER_RATE_INTERVAL="1000"
RATE_LIMITER_REDIS_HOST="localhost"
RATE_LIMITER_REDIS_PORT="6379"
RATE_LIMITER_TIMEOUT="300"

EXPORT_ESERVICE_CONTAINER="interop-application-import-export-local"
EXPORT_ESERVICE_PATH="local/eservices-export"
PRESIGNED_URL_GET_DURATION_MINUTES=5000
IMPORT_ESERVICE_CONTAINER="interop-application-import-export-local"
IMPORT_ESERVICE_PATH="local/eservices-import"

IMPORT_ESERVICE_CONTAINER= "interop-application-import-export-local"
IMPORT_ESERVICE_PATH= "local/eservices-import"
PRESIGNED_URL_GET_DURATION_MINUTES=5000
PRESIGNED_URL_PUT_DURATION_MINUTES= 5000

RISK_ANALYSIS_DOCUMENTS_PATH="risk-analysis/docs"
1 change: 1 addition & 0 deletions packages/bff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"fast-xml-parser": "4.4.1",
"multer": "1.4.5-lts.1",
"adm-zip": "0.5.15",
"mime": "4.0.4",
"pagopa-interop-agreement-lifecycle": "workspace:*",
"pagopa-interop-api-clients": "workspace:*",
"pagopa-interop-commons": "workspace:*",
Expand Down
1 change: 1 addition & 0 deletions packages/bff/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export const AllowedListConfig = z
allowListPath: c.ALLOW_LIST_PATH,
allowListFileName: c.ALLOW_LIST_FILE_NAME,
}));

export const ExportFileConfig = z
.object({
EXPORT_ESERVICE_CONTAINER: z.string(),
Expand Down
58 changes: 57 additions & 1 deletion packages/bff/src/model/api/apiTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { agreementApi, catalogApi } from "pagopa-interop-api-clients";
import { agreementApi, bffApi, catalogApi } from "pagopa-interop-api-clients";
import { z } from "zod";

export const catalogApiDescriptorState =
Expand All @@ -13,3 +13,59 @@ export const EserviceConsumer = z.object({
consumerName: z.string(),
consumerExternalId: z.string(),
});

export const ConfigurationSingleAnswer = z.object({
key: z.string(),
value: z.string().nullable().optional(),
});
export type ConfigurationSingleAnswer = z.infer<
typeof ConfigurationSingleAnswer
>;

export const ConfigurationMultiAnswer = z.object({
key: z.string(),
values: z.array(z.string()),
});
export type ConfigurationMultiAnswer = z.infer<typeof ConfigurationMultiAnswer>;

const ConfigurationRiskAnalysisForm = z.object({
version: z.string(),
singleAnswers: z.array(ConfigurationSingleAnswer),
multiAnswers: z.array(ConfigurationMultiAnswer),
});

export const ConfigurationRiskAnalysis = z.object({
name: z.string(),
riskAnalysisForm: ConfigurationRiskAnalysisForm,
});

export type ConfigurationRiskAnalysis = z.infer<
typeof ConfigurationRiskAnalysis
>;

export const ConfigurationDoc = z.object({
prettyName: z.string(),
path: z.string(),
});
export type ConfigurationDoc = z.infer<typeof ConfigurationDoc>;

export const ConfigurationDescriptor = z.object({
interface: ConfigurationDoc.optional(),
docs: z.array(ConfigurationDoc),
audience: z.array(z.string()),
voucherLifespan: z.number(),
dailyCallsPerConsumer: z.number(),
dailyCallsTotal: z.number(),
description: z.string().optional(),
agreementApprovalPolicy: bffApi.AgreementApprovalPolicy,
});

export const ConfigurationEservice = z.object({
name: z.string(),
description: z.string(),
technology: bffApi.EServiceTechnology,
mode: bffApi.EServiceMode,
descriptor: ConfigurationDescriptor,
riskAnalysis: z.array(ConfigurationRiskAnalysis),
});
export type ConfigurationEservice = z.infer<typeof ConfigurationEservice>;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ import {
isAgreementUpgradable,
hasCertifiedAttributes,
} from "../../validators.js";
import { catalogApiDescriptorState } from "../apiTypes.js";
import {
ConfigurationRiskAnalysis,
catalogApiDescriptorState,
} from "../apiTypes.js";

export function toEserviceCatalogProcessQueryParams(
queryParams: bffApi.BffGetCatalogQueryParam
Expand Down Expand Up @@ -215,6 +218,46 @@ export function toBffCatalogApiEserviceRiskAnalysis(
};
}

export function toBffCatalogApiEserviceRiskAnalysisSeed(
riskAnalysis: ConfigurationRiskAnalysis
): bffApi.EServiceRiskAnalysisSeed {
const answers: bffApi.RiskAnalysisForm["answers"] =
riskAnalysis.riskAnalysisForm.singleAnswers
.concat(
riskAnalysis.riskAnalysisForm.multiAnswers.flatMap((multiAnswer) =>
multiAnswer.values.map((answerValue) => ({
value: answerValue,
key: multiAnswer.key,
}))
)
)
// eslint-disable-next-line sonarjs/no-identical-functions
.reduce((answers: bffApi.RiskAnalysisForm["answers"], answer) => {
const key = answer.key;
if (!answers[key]) {
answers[key] = [];
}

if (answer.value) {
answers[key] = [...answers[key], answer.value];
} else {
answers[key] = [];
}

return answers;
}, {});

const riskAnalysisForm: bffApi.RiskAnalysisForm = {
version: riskAnalysis.riskAnalysisForm.version,
answers,
};

return {
name: riskAnalysis.name,
riskAnalysisForm,
};
}

export function toBffCatalogApiProducerDescriptorEService(
eservice: catalogApi.EService,
producer: tenantApi.Tenant
Expand Down
9 changes: 9 additions & 0 deletions packages/bff/src/model/domain/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const errorCodes = {
privacyNoticeNotFoundInConfiguration: "0034",
privacyNoticeNotFound: "0035",
privacyNoticeVersionIsNotTheLatest: "0036",
invalidZipStructure: "0037",
};

export type ErrorCodes = keyof typeof errorCodes;
Expand Down Expand Up @@ -369,3 +370,11 @@ export function invalidContentType(
title: "Invalid content type",
});
}

export function invalidZipStructure(description: string): ApiError<ErrorCodes> {
return new ApiError({
detail: `Invalid zip structure: ${description}`,
code: "invalidZipStructure",
title: "Invalid zip structure",
});
}
19 changes: 18 additions & 1 deletion packages/bff/src/routers/catalogRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,24 @@ const catalogRouter = (
return res.status(errorRes.status).json(errorRes).end();
}
})
.post("/import/eservices", async (_req, res) => res.status(501).send());
.post("/import/eservices", async (req, res) => {
const ctx = fromBffAppContext(req.ctx, req.headers);
try {
const createdEServiceDescriptor = await catalogService.importEService(
req.body,
ctx
);
return res.status(200).json(createdEServiceDescriptor).send();
} catch (error) {
const errorRes = makeApiProblem(
error,
emptyErrorMapper,
ctx.logger,
"Error importing eService"
);
return res.status(errorRes.status).json(errorRes).end();
}
});

return catalogRouter;
};
Expand Down
Loading

0 comments on commit 46010f0

Please sign in to comment.