UNPKG

@sonar/scan

Version:
59 lines (58 loc) 2.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getProxyUrl = getProxyUrl; exports.proxyUrlToJavaOptions = proxyUrlToJavaOptions; /* * sonar-scanner-npm * Copyright (C) 2022-2025 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * 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 GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ const url_1 = require("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 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}`, ]; }