Skip to content

Commit

Permalink
IMN-670 get eservice descriptor document (#918)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandrotaje authored Sep 11, 2024
1 parent 6e301c1 commit f7f3eea
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/api-clients/template-bff.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export const {{@key}}Endpoints = makeApi([
response: z.instanceof(Buffer),
{{else if (and (eq method "get") (eq path "/eservices/:eServiceId/consumers"))}}
response: z.instanceof(Buffer),
{{else if (and (eq method "get") (eq path "/eservices/:eServiceId/descriptors/:descriptorId/documents/:documentId"))}}
response: z.instanceof(Buffer),
{{else}}
response: {{{response}}},
{{/if}}
Expand Down
1 change: 1 addition & 0 deletions packages/bff/.env
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ GENERATED_JWT_SECONDS_DURATION=60
S3_CUSTOM_SERVER=true
S3_SERVER_HOST=http://localhost
S3_SERVER_PORT=9000
S3_BUCKET=interop-local-bucket

RISK_ANALYSIS_DOCUMENTS_PATH="risk-analysis/docs"

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 @@ -111,6 +111,7 @@ const BffProcessConfig = CommonHTTPServiceConfig.and(TenantProcessServerConfig)
.and(TokenGenerationConfig)
.and(SessionTokenGenerationConfig)
.and(FileManagerConfig)
.and(S3RiskAnalysisConfig)
.and(AllowedListConfig)
.and(SelfCareConfig)
.and(S3RiskAnalysisConfig)
Expand Down
21 changes: 20 additions & 1 deletion packages/bff/src/routers/catalogRouter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { constants } from "http2";
import { ZodiosEndpointDefinitions } from "@zodios/core";
import { ZodiosRouter } from "@zodios/express";
import { bffApi } from "pagopa-interop-api-clients";
Expand Down Expand Up @@ -331,7 +332,25 @@ const catalogRouter = (
)
.get(
"/eservices/:eServiceId/descriptors/:descriptorId/documents/:documentId",
async (_req, res) => res.status(501).send()
async (req, res) => {
const ctx = fromBffAppContext(req.ctx, req.headers);
try {
const { contentType, document } =
await catalogService.getEServiceDocumentById(
unsafeBrandId(req.params.eServiceId),
unsafeBrandId(req.params.descriptorId),
unsafeBrandId(req.params.documentId),
ctx
);
return res
.header(constants.HTTP2_HEADER_CONTENT_TYPE, contentType)
.status(200)
.end(document);
} catch (error) {
const errorRes = makeApiProblem(error, emptyErrorMapper, ctx.logger);
return res.status(errorRes.status).json(errorRes).end();
}
}
)
.post(
"/eservices/:eServiceId/descriptors/:descriptorId/clone",
Expand Down
20 changes: 20 additions & 0 deletions packages/bff/src/services/catalogService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,26 @@ export function catalogServiceBuilder(

return toBffCatalogApiEserviceRiskAnalysis(riskAnalysis);
},
getEServiceDocumentById: async (
eServiceId: EServiceId,
descriptorId: DescriptorId,
documentId: EServiceDocumentId,
ctx: WithLogger<BffAppContext>
): Promise<{ contentType: string; document: Buffer }> => {
const { path, contentType } =
await catalogProcessClient.getEServiceDocumentById({
params: {
eServiceId,
descriptorId,
documentId,
},
headers: ctx.headers,
});

const stream = await fileManager.get(config.s3Bucket, path, ctx.logger);

return { contentType, document: Buffer.from(stream) };
},
createDescriptor: async (
eServiceId: string,
{ headers, logger }: WithLogger<BffAppContext>
Expand Down
1 change: 0 additions & 1 deletion packages/commons/src/file-manager/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const streamToString = (data: Uint8Array): string => {
const decoder = new TextDecoder("utf-8");

return decoder.decode(data);
};

0 comments on commit f7f3eea

Please sign in to comment.