UNPKG

sonarqube-scanner

Version:
56 lines (55 loc) 2.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProxyUrl = getProxyUrl; exports.proxyUrlToJavaOptions = proxyUrlToJavaOptions; /* * sonar-scanner-npm * Copyright (C) SonarSource Sàrl * mailto:info AT sonarsource DOT com * * You can redistribute and/or modify this program under the terms of * the Sonar Source-Available License Version 1, as published by SonarSource Sàrl. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the Sonar Source-Available License for more details. * * You should have received a copy of the Sonar Source-Available License * along with this program; if not, see https://sonarsource.com/license/ssal/ */ const node_url_1 = require("node:url"); const logging_1 = require("./logging"); const types_1 = require("./types"); function getProxyUrl(properties) { const proxyHost = properties[types_1.ScannerProperty.SonarScannerProxyHost]; if (proxyHost) { const proxyPort = properties[types_1.ScannerProperty.SonarScannerProxyPort] ?? '80'; const proxyUser = properties[types_1.ScannerProperty.SonarScannerProxyUser] ?? ''; const proxyPassword = properties[types_1.ScannerProperty.SonarScannerProxyPassword] ?? ''; // SCANNPM-47 We assume the proxy is HTTP. HTTPS proxies are not supported by the scanner yet (CONNECT over TLS) const proxyUrl = new node_url_1.URL(`http://${proxyUser}:${proxyPassword}@${proxyHost}:${proxyPort}`); (0, logging_1.log)(logging_1.LogLevel.DEBUG, `Detecting proxy: ${proxyUrl}`); return proxyUrl; } else if (properties[types_1.ScannerProperty.SonarScannerProxyPort] || properties[types_1.ScannerProperty.SonarScannerProxyUser] || properties[types_1.ScannerProperty.SonarScannerProxyPassword]) { (0, logging_1.log)(logging_1.LogLevel.WARN, `Detecting proxy: Incomplete proxy configuration. Proxy host is missing.`); } (0, logging_1.log)(logging_1.LogLevel.DEBUG, 'Detecting proxy: No proxy detected'); return undefined; } function proxyUrlToJavaOptions(properties) { const proxyUrl = getProxyUrl(properties); if (!proxyUrl) { return []; } const protocol = properties[types_1.ScannerProperty.SonarHostUrl].startsWith('https') ? 'https' : 'http'; return [ `-D${protocol}.proxyHost=${proxyUrl.hostname}`, `-D${protocol}.proxyPort=${proxyUrl.port}`, `-D${protocol}.proxyUser=${proxyUrl.username}`, `-D${protocol}.proxyPassword=${proxyUrl.password}`, ]; }