зеркало из https://github.com/mozilla/fxa.git
Родитель
57b2cbecf8
Коммит
fe2b56989c
|
@ -23,6 +23,15 @@ const db = firestoreEnabled
|
|||
? createDatastore(FirestoreDatastore, firestoreConfig)
|
||||
: createDatastore(InMemoryDatastore, {});
|
||||
|
||||
export function extractRegionFromUrl(url: string) {
|
||||
const matchResult = url.match(/(?:.*\/sqs\.)([^\.]+)/i);
|
||||
if (!matchResult || matchResult.length !== 2) {
|
||||
return undefined;
|
||||
} else {
|
||||
return matchResult[1];
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const capabilityService = new ClientCapabilityService(
|
||||
logger,
|
||||
|
@ -37,15 +46,14 @@ async function main() {
|
|||
|
||||
// Extract region for SQS object
|
||||
const serviceNotificationQueueUrl = Config.get('serviceNotificationQueueUrl');
|
||||
const matchResult = serviceNotificationQueueUrl.match(/(?:.*\/sqs\.)([^\.]+)/i);
|
||||
if (!matchResult || matchResult.length !== 2) {
|
||||
const region = extractRegionFromUrl(serviceNotificationQueueUrl);
|
||||
if (!region) {
|
||||
logger.error('invalidServiceUrl', {
|
||||
message: 'Cant find region in service url',
|
||||
serviceNotificationQueueUrl
|
||||
});
|
||||
process.exit(8);
|
||||
}
|
||||
const region = matchResult![1];
|
||||
const processor = new ServiceNotificationProcessor(
|
||||
logger,
|
||||
db,
|
||||
|
@ -87,4 +95,6 @@ async function main() {
|
|||
}
|
||||
}
|
||||
|
||||
main();
|
||||
if (require.main === module) {
|
||||
main();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
/* 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 { assert } from 'chai';
|
||||
import 'mocha';
|
||||
|
||||
import { extractRegionFromUrl } from '../../bin/worker';
|
||||
|
||||
describe('Worker', () => {
|
||||
it('extracts the region from the config', () => {
|
||||
const url = 'https://sqs.us-east-1.amazonaws.com/8284828319293/service-notifications';
|
||||
const region = extractRegionFromUrl(url);
|
||||
assert.equal(region, 'us-east-1');
|
||||
});
|
||||
|
||||
it('extracts undefined for invalid url', () => {
|
||||
const url = 'http://example.com/example';
|
||||
const region = extractRegionFromUrl(url);
|
||||
assert.equal(region, undefined);
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче