Skip to content

Commit

Permalink
feat: add FIMS endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacavallaro authored Nov 13, 2024
1 parent 4369c11 commit ac1afd7
Show file tree
Hide file tree
Showing 13 changed files with 874 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ROOT_REDIRECT_URL=https://io.italia.it
FF_BONUS_ENABLED=1
FF_CGN_ENABLED=1
FF_IO_SIGN_ENABLED=1
FF_IO_FIMS_ENABLED=1
FF_IO_WALLET_ENABLED=1
FF_IO_WALLET_TRIAL_ENABLED=1

Expand All @@ -49,6 +50,13 @@ IO_SIGN_API_URL=http://host.docker.internal:7075
IO_SIGN_API_BASE_PATH="/api/v1/sign"
IO_SIGN_SERVICE_ID="aIoSignServiceId"

# ------------------------------------
# IO_FIMS Env Variables
# ------------------------------------
IO_FIMS_API_KEY=put_your_api_key_here
IO_FIMS_API_URL=http://host.docker.internal:7075
IO_FIMS_API_BASE_PATH="/api/v1/fims"

# ------------------------------------
# CGN Env Variables
# ------------------------------------
Expand Down
142 changes: 142 additions & 0 deletions api_io_fims.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
openapi: 3.0.1
info:
version: 1.0.1
title: IO FIMS - Backend API
servers:
- url: https://api-app.io.pagopa.it/api/v1/fims
security:
- Bearer: []

paths:
/accesses:
get:
summary: Get access history
description: Get the access history for the specified user
operationId: getAccessHistory
parameters:
- in: query
name: page
schema:
type: string
description: The page identifier
- in: header
name: Accept-Language
required: false
schema:
type: string
responses:
"200":
description: An access history page
content:
application/json:
schema:
$ref: "#/components/schemas/AccessHistoryPage"
"400":
description: Validation error
content:
application/json:
schema:
$ref: "#/components/schemas/ProblemJson"
"500":
description: Internal server error
content:
application/json:
schema:
$ref: "#/components/schemas/ProblemJson"

/export-requests:
post:
summary: Request export
description: Request the export of the access history for the specified user
operationId: requestExport
responses:
"202":
description: The export request has been accepted
content:
application/json:
schema:
$ref: "#/components/schemas/ExportRequest"
"409":
description: The export request has already been requested
content:
application/json:
schema:
$ref: "#/components/schemas/ProblemJson"
"400":
description: Validation error
content:
application/json:
schema:
$ref: "#/components/schemas/ProblemJson"
"500":
description: Internal server error
content:
application/json:
schema:
$ref: "#/components/schemas/ProblemJson"

components:
securitySchemes:
Bearer:
type: apiKey
name: Authorization
in: header

schemas:
Timestamp:
$ref: "https://raw.githubusercontent.com/pagopa/io-functions-commons/v26.3.0/openapi/definitions.yaml#/Timestamp"

ProblemJson:
$ref: "https://raw.githubusercontent.com/pagopa/io-functions-commons/v26.3.0/openapi/definitions.yaml#/ProblemJson"

Redirect:
type: object
properties:
display_name:
type: string
uri:
type: string
format: uri
required:
- display_name
- uri

Access:
type: object
properties:
id:
type: string
format: ulid
redirect:
$ref: "#/components/schemas/Redirect"
service_id:
type: string
format: ulid
timestamp:
$ref: "#/components/schemas/Timestamp"
required:
- id
- redirect
- service_id
- timestamp

AccessHistoryPage:
type: object
properties:
data:
type: array
items:
$ref: "#/components/schemas/Access"
next:
type: string
required:
- data

ExportRequest:
type: object
properties:
id:
type: string
format: ulid
required:
- id
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
"generate:proxy:bonus-models": "rimraf generated/bonus && gen-api-models --api-spec api_bonus.yaml --out-dir generated/bonus",
"generate:proxy:cgn-models": "rimraf generated/cgn && gen-api-models --api-spec api_cgn.yaml --out-dir generated/cgn",
"generate:proxy:io-sign-models": "rimraf generated/io-sign && gen-api-models --api-spec api_io_sign.yaml --out-dir generated/io-sign",
"generate:proxy:io-fims-models": "rimraf generated/io-fims && gen-api-models --api-spec api_io_fims.yaml --out-dir generated/io-fims",
"generate:proxy:cgn-operator-search-models": "rimraf generated/cgn-operator-search && gen-api-models --api-spec api_cgn_operator_search.yaml --out-dir generated/cgn-operator-search",
"generate:api:io-bonus": "rimraf generated/io-bonus-api && gen-api-models --api-spec openapi/consumed/fn_bonus.yaml --no-strict --out-dir generated/io-bonus-api --request-types --response-decoders --client",
"generate:api:io-sign": "rimraf generated/io-sign-api && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-sign/0a9124b7c782b2569dd82c094496e50a17b418f4/apps/io-func-sign-user/openapi.yaml --no-strict --out-dir generated/io-sign-api --request-types --response-decoders --client",
"generate:api:io-fims": "rimraf generated/io-fims-api && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-fims/44c478f9b9ca024aa4db963873a85f8d9c37f5d3/apps/user-func/openapi.yaml --no-strict --out-dir generated/io-fims-api --request-types --response-decoders --client",
"generate:api:io-cgn-operator-search": "rimraf generated/io-cgn-operator-search-api && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-cgn/refs/tags/search-func@3.3.0/apps/search-func/openapi/index.yaml --no-strict --out-dir generated/io-cgn-operator-search-api --request-types --response-decoders --client",
"generate:api:pagopaproxy": "rimraf generated/pagopa-proxy && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-pagopa-proxy/v1.6.0/api-spec/api-for-io.yaml --no-strict --out-dir generated/pagopa-proxy --request-types --response-decoders --client",
"generate:api:lollipop": "rimraf generated/lollipop-api && gen-api-models --api-spec https://raw.githubusercontent.com/pagopa/io-functions-lollipop/724c3ba79d272d4e2555dbc2a8e1657bec9f84ce/openapi/internal.yaml --no-strict --out-dir generated/lollipop-api --request-types --response-decoders --client",
Expand Down
3 changes: 3 additions & 0 deletions src/__tests__/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const aMyPortalBasePath = "/myportal/api/v1";
const aCgnAPIBasePath = "/api/v1/cgn";
const aCgnOperatorSearchAPIBasePath = "/api/v1/cgn-operator-search";
const aEuCovidCertAPIBasePath = "/api/v1/eucovidcert";
const aIoFimsAPIBasePath = "/api/v1/fims";
const aIoSignAPIBasePath = "/api/v1/sign";
const aServicesAppBackendBasePath = "/api/v2";
const aTrialSystemBasePath = "/trials/api/v1";
Expand All @@ -80,6 +81,7 @@ describe("Success app start", () => {
CGNAPIBasePath: aCgnAPIBasePath,
CGNOperatorSearchAPIBasePath: aCgnOperatorSearchAPIBasePath,
EUCovidCertBasePath: aEuCovidCertAPIBasePath,
IoFimsAPIBasePath: aIoFimsAPIBasePath,
IoSignAPIBasePath: aIoSignAPIBasePath,
IoWalletAPIBasePath: aIoWalletAPIBasePath,
MyPortalBasePath: aMyPortalBasePath,
Expand Down Expand Up @@ -188,6 +190,7 @@ describe("Failure app start", () => {
CGNAPIBasePath: aCgnAPIBasePath,
CGNOperatorSearchAPIBasePath: aCgnOperatorSearchAPIBasePath,
EUCovidCertBasePath: aEuCovidCertAPIBasePath,
IoFimsAPIBasePath: aIoFimsAPIBasePath,
IoSignAPIBasePath: aIoSignAPIBasePath,
IoWalletAPIBasePath: aIoWalletAPIBasePath,
MyPortalBasePath: aMyPortalBasePath,
Expand Down
46 changes: 46 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ import {
FF_ENABLE_SESSION_ENDPOINTS,
FF_EUCOVIDCERT_ENABLED,
FF_IO_SIGN_ENABLED,
FF_IO_FIMS_ENABLED,
FF_IO_WALLET_ENABLED,
FF_ROUTING_PUSH_NOTIF,
FF_ROUTING_PUSH_NOTIF_BETA_TESTER_SHA_LIST,
FF_ROUTING_PUSH_NOTIF_CANARY_SHA_USERS_REGEX,
FF_TRIAL_SYSTEM_ENABLED,
FIRST_LOLLIPOP_CONSUMER_CLIENT,
IO_SIGN_API_CLIENT,
IO_FIMS_API_CLIENT,
IO_SIGN_SERVICE_ID,
IO_WALLET_API_CLIENT,
LOCKED_PROFILES_STORAGE_CONNECTION_STRING,
Expand Down Expand Up @@ -105,6 +107,7 @@ import CgnService from "./services/cgnService";
import EUCovidCertService from "./services/eucovidcertService";
import FunctionsAppService from "./services/functionAppService";
import IoSignService from "./services/ioSignService";
import IoFimsService from "./services/fimsService";
import LollipopService from "./services/lollipopService";
import NewMessagesService from "./services/newMessagesService";
import NotificationService from "./services/notificationService";
Expand Down Expand Up @@ -140,6 +143,7 @@ import TrialService from "./services/trialService";
import TrialController from "./controllers/trialController";
import IoWalletController from "./controllers/ioWalletController";
import IoWalletService from "./services/ioWalletService";
import IoFimsController from "./controllers/fimsController";

const defaultModule = {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
Expand All @@ -159,6 +163,7 @@ export interface IAppFactoryParameters {
readonly CGNAPIBasePath: string;
readonly CGNOperatorSearchAPIBasePath: string;
readonly IoSignAPIBasePath: string;
readonly IoFimsAPIBasePath: string;
readonly IoWalletAPIBasePath: string;
readonly EUCovidCertBasePath: string;
readonly ServicesAppBackendBasePath: string;
Expand All @@ -178,6 +183,7 @@ export async function newApp({
MyPortalBasePath,
CGNAPIBasePath,
IoSignAPIBasePath,
IoFimsAPIBasePath,
IoWalletAPIBasePath,
CGNOperatorSearchAPIBasePath,
EUCovidCertBasePath,
Expand Down Expand Up @@ -326,6 +332,9 @@ export async function newApp({
// Create the io sign
const IO_SIGN_SERVICE = new IoSignService(IO_SIGN_API_CLIENT);

// Create the io fims service
const IO_FIMS_SERVICE = new IoFimsService(IO_FIMS_API_CLIENT);

// Create the cgn operator search service
const CGN_OPERATOR_SEARCH_SERVICE = new CgnOperatorSearchService(
CGN_OPERATOR_SEARCH_API_CLIENT
Expand Down Expand Up @@ -512,6 +521,17 @@ export async function newApp({
);
}

if (FF_IO_FIMS_ENABLED) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerIoFimsAPIRoutes(
app,
IoFimsAPIBasePath,
IO_FIMS_SERVICE,
PROFILE_SERVICE,
authMiddlewares.bearerSession
);
}

if (FF_EUCOVIDCERT_ENABLED) {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
registerEUCovidCertAPIRoutes(
Expand Down Expand Up @@ -1161,6 +1181,32 @@ function registerIoSignAPIRoutes(
);
}

function registerIoFimsAPIRoutes(
app: Express,
basePath: string,
ioFimsService: IoFimsService,
profileService: ProfileService,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
bearerSessionTokenAuth: any
): void {
const ioFimsController: IoFimsController = new IoFimsController(
ioFimsService,
profileService
);

app.get(
`${basePath}/accesses`,
bearerSessionTokenAuth,
toExpressHandler(ioFimsController.getAccessHistory, ioFimsController)
);

app.post(
`${basePath}/export-requests`,
bearerSessionTokenAuth,
toExpressHandler(ioFimsController.requestExport, ioFimsController)
);
}

function registerCgnOperatorSearchAPIRoutes(
app: Express,
basePath: string,
Expand Down
23 changes: 23 additions & 0 deletions src/clients/io-fims.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import nodeFetch from "node-fetch";
import { Client, createClient } from "../../generated/io-fims-api/client";

export function IoFimsAPIClient(
token: string,
baseUrl: string,
basePath: string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fetchApi: typeof fetch = nodeFetch as any as typeof fetch
): Client<"FunctionsKey"> {
return createClient<"FunctionsKey">({
basePath,
baseUrl,
fetchApi,
withDefaults: (op) => (params) =>
op({
...params,
FunctionsKey: token,
}),
});
}

export type IoFimsAPIClient = typeof IoFimsAPIClient;
12 changes: 12 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { LollipopApiClient } from "./clients/lollipop";
import { FirstLollipopConsumerClient } from "./clients/firstLollipopConsumer";
import { TrialSystemAPIClient } from "./clients/trial-system.client";
import { IoWalletAPIClient } from "./clients/io-wallet";
import { IoFimsAPIClient } from "./clients/io-fims";

// Without this, the environment variables loaded by dotenv aren't available in
// this file.
Expand Down Expand Up @@ -187,6 +188,16 @@ export const IO_SIGN_API_CLIENT = IoSignAPIClient(
httpOrHttpsApiFetch
);

export const IO_FIMS_API_KEY = getRequiredENVVar("IO_FIMS_API_KEY");
export const IO_FIMS_API_URL = getRequiredENVVar("IO_FIMS_API_URL");
export const IO_FIMS_API_BASE_PATH = getRequiredENVVar("IO_FIMS_API_BASE_PATH");
export const IO_FIMS_API_CLIENT = IoFimsAPIClient(
IO_FIMS_API_KEY,
IO_FIMS_API_URL,
IO_FIMS_API_BASE_PATH,
httpOrHttpsApiFetch
);

export const CGN_API_KEY = getRequiredENVVar("CGN_API_KEY");
export const CGN_API_URL = getRequiredENVVar("CGN_API_URL");
export const CGN_API_BASE_PATH = getRequiredENVVar("CGN_API_BASE_PATH");
Expand Down Expand Up @@ -422,6 +433,7 @@ export const DEFAULT_APPINSIGHTS_SAMPLING_PERCENTAGE = 5;
export const FF_BONUS_ENABLED = process.env.FF_BONUS_ENABLED === "1";
export const FF_CGN_ENABLED = process.env.FF_CGN_ENABLED === "1";
export const FF_IO_SIGN_ENABLED = process.env.FF_IO_SIGN_ENABLED === "1";
export const FF_IO_FIMS_ENABLED = process.env.FF_IO_FIMS_ENABLED === "1";
export const FF_EUCOVIDCERT_ENABLED =
process.env.FF_EUCOVIDCERT_ENABLED === "1";

Expand Down
Loading

0 comments on commit ac1afd7

Please sign in to comment.