Skip to content

Commit

Permalink
Refactor storage configuration (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuele De Cupis authored Nov 18, 2021
1 parent ad574cc commit 64887cb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
4 changes: 3 additions & 1 deletion GetMessage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ const notificationStatusModel = new NotificationStatusModel(
cosmosdbInstance.container(NOTIFICATION_STATUS_COLLECTION_NAME)
);

const blobService = createBlobService(config.QueueStorageConnection);
const blobService = createBlobService(
config.MESSAGE_CONTENT_STORAGE_CONNECTION_STRING
);

app.get(
"/api/v1/messages/:fiscalcode/:id",
Expand Down
4 changes: 3 additions & 1 deletion GetSubscriptionsFeed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const serviceModel = new ServiceModel(
cosmosdbInstance.container(SERVICE_COLLECTION_NAME)
);

const tableService = createTableService(config.QueueStorageConnection);
const tableService = createTableService(
config.SUBSCRIPTION_FEED_STORAGE_CONNECTION_STRING
);

app.get(
"/api/v1/subscriptions-feed/:date",
Expand Down
13 changes: 12 additions & 1 deletion Info/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ export function Info(): express.RequestHandler {
const handler = InfoHandler(
healthcheck.checkApplicationHealth(IConfig, [
c => healthcheck.checkAzureCosmosDbHealth(c.COSMOSDB_URI, c.COSMOSDB_KEY),
c => healthcheck.checkAzureStorageHealth(c.QueueStorageConnection),
c =>
healthcheck.checkAzureStorageHealth(
c.MESSAGE_CONTENT_STORAGE_CONNECTION_STRING
),
c =>
healthcheck.checkAzureStorageHealth(
c.SUBSCRIPTION_FEED_STORAGE_CONNECTION_STRING
),
c =>
healthcheck.checkAzureStorageHealth(
c.INTERNAL_STORAGE_CONNECTION_STRING
),
c => healthcheck.checkUrlHealth(c.WEBHOOK_CHANNEL_URL)
])
);
Expand Down
12 changes: 9 additions & 3 deletions ProcessMessage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ const messageModel = new MessageModel(
config.MESSAGE_CONTAINER_NAME
);

const blobService = createBlobService(config.QueueStorageConnection);
const blobServiceForMessageContent = createBlobService(
config.MESSAGE_CONTENT_STORAGE_CONNECTION_STRING
);

const blobServiceForTemporaryProcessingMessage = createBlobService(
config.INTERNAL_STORAGE_CONNECTION_STRING
);

const servicePreferencesModel = new ServicesPreferencesModel(
cosmosdbInstance.container(SERVICE_PREFERENCES_COLLECTION_NAME),
Expand All @@ -52,13 +58,13 @@ const telemetryClient = initTelemetryClient(

const retrieveProcessingMessageData = makeRetrieveExpandedDataFromBlob(
CommonMessageData,
blobService,
blobServiceForTemporaryProcessingMessage,
config.PROCESSING_MESSAGE_CONTAINER_NAME
);

const activityFunctionHandler: AzureFunction = getProcessMessageHandler({
isOptInEmailEnabled: config.FF_OPT_IN_EMAIL_ENABLED,
lBlobService: blobService,
lBlobService: blobServiceForMessageContent,
lMessageModel: messageModel,
lMessageStatusModel: messageStatusModel,
lProfileModel: profileModel,
Expand Down
4 changes: 3 additions & 1 deletion StoreMessageContentActivity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const messageModel = new MessageModel(
config.MESSAGE_CONTAINER_NAME
);

const blobService = createBlobService(config.QueueStorageConnection);
const blobService = createBlobService(
config.MESSAGE_CONTENT_STORAGE_CONNECTION_STRING
);

const servicePreferencesModel = new ServicesPreferencesModel(
cosmosdbInstance.container(SERVICE_PREFERENCES_COLLECTION_NAME),
Expand Down
19 changes: 15 additions & 4 deletions utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { NumberFromString } from "@pagopa/ts-commons/lib/numbers";
import { pipe } from "fp-ts/lib/function";
import { CommaSeparatedListOf } from "./comma-separated-list";

// used for internal job dispatch, temporary files, etc...
const InternalStorageAccount = t.interface({
INTERNAL_STORAGE_CONNECTION_STRING: NonEmptyString,
// queues for handling message processing jobs
Expand All @@ -28,6 +29,18 @@ const InternalStorageAccount = t.interface({
PROCESSING_MESSAGE_CONTAINER_NAME: NonEmptyString
});

// used to read and write message content on blob storage
const MessageContentStorageAccount = t.interface({
MESSAGE_CONTAINER_NAME: NonEmptyString,
MESSAGE_CONTENT_STORAGE_CONNECTION_STRING: NonEmptyString
});

// used to read and write subscription feed entries on table storage
const SubscriptionFeedStorageAccount = t.interface({
SUBSCRIPTIONS_FEED_TABLE: NonEmptyString,
SUBSCRIPTION_FEED_STORAGE_CONNECTION_STRING: NonEmptyString
});

// global app configuration
export type IConfig = t.TypeOf<typeof IConfig>;
export const IConfig = t.intersection([
Expand All @@ -47,13 +60,9 @@ export const IConfig = t.intersection([
IO_FUNCTIONS_ADMIN_API_TOKEN: NonEmptyString,
IO_FUNCTIONS_ADMIN_BASE_URL: NonEmptyString,

MESSAGE_CONTAINER_NAME: NonEmptyString,
OPT_OUT_EMAIL_SWITCH_DATE: DateFromTimestamp,

QueueStorageConnection: NonEmptyString,

SANDBOX_FISCAL_CODE: NonEmptyString,
SUBSCRIPTIONS_FEED_TABLE: NonEmptyString,

WEBHOOK_CHANNEL_URL: NonEmptyString,

Expand All @@ -65,6 +74,8 @@ export const IConfig = t.intersection([

isProduction: t.boolean
}),
MessageContentStorageAccount,
SubscriptionFeedStorageAccount,
InternalStorageAccount,
MailerConfig
]);
Expand Down

0 comments on commit 64887cb

Please sign in to comment.