feat: add queue prefix config and fix login validation

Because:

* The queue prefix is not configurable and FxA reuses client ID's in
  the dev/stage environment.
* Login messages don't always include a service property.

This commit:

* Allows the queue prefix to be configured.
* Makes the service property optional for login messages.

Closes #2819
This commit is contained in:
Ben Bangert 2019-10-09 17:10:14 -07:00
Родитель da63f5570a
Коммит 1e00dc4aba
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 340D6D716D25CCA6
7 изменённых файлов: 15 добавлений и 4 удалений

Просмотреть файл

@ -67,6 +67,7 @@ async function main() {
capabilityService,
webhookService,
pubsub,
Config.get('topicPrefix'),
serviceNotificationQueueUrl,
new SQS({ region })
);

Просмотреть файл

@ -139,6 +139,7 @@ async function main() {
capabilityService,
webhookService,
pubsub,
Config.get('topicPrefix'),
Config.get('serviceNotificationQueueUrl'),
new SQS()
);

Просмотреть файл

@ -181,6 +181,12 @@ const conf = convict({
'The queue URL to use (should include https://sqs.<region>.amazonaws.com/<account-id>/<queue-name>)',
env: 'SERVICE_NOTIFICATION_QUEUE_URL',
format: String
},
topicPrefix: {
default: 'rpQueue-',
doc: 'GCP PubSub Queue prefix',
env: 'PUBSUB_QUEUE_PREFIX',
format: String
}
});

Просмотреть файл

@ -1,7 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { DocumentData, Firestore, Settings } from '@google-cloud/firestore';
import { Firestore, Settings } from '@google-cloud/firestore';
import { TypedCollectionReference, TypedDocumentReference } from 'typesafe-node-firestore';
import { ClientWebhooks } from '../selfUpdatingService/clientWebhookService';

Просмотреть файл

@ -31,7 +31,6 @@ function unhandledEventType(e: ServiceNotification) {
class ServiceNotificationProcessor {
public readonly app: Consumer;
private readonly topicPrefix = 'rpQueue-';
constructor(
private readonly logger: Logger,
@ -40,6 +39,7 @@ class ServiceNotificationProcessor {
private readonly capabilityService: ClientCapabilityService,
private readonly webhookService: ClientWebhookService,
private readonly pubsub: PubSub,
private readonly topicPrefix: string,
queueUrl: string,
sqs: SQS
) {

Просмотреть файл

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import * as sentry from '@sentry/node';
import { Logger } from 'mozlog';
import * as joi from 'typesafe-joi';
@ -32,7 +33,7 @@ const LOGIN_SCHEMA = joi
.string()
.valid(LOGIN_EVENT)
.required(),
service: joi.string().required(),
service: joi.string().optional(),
timestamp: joi.number().optional(),
ts: joi.number().required(),
uid: joi.string().required(),
@ -121,7 +122,7 @@ function multiSchemaAttempt(
}
export const ServiceNotification = {
from(logger: Logger, rawMessage: object): ServiceNotification {
from(logger: Logger, rawMessage: object): ServiceNotification | undefined {
try {
const validMessage = multiSchemaAttempt(eventSchemas, rawMessage);
if (validMessage) {
@ -129,6 +130,7 @@ export const ServiceNotification = {
return validMessage;
}
} catch (err) {
sentry.captureException(err);
logger.error('from.sqsMessage', { message: 'Invalid message', err });
}
}

Просмотреть файл

@ -95,6 +95,7 @@ describe('ServiceNotificationProcessor', () => {
capabilityService,
webhookService,
pubsub,
'rpQueue-',
'https://sqs.eu-west-1.amazonaws.com/account-id/queue-name',
sqs
);