Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#172621882] use different blob service for message and user data #52

Merged
merged 1 commit into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ coverage

yarn-error.log

generated
generated
.env.prod
.env.test
todo.md
57 changes: 30 additions & 27 deletions ExtractUserDataActivity/__tests__/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@ describe("createExtractUserDataActivityHandler", () => {

it("should handle export for existing user", async () => {
const { blobServiceMock } = setupStreamMocks();
const handler = createExtractUserDataActivityHandler(
messageModelMock,
messageStatusModelMock,
notificationModelMock,
notificationStatusModelMock,
profileModelMock,
blobServiceMock,
aUserDataContainerName
);
const handler = createExtractUserDataActivityHandler({
messageContentBlobService: blobServiceMock,
messageModel: messageModelMock,
messageStatusModel: messageStatusModelMock,
notificationModel: notificationModelMock,
notificationStatusModel: notificationStatusModelMock,
profileModel: profileModelMock,
userDataBlobService: blobServiceMock,
userDataContainerName: aUserDataContainerName
});
const input: ActivityInput = {
fiscalCode: aFiscalCode
};
Expand All @@ -141,15 +142,16 @@ describe("createExtractUserDataActivityHandler", () => {
)
} as any) as NotificationModel;

const handler = createExtractUserDataActivityHandler(
messageModelMock,
messageStatusModelMock,
notificationWebhookModelMock,
notificationStatusModelMock,
profileModelMock,
blobServiceMock,
aUserDataContainerName
);
const handler = createExtractUserDataActivityHandler({
messageContentBlobService: blobServiceMock,
messageModel: messageModelMock,
messageStatusModel: messageStatusModelMock,
notificationModel: notificationWebhookModelMock,
notificationStatusModel: notificationStatusModelMock,
profileModel: profileModelMock,
userDataBlobService: blobServiceMock,
userDataContainerName: aUserDataContainerName
});
const input: ActivityInput = {
fiscalCode: aFiscalCode
};
Expand All @@ -167,15 +169,16 @@ describe("createExtractUserDataActivityHandler", () => {
const { blobServiceMock, aZipStream } = setupStreamMocks();
const appendSpy = jest.spyOn(aZipStream, "append");

const handler = createExtractUserDataActivityHandler(
messageModelMock,
messageStatusModelMock,
notificationModelMock,
notificationStatusModelMock,
profileModelMock,
blobServiceMock,
aUserDataContainerName
);
const handler = createExtractUserDataActivityHandler({
messageContentBlobService: blobServiceMock,
messageModel: messageModelMock,
messageStatusModel: messageStatusModelMock,
notificationModel: notificationModelMock,
notificationStatusModel: notificationStatusModelMock,
profileModel: profileModelMock,
userDataBlobService: blobServiceMock,
userDataContainerName: aUserDataContainerName
});
const input: ActivityInput = {
fiscalCode: aFiscalCode
};
Expand Down
46 changes: 31 additions & 15 deletions ExtractUserDataActivity/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export const getProfile = (
* Retrieves all contents for provided messages
*/
export const getAllMessageContents = (
blobService: BlobService,
messageContentBlobService: BlobService,
messageModel: MessageModel,
messages: readonly RetrievedMessageWithoutContent[]
): TaskEither<
Expand All @@ -247,7 +247,8 @@ export const getAllMessageContents = (
array.sequence(taskEither)(
messages.map(({ id: messageId }) =>
fromQueryEither(
() => messageModel.getContentFromBlob(blobService, messageId),
() =>
messageModel.getContentFromBlob(messageContentBlobService, messageId),
"messageModel.getContentFromBlob (1)"
).foldTaskEither<ActivityResultQueryFailure, MessageContentWithId>(
failure => fromEither(left(failure)),
Expand Down Expand Up @@ -373,7 +374,7 @@ export const queryAllUserData = (
notificationModel: NotificationModel,
notificationStatusModel: NotificationStatusModel,
profileModel: ProfileModel,
blobService: BlobService,
messageContentBlobService: BlobService,
fiscalCode: FiscalCode
): TaskEither<
ActivityResultUserNotFound | ActivityResultQueryFailure,
Expand All @@ -399,7 +400,7 @@ export const queryAllUserData = (
const asRetrievedMessages = (messages as any) as readonly RetrievedMessageWithoutContent[];
return sequenceS(taskEither)({
messageContents: getAllMessageContents(
blobService,
messageContentBlobService,
messageModel,
asRetrievedMessages
),
Expand Down Expand Up @@ -520,18 +521,33 @@ export const saveDataToBlob = (
).map(_ => _[2]);
};

export interface IActivityHandlerInput {
messageModel: MessageModel;
messageStatusModel: MessageStatusModel;
notificationModel: NotificationModel;
notificationStatusModel: NotificationStatusModel;
profileModel: ProfileModel;
messageContentBlobService: BlobService;
userDataBlobService: BlobService;
userDataContainerName: NonEmptyString;
}

/**
* Factory methods that builds an activity function
*/
export function createExtractUserDataActivityHandler(
messageModel: MessageModel,
messageStatusModel: MessageStatusModel,
notificationModel: NotificationModel,
notificationStatusModel: NotificationStatusModel,
profileModel: ProfileModel,
blobService: BlobService,
userDataContainerName: NonEmptyString
): (context: Context, input: unknown) => Promise<ActivityResult> {
export function createExtractUserDataActivityHandler({
messageModel,
messageStatusModel,
notificationModel,
notificationStatusModel,
profileModel,
messageContentBlobService,
userDataBlobService,
userDataContainerName
}: IActivityHandlerInput): (
context: Context,
input: unknown
) => Promise<ActivityResult> {
return (context: Context, input: unknown) =>
fromEither(
ActivityInput.decode(input).mapLeft<ActivityResultFailure>(
Expand All @@ -549,7 +565,7 @@ export function createExtractUserDataActivityHandler(
notificationModel,
notificationStatusModel,
profileModel,
blobService,
messageContentBlobService,
fiscalCode
)
)
Expand All @@ -563,7 +579,7 @@ export function createExtractUserDataActivityHandler(
})
.chain(allUserData =>
saveDataToBlob(
blobService,
userDataBlobService,
userDataContainerName,
allUserData,
generateStrongPassword()
Expand Down
17 changes: 12 additions & 5 deletions ExtractUserDataActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,25 @@ const profileModel = new ProfileModel(
)
);

const blobService = createBlobService(
const userDataBlobService = createBlobService(
getRequiredStringEnv("UserDataArchiveStorageConnection")
);

const activityFunctionHandler = createExtractUserDataActivityHandler(
const messageContentBlobService = createBlobService(
getRequiredStringEnv("MessageContentStorageConnection")
);

const userDataContainerName = getRequiredStringEnv("USER_DATA_CONTAINER_NAME");

const activityFunctionHandler = createExtractUserDataActivityHandler({
messageContentBlobService,
messageModel,
messageStatusModel,
notificationModel,
notificationStatusModel,
profileModel,
blobService,
getRequiredStringEnv("USER_DATA_CONTAINER_NAME")
);
userDataBlobService,
userDataContainerName
});

export default activityFunctionHandler;
4 changes: 3 additions & 1 deletion UserDataDownloadOrchestrator/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// tslint:disable: no-console no-any

import * as dotenv from "dotenv";
dotenv.config();
dotenv.config({
path: ".env.test"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

});

import { Context } from "@azure/functions";
import { readableReport } from "italia-ts-commons/lib/reporters";
Expand Down