Skip to content

Commit 35f833d

Browse files
authored
feat: added migrateWalletInstances function
Refs: #598 [SIW-3556]
1 parent 8a3b0e7 commit 35f833d

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

.changeset/whole-dancers-raise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"io-wallet-user-func": minor
3+
---
4+
5+
Added function `migrateWalletInstances` to copy wallet instances data to new tenant database collection

apps/io-wallet-user-func/local.settings.json.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
"PidIssuerHealthCheckEnabled": "PID_ISSUER_HEALTH_CHECK_ENABLED",
4141
"PidIssuerApiRequestTimeout": "PID_ISSUER_API_REQUEST_TIMEOUT",
4242
"HttpRequestTimeout": "HTTP_REQUEST_TIMEOUT",
43-
"SkipSignatureValidation": "SKIP_SIGNATURE_VALIDATION",
4443
"HardwarePublicTestKey": "HARDWARE_PUBLIC_TEST_PEM_BASE64_ENCODED",
45-
"SlackStatusChannelWebhook": "SLACK_STATUS_CHANNEL_WEBHOOK",
4644
"MailupUsername": "MAILUP_USERNAME",
4745
"MailupSecret": "MAILUP_SECRET",
4846
"MailSender": "MAIL_SENDER",
@@ -59,6 +57,7 @@
5957
"FrontDoorProfileName": "FRONT_DOOR_PROFILE_NAME",
6058
"FrontDoorEndpointName": "FRONT_DOOR_ENDPOINT_NAME",
6159
"APPLICATIONINSIGHTS_CONNECTION_STRING": "APPLICATIONINSIGHTS_CONNECTION_STRING",
62-
"NODE_OPTIONS": "--import @pagopa/azure-tracing"
60+
"NODE_OPTIONS": "--import @pagopa/azure-tracing",
61+
"PagoPACosmosDbConnectionString": "PAGOPA_COSMOS_DB_CONNECTION_STRING"
6362
}
6463
}

apps/io-wallet-user-func/src/app/main.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CdnManagementClient } from "@azure/arm-cdn";
22
import { CosmosClient } from "@azure/cosmos";
3-
import { app } from "@azure/functions";
3+
import { app, output } from "@azure/functions";
44
import { DefaultAzureCredential } from "@azure/identity";
55
import { BlobServiceClient } from "@azure/storage-blob";
66
import { QueueServiceClient } from "@azure/storage-queue";
@@ -10,6 +10,7 @@ import { Crypto } from "@peculiar/webcrypto";
1010
import * as E from "fp-ts/Either";
1111
import { identity, pipe } from "fp-ts/function";
1212
import * as t from "io-ts";
13+
import { WalletInstance } from "io-wallet-common/wallet-instance";
1314

1415
import { getCrlFromUrl } from "@/certificates";
1516
import { CosmosDbCertificateRepository } from "@/infra/azure/cosmos/certificate";
@@ -26,6 +27,7 @@ import { GetCurrentWalletInstanceStatusFunction } from "@/infra/azure/functions/
2627
import { GetNonceFunction } from "@/infra/azure/functions/get-nonce";
2728
import { GetWalletInstanceStatusFunction } from "@/infra/azure/functions/get-wallet-instance-status";
2829
import { HealthFunction } from "@/infra/azure/functions/health";
30+
import { MigrateWalletInstancesFunction } from "@/infra/azure/functions/migrate-wallet-instances";
2931
import { SendEmailOnWalletInstanceCreationFunction } from "@/infra/azure/functions/send-email-on-wallet-instance-creation";
3032
import { SendEmailOnWalletInstanceRevocationFunction } from "@/infra/azure/functions/send-email-on-wallet-instance-revocation";
3133
import { SetWalletInstanceStatusFunction } from "@/infra/azure/functions/set-wallet-instance-status";
@@ -299,3 +301,22 @@ app.http("generateCertificateChain", {
299301
methods: ["POST"],
300302
route: "certificate-chain",
301303
});
304+
305+
app.cosmosDB("migrateWalletInstances", {
306+
connection: "PagoPACosmosDbConnectionString",
307+
containerName: "wallet-instances",
308+
createLeaseCollectionIfNotExists: true,
309+
databaseName: "db",
310+
handler: MigrateWalletInstancesFunction({
311+
inputDecoder: t.array(WalletInstance),
312+
}),
313+
leaseContainerName: "leases-migration",
314+
maxItemsPerInvocation: 50,
315+
return: output.cosmosDB({
316+
connection: "CosmosDbEndpoint",
317+
containerName: "wallet-instances",
318+
createIfNotExists: false,
319+
databaseName: "db",
320+
}),
321+
startFromBeginning: true,
322+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { azureFunction } from "@pagopa/handler-kit-azure-func";
2+
3+
import { MigrateWalletInstancesHandler } from "@/infra/handlers/migrate-wallet-instances";
4+
5+
export const MigrateWalletInstancesFunction = azureFunction(
6+
MigrateWalletInstancesHandler,
7+
);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as H from "@pagopa/handler-kit";
2+
import { flow, pipe } from "fp-ts/function";
3+
import * as RTE from "fp-ts/lib/ReaderTaskEither";
4+
import { WalletInstance } from "io-wallet-common/wallet-instance";
5+
6+
import { sendTelemetryException } from "@/infra/telemetry";
7+
8+
export const MigrateWalletInstancesHandler = H.of(
9+
(walletInstances: WalletInstance[]) =>
10+
pipe(
11+
walletInstances,
12+
RTE.right,
13+
RTE.orElseFirstW(
14+
flow(
15+
sendTelemetryException({
16+
functionName: "migrateWalletInstances",
17+
}),
18+
RTE.fromEither,
19+
),
20+
),
21+
),
22+
);

0 commit comments

Comments
 (0)