@pellegrims/nx-remotecache-s3
Version:
Remote caching for @nrwl/nx using S3 storage
50 lines • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchesNoProxy = exports.getNoProxy = exports.getHttpsProxy = exports.getHttpProxy = exports.buildCommonCommandInput = exports.getEnv = void 0;
const matcher_1 = require("matcher");
const HTTP_PROXY = 'HTTP_PROXY';
const HTTPS_PROXY = 'HTTPS_PROXY';
const NO_PROXY = 'NO_PROXY';
const getEnv = (key) => process.env[key];
exports.getEnv = getEnv;
const buildCommonCommandInput = (bucket, prefix, filename) => ({
/* eslint-disable @typescript-eslint/naming-convention */
Bucket: bucket,
Key: `${prefix}${filename}`,
/* eslint-enable @typescript-eslint/naming-convention */
});
exports.buildCommonCommandInput = buildCommonCommandInput;
const getHttpProxy = () => (0, exports.getEnv)(HTTP_PROXY.toLowerCase()) || (0, exports.getEnv)(HTTP_PROXY) || undefined;
exports.getHttpProxy = getHttpProxy;
const getHttpsProxy = () => (0, exports.getEnv)(HTTPS_PROXY.toLowerCase()) || (0, exports.getEnv)(HTTPS_PROXY) || undefined;
exports.getHttpsProxy = getHttpsProxy;
const getNoProxy = () => (0, exports.getEnv)(NO_PROXY.toLowerCase()) || (0, exports.getEnv)(NO_PROXY) || undefined;
exports.getNoProxy = getNoProxy;
const matchesNoProxy = (subjectUrl, noProxy) => {
if (!noProxy)
return false;
const subjectUrlTokens = new URL(subjectUrl);
const rules = noProxy.split(/[\s,]+/);
for (const rule of rules) {
const ruleMatch = rule
.replace(/^(?<leadingDot>\.)/, '*')
.match(/^(?<hostname>.+?)(?::(?<port>\d+))?$/);
if (!ruleMatch || !ruleMatch.groups) {
throw new Error('Invalid NO_PROXY pattern.');
}
if (!ruleMatch.groups.hostname) {
throw new Error('NO_PROXY entry pattern must include hostname. Use * to match any hostname.');
}
const hostnameIsMatch = (0, matcher_1.isMatch)(subjectUrlTokens.hostname, ruleMatch.groups.hostname);
if (hostnameIsMatch &&
(!ruleMatch.groups ||
!ruleMatch.groups.port ||
(subjectUrlTokens.port &&
subjectUrlTokens.port === ruleMatch.groups.port))) {
return true;
}
}
return false;
};
exports.matchesNoProxy = matchesNoProxy;
//# sourceMappingURL=util.js.map