UNPKG

enhanced-adot-node-autoinstrumentation

Version:

This package provides Amazon Web Services distribution of the OpenTelemetry Node Instrumentation, which allows for auto-instrumentation of NodeJS applications.

56 lines 2.11 kB
"use strict"; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.SqsUrlParser = void 0; const HTTP_SCHEMA = 'http://'; const HTTPS_SCHEMA = 'https://'; // Cannot define type for regex variables // eslint-disable-next-line @typescript-eslint/typedef const ALPHABET_REGEX = /^[a-zA-Z]+$/; class SqsUrlParser { /** * Best-effort logic to extract queue name from an HTTP url. This method should only be used with * a string that is, with reasonably high confidence, an SQS queue URL. Handles new/legacy/some * custom URLs. Essentially, we require that the URL should have exactly three parts, delimited by * /'s (excluding schema), the second part should be a 12-digit account id, and the third part * should be a valid queue name, per SQS naming conventions. */ static getQueueName(url) { if (typeof url !== 'string') { return undefined; } url = url.replace(HTTP_SCHEMA, '').replace(HTTPS_SCHEMA, ''); const splitUrl = url.split('/'); if (splitUrl.length === 3 && this.isAccountId(splitUrl[1]) && this.isValidQueueName(splitUrl[2])) { return splitUrl[2]; } return undefined; } static isAccountId(input) { if (input == null || input.length !== 12) { return false; } if (!this._checkDigits(input)) { return false; } return true; } static _checkDigits(str) { return /^\d+$/.test(str); } static isValidQueueName(input) { if (input == null || input.length === 0 || input.length > 80) { return false; } for (let i = 0; i < input.length; i++) { const c = input.charAt(i); if (c !== '_' && c !== '-' && !ALPHABET_REGEX.test(c) && !(c >= '0' && c <= '9')) { return false; } } return true; } } exports.SqsUrlParser = SqsUrlParser; //# sourceMappingURL=sqs-url-parser.js.map