CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
redact.js86 linesDownload Raw Back to lib
1"use strict";2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {3    if (k2 === undefined) k2 = k;4    var desc = Object.getOwnPropertyDescriptor(m, k);5    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {6      desc = { enumerable: true, get: function() { return m[k]; } };7    }8    Object.defineProperty(o, k2, desc);9}) : (function(o, m, k, k2) {10    if (k2 === undefined) k2 = k;11    o[k2] = m[k];12}));13var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {14    Object.defineProperty(o, "default", { enumerable: true, value: v });15}) : function(o, v) {16    o["default"] = v;17});18var __importStar = (this && this.__importStar) || function (mod) {19    if (mod && mod.__esModule) return mod;20    var result = {};21    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);22    __setModuleDefault(result, mod);23    return result;24};25Object.defineProperty(exports, "__esModule", { value: true });26exports.redactConnectionString = exports.redactValidConnectionString = void 0;27const index_1 = __importStar(require("./index"));28function redactValidConnectionString(inputUrl, options) {29    var _a, _b;30    const url = inputUrl.clone();31    const replacementString = (_a = options === null || options === void 0 ? void 0 : options.replacementString) !== null && _a !== void 0 ? _a : '_credentials_';32    const redactUsernames = (_b = options === null || options === void 0 ? void 0 : options.redactUsernames) !== null && _b !== void 0 ? _b : true;33    if ((url.username || url.password) && redactUsernames) {34        url.username = replacementString;35        url.password = '';36    }37    else if (url.password) {38        url.password = replacementString;39    }40    if (url.searchParams.has('authMechanismProperties')) {41        const props = new index_1.CommaAndColonSeparatedRecord(url.searchParams.get('authMechanismProperties'));42        if (props.get('AWS_SESSION_TOKEN')) {43            props.set('AWS_SESSION_TOKEN', replacementString);44            url.searchParams.set('authMechanismProperties', props.toString());45        }46    }47    if (url.searchParams.has('tlsCertificateKeyFilePassword')) {48        url.searchParams.set('tlsCertificateKeyFilePassword', replacementString);49    }50    if (url.searchParams.has('proxyUsername') && redactUsernames) {51        url.searchParams.set('proxyUsername', replacementString);52    }53    if (url.searchParams.has('proxyPassword')) {54        url.searchParams.set('proxyPassword', replacementString);55    }56    return url;57}58exports.redactValidConnectionString = redactValidConnectionString;59function redactConnectionString(uri, options) {60    var _a, _b;61    const replacementString = (_a = options === null || options === void 0 ? void 0 : options.replacementString) !== null && _a !== void 0 ? _a : '<credentials>';62    const redactUsernames = (_b = options === null || options === void 0 ? void 0 : options.redactUsernames) !== null && _b !== void 0 ? _b : true;63    let parsed;64    try {65        parsed = new index_1.default(uri);66    }67    catch (_c) { }68    if (parsed) {69        options = { ...options, replacementString: '___credentials___' };70        return parsed.redact(options).toString().replace(/___credentials___/g, replacementString);71    }72    const R = replacementString;73    const replacements = [74        uri => uri.replace(redactUsernames ? /(\/\/)(.*)(@)/g : /(\/\/[^@]*:)(.*)(@)/g, `$1${R}$3`),75        uri => uri.replace(/(AWS_SESSION_TOKEN(:|%3A))([^,&]+)/gi, `$1${R}`),76        uri => uri.replace(/(tlsCertificateKeyFilePassword=)([^&]+)/gi, `$1${R}`),77        uri => redactUsernames ? uri.replace(/(proxyUsername=)([^&]+)/gi, `$1${R}`) : uri,78        uri => uri.replace(/(proxyPassword=)([^&]+)/gi, `$1${R}`)79    ];80    for (const replacer of replacements) {81        uri = replacer(uri);82    }83    return uri;84}85exports.redactConnectionString = redactConnectionString;86//# sourceMappingURL=redact.js.map