|
|
|
@@ -81,6 +81,373 @@ function wrappy (fn, cb) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 13:
|
|
|
|
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
const assert = __webpack_require__(357)
|
|
|
|
|
const path = __webpack_require__(622)
|
|
|
|
|
const fs = __webpack_require__(747)
|
|
|
|
|
let glob = undefined
|
|
|
|
|
try {
|
|
|
|
|
glob = __webpack_require__(402)
|
|
|
|
|
} catch (_err) {
|
|
|
|
|
// treat glob as optional.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const defaultGlobOpts = {
|
|
|
|
|
nosort: true,
|
|
|
|
|
silent: true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// for EMFILE handling
|
|
|
|
|
let timeout = 0
|
|
|
|
|
|
|
|
|
|
const isWindows = (process.platform === "win32")
|
|
|
|
|
|
|
|
|
|
const defaults = options => {
|
|
|
|
|
const methods = [
|
|
|
|
|
'unlink',
|
|
|
|
|
'chmod',
|
|
|
|
|
'stat',
|
|
|
|
|
'lstat',
|
|
|
|
|
'rmdir',
|
|
|
|
|
'readdir'
|
|
|
|
|
]
|
|
|
|
|
methods.forEach(m => {
|
|
|
|
|
options[m] = options[m] || fs[m]
|
|
|
|
|
m = m + 'Sync'
|
|
|
|
|
options[m] = options[m] || fs[m]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
options.maxBusyTries = options.maxBusyTries || 3
|
|
|
|
|
options.emfileWait = options.emfileWait || 1000
|
|
|
|
|
if (options.glob === false) {
|
|
|
|
|
options.disableGlob = true
|
|
|
|
|
}
|
|
|
|
|
if (options.disableGlob !== true && glob === undefined) {
|
|
|
|
|
throw Error('glob dependency not found, set `options.disableGlob = true` if intentional')
|
|
|
|
|
}
|
|
|
|
|
options.disableGlob = options.disableGlob || false
|
|
|
|
|
options.glob = options.glob || defaultGlobOpts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const rimraf = (p, options, cb) => {
|
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
|
cb = options
|
|
|
|
|
options = {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(p, 'rimraf: missing path')
|
|
|
|
|
assert.equal(typeof p, 'string', 'rimraf: path should be a string')
|
|
|
|
|
assert.equal(typeof cb, 'function', 'rimraf: callback function required')
|
|
|
|
|
assert(options, 'rimraf: invalid options argument provided')
|
|
|
|
|
assert.equal(typeof options, 'object', 'rimraf: options should be object')
|
|
|
|
|
|
|
|
|
|
defaults(options)
|
|
|
|
|
|
|
|
|
|
let busyTries = 0
|
|
|
|
|
let errState = null
|
|
|
|
|
let n = 0
|
|
|
|
|
|
|
|
|
|
const next = (er) => {
|
|
|
|
|
errState = errState || er
|
|
|
|
|
if (--n === 0)
|
|
|
|
|
cb(errState)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const afterGlob = (er, results) => {
|
|
|
|
|
if (er)
|
|
|
|
|
return cb(er)
|
|
|
|
|
|
|
|
|
|
n = results.length
|
|
|
|
|
if (n === 0)
|
|
|
|
|
return cb()
|
|
|
|
|
|
|
|
|
|
results.forEach(p => {
|
|
|
|
|
const CB = (er) => {
|
|
|
|
|
if (er) {
|
|
|
|
|
if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") &&
|
|
|
|
|
busyTries < options.maxBusyTries) {
|
|
|
|
|
busyTries ++
|
|
|
|
|
// try again, with the same exact callback as this one.
|
|
|
|
|
return setTimeout(() => rimraf_(p, options, CB), busyTries * 100)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this one won't happen if graceful-fs is used.
|
|
|
|
|
if (er.code === "EMFILE" && timeout < options.emfileWait) {
|
|
|
|
|
return setTimeout(() => rimraf_(p, options, CB), timeout ++)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// already gone
|
|
|
|
|
if (er.code === "ENOENT") er = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timeout = 0
|
|
|
|
|
next(er)
|
|
|
|
|
}
|
|
|
|
|
rimraf_(p, options, CB)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.disableGlob || !glob.hasMagic(p))
|
|
|
|
|
return afterGlob(null, [p])
|
|
|
|
|
|
|
|
|
|
options.lstat(p, (er, stat) => {
|
|
|
|
|
if (!er)
|
|
|
|
|
return afterGlob(null, [p])
|
|
|
|
|
|
|
|
|
|
glob(p, options.glob, afterGlob)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Two possible strategies.
|
|
|
|
|
// 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
|
|
|
|
|
// 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
|
|
|
|
|
//
|
|
|
|
|
// Both result in an extra syscall when you guess wrong. However, there
|
|
|
|
|
// are likely far more normal files in the world than directories. This
|
|
|
|
|
// is based on the assumption that a the average number of files per
|
|
|
|
|
// directory is >= 1.
|
|
|
|
|
//
|
|
|
|
|
// If anyone ever complains about this, then I guess the strategy could
|
|
|
|
|
// be made configurable somehow. But until then, YAGNI.
|
|
|
|
|
const rimraf_ = (p, options, cb) => {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
assert(typeof cb === 'function')
|
|
|
|
|
|
|
|
|
|
// sunos lets the root user unlink directories, which is... weird.
|
|
|
|
|
// so we have to lstat here and make sure it's not a dir.
|
|
|
|
|
options.lstat(p, (er, st) => {
|
|
|
|
|
if (er && er.code === "ENOENT")
|
|
|
|
|
return cb(null)
|
|
|
|
|
|
|
|
|
|
// Windows can EPERM on stat. Life is suffering.
|
|
|
|
|
if (er && er.code === "EPERM" && isWindows)
|
|
|
|
|
fixWinEPERM(p, options, er, cb)
|
|
|
|
|
|
|
|
|
|
if (st && st.isDirectory())
|
|
|
|
|
return rmdir(p, options, er, cb)
|
|
|
|
|
|
|
|
|
|
options.unlink(p, er => {
|
|
|
|
|
if (er) {
|
|
|
|
|
if (er.code === "ENOENT")
|
|
|
|
|
return cb(null)
|
|
|
|
|
if (er.code === "EPERM")
|
|
|
|
|
return (isWindows)
|
|
|
|
|
? fixWinEPERM(p, options, er, cb)
|
|
|
|
|
: rmdir(p, options, er, cb)
|
|
|
|
|
if (er.code === "EISDIR")
|
|
|
|
|
return rmdir(p, options, er, cb)
|
|
|
|
|
}
|
|
|
|
|
return cb(er)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fixWinEPERM = (p, options, er, cb) => {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
assert(typeof cb === 'function')
|
|
|
|
|
|
|
|
|
|
options.chmod(p, 0o666, er2 => {
|
|
|
|
|
if (er2)
|
|
|
|
|
cb(er2.code === "ENOENT" ? null : er)
|
|
|
|
|
else
|
|
|
|
|
options.stat(p, (er3, stats) => {
|
|
|
|
|
if (er3)
|
|
|
|
|
cb(er3.code === "ENOENT" ? null : er)
|
|
|
|
|
else if (stats.isDirectory())
|
|
|
|
|
rmdir(p, options, er, cb)
|
|
|
|
|
else
|
|
|
|
|
options.unlink(p, cb)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const fixWinEPERMSync = (p, options, er) => {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
options.chmodSync(p, 0o666)
|
|
|
|
|
} catch (er2) {
|
|
|
|
|
if (er2.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
throw er
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let stats
|
|
|
|
|
try {
|
|
|
|
|
stats = options.statSync(p)
|
|
|
|
|
} catch (er3) {
|
|
|
|
|
if (er3.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
throw er
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stats.isDirectory())
|
|
|
|
|
rmdirSync(p, options, er)
|
|
|
|
|
else
|
|
|
|
|
options.unlinkSync(p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const rmdir = (p, options, originalEr, cb) => {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
assert(typeof cb === 'function')
|
|
|
|
|
|
|
|
|
|
// try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
|
|
|
|
|
// if we guessed wrong, and it's not a directory, then
|
|
|
|
|
// raise the original error.
|
|
|
|
|
options.rmdir(p, er => {
|
|
|
|
|
if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM"))
|
|
|
|
|
rmkids(p, options, cb)
|
|
|
|
|
else if (er && er.code === "ENOTDIR")
|
|
|
|
|
cb(originalEr)
|
|
|
|
|
else
|
|
|
|
|
cb(er)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const rmkids = (p, options, cb) => {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
assert(typeof cb === 'function')
|
|
|
|
|
|
|
|
|
|
options.readdir(p, (er, files) => {
|
|
|
|
|
if (er)
|
|
|
|
|
return cb(er)
|
|
|
|
|
let n = files.length
|
|
|
|
|
if (n === 0)
|
|
|
|
|
return options.rmdir(p, cb)
|
|
|
|
|
let errState
|
|
|
|
|
files.forEach(f => {
|
|
|
|
|
rimraf(path.join(p, f), options, er => {
|
|
|
|
|
if (errState)
|
|
|
|
|
return
|
|
|
|
|
if (er)
|
|
|
|
|
return cb(errState = er)
|
|
|
|
|
if (--n === 0)
|
|
|
|
|
options.rmdir(p, cb)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this looks simpler, and is strictly *faster*, but will
|
|
|
|
|
// tie up the JavaScript thread and fail on excessively
|
|
|
|
|
// deep directory trees.
|
|
|
|
|
const rimrafSync = (p, options) => {
|
|
|
|
|
options = options || {}
|
|
|
|
|
defaults(options)
|
|
|
|
|
|
|
|
|
|
assert(p, 'rimraf: missing path')
|
|
|
|
|
assert.equal(typeof p, 'string', 'rimraf: path should be a string')
|
|
|
|
|
assert(options, 'rimraf: missing options')
|
|
|
|
|
assert.equal(typeof options, 'object', 'rimraf: options should be object')
|
|
|
|
|
|
|
|
|
|
let results
|
|
|
|
|
|
|
|
|
|
if (options.disableGlob || !glob.hasMagic(p)) {
|
|
|
|
|
results = [p]
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
options.lstatSync(p)
|
|
|
|
|
results = [p]
|
|
|
|
|
} catch (er) {
|
|
|
|
|
results = glob.sync(p, options.glob)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!results.length)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
for (let i = 0; i < results.length; i++) {
|
|
|
|
|
const p = results[i]
|
|
|
|
|
|
|
|
|
|
let st
|
|
|
|
|
try {
|
|
|
|
|
st = options.lstatSync(p)
|
|
|
|
|
} catch (er) {
|
|
|
|
|
if (er.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
// Windows can EPERM on stat. Life is suffering.
|
|
|
|
|
if (er.code === "EPERM" && isWindows)
|
|
|
|
|
fixWinEPERMSync(p, options, er)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// sunos lets the root user unlink directories, which is... weird.
|
|
|
|
|
if (st && st.isDirectory())
|
|
|
|
|
rmdirSync(p, options, null)
|
|
|
|
|
else
|
|
|
|
|
options.unlinkSync(p)
|
|
|
|
|
} catch (er) {
|
|
|
|
|
if (er.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
if (er.code === "EPERM")
|
|
|
|
|
return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
|
|
|
|
|
if (er.code !== "EISDIR")
|
|
|
|
|
throw er
|
|
|
|
|
|
|
|
|
|
rmdirSync(p, options, er)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const rmdirSync = (p, options, originalEr) => {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
options.rmdirSync(p)
|
|
|
|
|
} catch (er) {
|
|
|
|
|
if (er.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
if (er.code === "ENOTDIR")
|
|
|
|
|
throw originalEr
|
|
|
|
|
if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")
|
|
|
|
|
rmkidsSync(p, options)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const rmkidsSync = (p, options) => {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
options.readdirSync(p).forEach(f => rimrafSync(path.join(p, f), options))
|
|
|
|
|
|
|
|
|
|
// We only end up here once we got ENOTEMPTY at least once, and
|
|
|
|
|
// at this point, we are guaranteed to have removed all the kids.
|
|
|
|
|
// So, we know that it won't be ENOENT or ENOTDIR or anything else.
|
|
|
|
|
// try really hard to delete stuff on windows, because it has a
|
|
|
|
|
// PROFOUNDLY annoying habit of not closing handles promptly when
|
|
|
|
|
// files are deleted, resulting in spurious ENOTEMPTY errors.
|
|
|
|
|
const retries = isWindows ? 100 : 1
|
|
|
|
|
let i = 0
|
|
|
|
|
do {
|
|
|
|
|
let threw = true
|
|
|
|
|
try {
|
|
|
|
|
const ret = options.rmdirSync(p, options)
|
|
|
|
|
threw = false
|
|
|
|
|
return ret
|
|
|
|
|
} finally {
|
|
|
|
|
if (++i < retries && threw)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
} while (true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = rimraf
|
|
|
|
|
rimraf.sync = rimrafSync
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 16:
|
|
|
|
@@ -1138,6 +1505,316 @@ exports.issueCommand = issueCommand;
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 112:
|
|
|
|
|
/***/ (function(__unusedmodule, exports) {
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CRC64: cyclic redundancy check, 64-bits
|
|
|
|
|
*
|
|
|
|
|
* In order to validate that artifacts are not being corrupted over the wire, this redundancy check allows us to
|
|
|
|
|
* validate that there was no corruption during transmission. The implementation here is based on Go's hash/crc64 pkg,
|
|
|
|
|
* but without the slicing-by-8 optimization: https://cs.opensource.google/go/go/+/master:src/hash/crc64/crc64.go
|
|
|
|
|
*
|
|
|
|
|
* This implementation uses a pregenerated table based on 0x9A6C9329AC4BC9B5 as the polynomial, the same polynomial that
|
|
|
|
|
* is used for Azure Storage: https://github.com/Azure/azure-storage-net/blob/cbe605f9faa01bfc3003d75fc5a16b2eaccfe102/Lib/Common/Core/Util/Crc64.cs#L27
|
|
|
|
|
*/
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
// when transpile target is >= ES2020 (after dropping node 12) these can be changed to bigint literals - ts(2737)
|
|
|
|
|
const PREGEN_POLY_TABLE = [
|
|
|
|
|
BigInt('0x0000000000000000'),
|
|
|
|
|
BigInt('0x7F6EF0C830358979'),
|
|
|
|
|
BigInt('0xFEDDE190606B12F2'),
|
|
|
|
|
BigInt('0x81B31158505E9B8B'),
|
|
|
|
|
BigInt('0xC962E5739841B68F'),
|
|
|
|
|
BigInt('0xB60C15BBA8743FF6'),
|
|
|
|
|
BigInt('0x37BF04E3F82AA47D'),
|
|
|
|
|
BigInt('0x48D1F42BC81F2D04'),
|
|
|
|
|
BigInt('0xA61CECB46814FE75'),
|
|
|
|
|
BigInt('0xD9721C7C5821770C'),
|
|
|
|
|
BigInt('0x58C10D24087FEC87'),
|
|
|
|
|
BigInt('0x27AFFDEC384A65FE'),
|
|
|
|
|
BigInt('0x6F7E09C7F05548FA'),
|
|
|
|
|
BigInt('0x1010F90FC060C183'),
|
|
|
|
|
BigInt('0x91A3E857903E5A08'),
|
|
|
|
|
BigInt('0xEECD189FA00BD371'),
|
|
|
|
|
BigInt('0x78E0FF3B88BE6F81'),
|
|
|
|
|
BigInt('0x078E0FF3B88BE6F8'),
|
|
|
|
|
BigInt('0x863D1EABE8D57D73'),
|
|
|
|
|
BigInt('0xF953EE63D8E0F40A'),
|
|
|
|
|
BigInt('0xB1821A4810FFD90E'),
|
|
|
|
|
BigInt('0xCEECEA8020CA5077'),
|
|
|
|
|
BigInt('0x4F5FFBD87094CBFC'),
|
|
|
|
|
BigInt('0x30310B1040A14285'),
|
|
|
|
|
BigInt('0xDEFC138FE0AA91F4'),
|
|
|
|
|
BigInt('0xA192E347D09F188D'),
|
|
|
|
|
BigInt('0x2021F21F80C18306'),
|
|
|
|
|
BigInt('0x5F4F02D7B0F40A7F'),
|
|
|
|
|
BigInt('0x179EF6FC78EB277B'),
|
|
|
|
|
BigInt('0x68F0063448DEAE02'),
|
|
|
|
|
BigInt('0xE943176C18803589'),
|
|
|
|
|
BigInt('0x962DE7A428B5BCF0'),
|
|
|
|
|
BigInt('0xF1C1FE77117CDF02'),
|
|
|
|
|
BigInt('0x8EAF0EBF2149567B'),
|
|
|
|
|
BigInt('0x0F1C1FE77117CDF0'),
|
|
|
|
|
BigInt('0x7072EF2F41224489'),
|
|
|
|
|
BigInt('0x38A31B04893D698D'),
|
|
|
|
|
BigInt('0x47CDEBCCB908E0F4'),
|
|
|
|
|
BigInt('0xC67EFA94E9567B7F'),
|
|
|
|
|
BigInt('0xB9100A5CD963F206'),
|
|
|
|
|
BigInt('0x57DD12C379682177'),
|
|
|
|
|
BigInt('0x28B3E20B495DA80E'),
|
|
|
|
|
BigInt('0xA900F35319033385'),
|
|
|
|
|
BigInt('0xD66E039B2936BAFC'),
|
|
|
|
|
BigInt('0x9EBFF7B0E12997F8'),
|
|
|
|
|
BigInt('0xE1D10778D11C1E81'),
|
|
|
|
|
BigInt('0x606216208142850A'),
|
|
|
|
|
BigInt('0x1F0CE6E8B1770C73'),
|
|
|
|
|
BigInt('0x8921014C99C2B083'),
|
|
|
|
|
BigInt('0xF64FF184A9F739FA'),
|
|
|
|
|
BigInt('0x77FCE0DCF9A9A271'),
|
|
|
|
|
BigInt('0x08921014C99C2B08'),
|
|
|
|
|
BigInt('0x4043E43F0183060C'),
|
|
|
|
|
BigInt('0x3F2D14F731B68F75'),
|
|
|
|
|
BigInt('0xBE9E05AF61E814FE'),
|
|
|
|
|
BigInt('0xC1F0F56751DD9D87'),
|
|
|
|
|
BigInt('0x2F3DEDF8F1D64EF6'),
|
|
|
|
|
BigInt('0x50531D30C1E3C78F'),
|
|
|
|
|
BigInt('0xD1E00C6891BD5C04'),
|
|
|
|
|
BigInt('0xAE8EFCA0A188D57D'),
|
|
|
|
|
BigInt('0xE65F088B6997F879'),
|
|
|
|
|
BigInt('0x9931F84359A27100'),
|
|
|
|
|
BigInt('0x1882E91B09FCEA8B'),
|
|
|
|
|
BigInt('0x67EC19D339C963F2'),
|
|
|
|
|
BigInt('0xD75ADABD7A6E2D6F'),
|
|
|
|
|
BigInt('0xA8342A754A5BA416'),
|
|
|
|
|
BigInt('0x29873B2D1A053F9D'),
|
|
|
|
|
BigInt('0x56E9CBE52A30B6E4'),
|
|
|
|
|
BigInt('0x1E383FCEE22F9BE0'),
|
|
|
|
|
BigInt('0x6156CF06D21A1299'),
|
|
|
|
|
BigInt('0xE0E5DE5E82448912'),
|
|
|
|
|
BigInt('0x9F8B2E96B271006B'),
|
|
|
|
|
BigInt('0x71463609127AD31A'),
|
|
|
|
|
BigInt('0x0E28C6C1224F5A63'),
|
|
|
|
|
BigInt('0x8F9BD7997211C1E8'),
|
|
|
|
|
BigInt('0xF0F5275142244891'),
|
|
|
|
|
BigInt('0xB824D37A8A3B6595'),
|
|
|
|
|
BigInt('0xC74A23B2BA0EECEC'),
|
|
|
|
|
BigInt('0x46F932EAEA507767'),
|
|
|
|
|
BigInt('0x3997C222DA65FE1E'),
|
|
|
|
|
BigInt('0xAFBA2586F2D042EE'),
|
|
|
|
|
BigInt('0xD0D4D54EC2E5CB97'),
|
|
|
|
|
BigInt('0x5167C41692BB501C'),
|
|
|
|
|
BigInt('0x2E0934DEA28ED965'),
|
|
|
|
|
BigInt('0x66D8C0F56A91F461'),
|
|
|
|
|
BigInt('0x19B6303D5AA47D18'),
|
|
|
|
|
BigInt('0x980521650AFAE693'),
|
|
|
|
|
BigInt('0xE76BD1AD3ACF6FEA'),
|
|
|
|
|
BigInt('0x09A6C9329AC4BC9B'),
|
|
|
|
|
BigInt('0x76C839FAAAF135E2'),
|
|
|
|
|
BigInt('0xF77B28A2FAAFAE69'),
|
|
|
|
|
BigInt('0x8815D86ACA9A2710'),
|
|
|
|
|
BigInt('0xC0C42C4102850A14'),
|
|
|
|
|
BigInt('0xBFAADC8932B0836D'),
|
|
|
|
|
BigInt('0x3E19CDD162EE18E6'),
|
|
|
|
|
BigInt('0x41773D1952DB919F'),
|
|
|
|
|
BigInt('0x269B24CA6B12F26D'),
|
|
|
|
|
BigInt('0x59F5D4025B277B14'),
|
|
|
|
|
BigInt('0xD846C55A0B79E09F'),
|
|
|
|
|
BigInt('0xA72835923B4C69E6'),
|
|
|
|
|
BigInt('0xEFF9C1B9F35344E2'),
|
|
|
|
|
BigInt('0x90973171C366CD9B'),
|
|
|
|
|
BigInt('0x1124202993385610'),
|
|
|
|
|
BigInt('0x6E4AD0E1A30DDF69'),
|
|
|
|
|
BigInt('0x8087C87E03060C18'),
|
|
|
|
|
BigInt('0xFFE938B633338561'),
|
|
|
|
|
BigInt('0x7E5A29EE636D1EEA'),
|
|
|
|
|
BigInt('0x0134D92653589793'),
|
|
|
|
|
BigInt('0x49E52D0D9B47BA97'),
|
|
|
|
|
BigInt('0x368BDDC5AB7233EE'),
|
|
|
|
|
BigInt('0xB738CC9DFB2CA865'),
|
|
|
|
|
BigInt('0xC8563C55CB19211C'),
|
|
|
|
|
BigInt('0x5E7BDBF1E3AC9DEC'),
|
|
|
|
|
BigInt('0x21152B39D3991495'),
|
|
|
|
|
BigInt('0xA0A63A6183C78F1E'),
|
|
|
|
|
BigInt('0xDFC8CAA9B3F20667'),
|
|
|
|
|
BigInt('0x97193E827BED2B63'),
|
|
|
|
|
BigInt('0xE877CE4A4BD8A21A'),
|
|
|
|
|
BigInt('0x69C4DF121B863991'),
|
|
|
|
|
BigInt('0x16AA2FDA2BB3B0E8'),
|
|
|
|
|
BigInt('0xF86737458BB86399'),
|
|
|
|
|
BigInt('0x8709C78DBB8DEAE0'),
|
|
|
|
|
BigInt('0x06BAD6D5EBD3716B'),
|
|
|
|
|
BigInt('0x79D4261DDBE6F812'),
|
|
|
|
|
BigInt('0x3105D23613F9D516'),
|
|
|
|
|
BigInt('0x4E6B22FE23CC5C6F'),
|
|
|
|
|
BigInt('0xCFD833A67392C7E4'),
|
|
|
|
|
BigInt('0xB0B6C36E43A74E9D'),
|
|
|
|
|
BigInt('0x9A6C9329AC4BC9B5'),
|
|
|
|
|
BigInt('0xE50263E19C7E40CC'),
|
|
|
|
|
BigInt('0x64B172B9CC20DB47'),
|
|
|
|
|
BigInt('0x1BDF8271FC15523E'),
|
|
|
|
|
BigInt('0x530E765A340A7F3A'),
|
|
|
|
|
BigInt('0x2C608692043FF643'),
|
|
|
|
|
BigInt('0xADD397CA54616DC8'),
|
|
|
|
|
BigInt('0xD2BD67026454E4B1'),
|
|
|
|
|
BigInt('0x3C707F9DC45F37C0'),
|
|
|
|
|
BigInt('0x431E8F55F46ABEB9'),
|
|
|
|
|
BigInt('0xC2AD9E0DA4342532'),
|
|
|
|
|
BigInt('0xBDC36EC59401AC4B'),
|
|
|
|
|
BigInt('0xF5129AEE5C1E814F'),
|
|
|
|
|
BigInt('0x8A7C6A266C2B0836'),
|
|
|
|
|
BigInt('0x0BCF7B7E3C7593BD'),
|
|
|
|
|
BigInt('0x74A18BB60C401AC4'),
|
|
|
|
|
BigInt('0xE28C6C1224F5A634'),
|
|
|
|
|
BigInt('0x9DE29CDA14C02F4D'),
|
|
|
|
|
BigInt('0x1C518D82449EB4C6'),
|
|
|
|
|
BigInt('0x633F7D4A74AB3DBF'),
|
|
|
|
|
BigInt('0x2BEE8961BCB410BB'),
|
|
|
|
|
BigInt('0x548079A98C8199C2'),
|
|
|
|
|
BigInt('0xD53368F1DCDF0249'),
|
|
|
|
|
BigInt('0xAA5D9839ECEA8B30'),
|
|
|
|
|
BigInt('0x449080A64CE15841'),
|
|
|
|
|
BigInt('0x3BFE706E7CD4D138'),
|
|
|
|
|
BigInt('0xBA4D61362C8A4AB3'),
|
|
|
|
|
BigInt('0xC52391FE1CBFC3CA'),
|
|
|
|
|
BigInt('0x8DF265D5D4A0EECE'),
|
|
|
|
|
BigInt('0xF29C951DE49567B7'),
|
|
|
|
|
BigInt('0x732F8445B4CBFC3C'),
|
|
|
|
|
BigInt('0x0C41748D84FE7545'),
|
|
|
|
|
BigInt('0x6BAD6D5EBD3716B7'),
|
|
|
|
|
BigInt('0x14C39D968D029FCE'),
|
|
|
|
|
BigInt('0x95708CCEDD5C0445'),
|
|
|
|
|
BigInt('0xEA1E7C06ED698D3C'),
|
|
|
|
|
BigInt('0xA2CF882D2576A038'),
|
|
|
|
|
BigInt('0xDDA178E515432941'),
|
|
|
|
|
BigInt('0x5C1269BD451DB2CA'),
|
|
|
|
|
BigInt('0x237C997575283BB3'),
|
|
|
|
|
BigInt('0xCDB181EAD523E8C2'),
|
|
|
|
|
BigInt('0xB2DF7122E51661BB'),
|
|
|
|
|
BigInt('0x336C607AB548FA30'),
|
|
|
|
|
BigInt('0x4C0290B2857D7349'),
|
|
|
|
|
BigInt('0x04D364994D625E4D'),
|
|
|
|
|
BigInt('0x7BBD94517D57D734'),
|
|
|
|
|
BigInt('0xFA0E85092D094CBF'),
|
|
|
|
|
BigInt('0x856075C11D3CC5C6'),
|
|
|
|
|
BigInt('0x134D926535897936'),
|
|
|
|
|
BigInt('0x6C2362AD05BCF04F'),
|
|
|
|
|
BigInt('0xED9073F555E26BC4'),
|
|
|
|
|
BigInt('0x92FE833D65D7E2BD'),
|
|
|
|
|
BigInt('0xDA2F7716ADC8CFB9'),
|
|
|
|
|
BigInt('0xA54187DE9DFD46C0'),
|
|
|
|
|
BigInt('0x24F29686CDA3DD4B'),
|
|
|
|
|
BigInt('0x5B9C664EFD965432'),
|
|
|
|
|
BigInt('0xB5517ED15D9D8743'),
|
|
|
|
|
BigInt('0xCA3F8E196DA80E3A'),
|
|
|
|
|
BigInt('0x4B8C9F413DF695B1'),
|
|
|
|
|
BigInt('0x34E26F890DC31CC8'),
|
|
|
|
|
BigInt('0x7C339BA2C5DC31CC'),
|
|
|
|
|
BigInt('0x035D6B6AF5E9B8B5'),
|
|
|
|
|
BigInt('0x82EE7A32A5B7233E'),
|
|
|
|
|
BigInt('0xFD808AFA9582AA47'),
|
|
|
|
|
BigInt('0x4D364994D625E4DA'),
|
|
|
|
|
BigInt('0x3258B95CE6106DA3'),
|
|
|
|
|
BigInt('0xB3EBA804B64EF628'),
|
|
|
|
|
BigInt('0xCC8558CC867B7F51'),
|
|
|
|
|
BigInt('0x8454ACE74E645255'),
|
|
|
|
|
BigInt('0xFB3A5C2F7E51DB2C'),
|
|
|
|
|
BigInt('0x7A894D772E0F40A7'),
|
|
|
|
|
BigInt('0x05E7BDBF1E3AC9DE'),
|
|
|
|
|
BigInt('0xEB2AA520BE311AAF'),
|
|
|
|
|
BigInt('0x944455E88E0493D6'),
|
|
|
|
|
BigInt('0x15F744B0DE5A085D'),
|
|
|
|
|
BigInt('0x6A99B478EE6F8124'),
|
|
|
|
|
BigInt('0x224840532670AC20'),
|
|
|
|
|
BigInt('0x5D26B09B16452559'),
|
|
|
|
|
BigInt('0xDC95A1C3461BBED2'),
|
|
|
|
|
BigInt('0xA3FB510B762E37AB'),
|
|
|
|
|
BigInt('0x35D6B6AF5E9B8B5B'),
|
|
|
|
|
BigInt('0x4AB846676EAE0222'),
|
|
|
|
|
BigInt('0xCB0B573F3EF099A9'),
|
|
|
|
|
BigInt('0xB465A7F70EC510D0'),
|
|
|
|
|
BigInt('0xFCB453DCC6DA3DD4'),
|
|
|
|
|
BigInt('0x83DAA314F6EFB4AD'),
|
|
|
|
|
BigInt('0x0269B24CA6B12F26'),
|
|
|
|
|
BigInt('0x7D0742849684A65F'),
|
|
|
|
|
BigInt('0x93CA5A1B368F752E'),
|
|
|
|
|
BigInt('0xECA4AAD306BAFC57'),
|
|
|
|
|
BigInt('0x6D17BB8B56E467DC'),
|
|
|
|
|
BigInt('0x12794B4366D1EEA5'),
|
|
|
|
|
BigInt('0x5AA8BF68AECEC3A1'),
|
|
|
|
|
BigInt('0x25C64FA09EFB4AD8'),
|
|
|
|
|
BigInt('0xA4755EF8CEA5D153'),
|
|
|
|
|
BigInt('0xDB1BAE30FE90582A'),
|
|
|
|
|
BigInt('0xBCF7B7E3C7593BD8'),
|
|
|
|
|
BigInt('0xC399472BF76CB2A1'),
|
|
|
|
|
BigInt('0x422A5673A732292A'),
|
|
|
|
|
BigInt('0x3D44A6BB9707A053'),
|
|
|
|
|
BigInt('0x759552905F188D57'),
|
|
|
|
|
BigInt('0x0AFBA2586F2D042E'),
|
|
|
|
|
BigInt('0x8B48B3003F739FA5'),
|
|
|
|
|
BigInt('0xF42643C80F4616DC'),
|
|
|
|
|
BigInt('0x1AEB5B57AF4DC5AD'),
|
|
|
|
|
BigInt('0x6585AB9F9F784CD4'),
|
|
|
|
|
BigInt('0xE436BAC7CF26D75F'),
|
|
|
|
|
BigInt('0x9B584A0FFF135E26'),
|
|
|
|
|
BigInt('0xD389BE24370C7322'),
|
|
|
|
|
BigInt('0xACE74EEC0739FA5B'),
|
|
|
|
|
BigInt('0x2D545FB4576761D0'),
|
|
|
|
|
BigInt('0x523AAF7C6752E8A9'),
|
|
|
|
|
BigInt('0xC41748D84FE75459'),
|
|
|
|
|
BigInt('0xBB79B8107FD2DD20'),
|
|
|
|
|
BigInt('0x3ACAA9482F8C46AB'),
|
|
|
|
|
BigInt('0x45A459801FB9CFD2'),
|
|
|
|
|
BigInt('0x0D75ADABD7A6E2D6'),
|
|
|
|
|
BigInt('0x721B5D63E7936BAF'),
|
|
|
|
|
BigInt('0xF3A84C3BB7CDF024'),
|
|
|
|
|
BigInt('0x8CC6BCF387F8795D'),
|
|
|
|
|
BigInt('0x620BA46C27F3AA2C'),
|
|
|
|
|
BigInt('0x1D6554A417C62355'),
|
|
|
|
|
BigInt('0x9CD645FC4798B8DE'),
|
|
|
|
|
BigInt('0xE3B8B53477AD31A7'),
|
|
|
|
|
BigInt('0xAB69411FBFB21CA3'),
|
|
|
|
|
BigInt('0xD407B1D78F8795DA'),
|
|
|
|
|
BigInt('0x55B4A08FDFD90E51'),
|
|
|
|
|
BigInt('0x2ADA5047EFEC8728')
|
|
|
|
|
];
|
|
|
|
|
class CRC64 {
|
|
|
|
|
constructor() {
|
|
|
|
|
this._crc = BigInt(0);
|
|
|
|
|
}
|
|
|
|
|
update(data) {
|
|
|
|
|
const buffer = typeof data === 'string' ? Buffer.from(data) : data;
|
|
|
|
|
let crc = CRC64.flip64Bits(this._crc);
|
|
|
|
|
for (const dataByte of buffer) {
|
|
|
|
|
const crcByte = Number(crc & BigInt(0xff));
|
|
|
|
|
crc = PREGEN_POLY_TABLE[crcByte ^ dataByte] ^ (crc >> BigInt(8));
|
|
|
|
|
}
|
|
|
|
|
this._crc = CRC64.flip64Bits(crc);
|
|
|
|
|
}
|
|
|
|
|
digest(encoding) {
|
|
|
|
|
switch (encoding) {
|
|
|
|
|
case 'hex':
|
|
|
|
|
return this._crc.toString(16).toUpperCase();
|
|
|
|
|
case 'base64':
|
|
|
|
|
return this.toBuffer().toString('base64');
|
|
|
|
|
default:
|
|
|
|
|
return this.toBuffer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
toBuffer() {
|
|
|
|
|
return Buffer.from([0, 8, 16, 24, 32, 40, 48, 56].map(s => Number((this._crc >> BigInt(s)) & BigInt(0xff))));
|
|
|
|
|
}
|
|
|
|
|
static flip64Bits(n) {
|
|
|
|
|
return (BigInt(1) << BigInt(64)) - BigInt(1) - n;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.default = CRC64;
|
|
|
|
|
//# sourceMappingURL=crc64.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 117:
|
|
|
|
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
@@ -1738,10 +2415,8 @@ const fs = __webpack_require__(747);
|
|
|
|
|
const os = __webpack_require__(87);
|
|
|
|
|
const path = __webpack_require__(622);
|
|
|
|
|
const crypto = __webpack_require__(417);
|
|
|
|
|
const _c = fs.constants && os.constants ?
|
|
|
|
|
{ fs: fs.constants, os: os.constants } :
|
|
|
|
|
process.binding('constants');
|
|
|
|
|
const rimraf = __webpack_require__(569);
|
|
|
|
|
const _c = { fs: fs.constants, os: os.constants };
|
|
|
|
|
const rimraf = __webpack_require__(13);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The working inner variables.
|
|
|
|
@@ -1756,128 +2431,26 @@ const
|
|
|
|
|
|
|
|
|
|
CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),
|
|
|
|
|
|
|
|
|
|
// constants are off on the windows platform and will not match the actual errno codes
|
|
|
|
|
IS_WIN32 = os.platform() === 'win32',
|
|
|
|
|
EBADF = _c.EBADF || _c.os.errno.EBADF,
|
|
|
|
|
ENOENT = _c.ENOENT || _c.os.errno.ENOENT,
|
|
|
|
|
|
|
|
|
|
DIR_MODE = 448 /* 0o700 */,
|
|
|
|
|
FILE_MODE = 384 /* 0o600 */,
|
|
|
|
|
DIR_MODE = 0o700 /* 448 */,
|
|
|
|
|
FILE_MODE = 0o600 /* 384 */,
|
|
|
|
|
|
|
|
|
|
EXIT = 'exit',
|
|
|
|
|
|
|
|
|
|
SIGINT = 'SIGINT',
|
|
|
|
|
|
|
|
|
|
// this will hold the objects need to be removed on exit
|
|
|
|
|
_removeObjects = [];
|
|
|
|
|
_removeObjects = [],
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
// API change in fs.rmdirSync leads to error when passing in a second parameter, e.g. the callback
|
|
|
|
|
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs),
|
|
|
|
|
FN_RIMRAF_SYNC = rimraf.sync;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
_gracefulCleanup = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Random name generator based on crypto.
|
|
|
|
|
* Adapted from http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
|
|
|
|
|
*
|
|
|
|
|
* @param {number} howMany
|
|
|
|
|
* @returns {string} the generated random name
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _randomChars(howMany) {
|
|
|
|
|
var
|
|
|
|
|
value = [],
|
|
|
|
|
rnd = null;
|
|
|
|
|
|
|
|
|
|
// make sure that we do not fail because we ran out of entropy
|
|
|
|
|
try {
|
|
|
|
|
rnd = crypto.randomBytes(howMany);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
rnd = crypto.pseudoRandomBytes(howMany);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < howMany; i++) {
|
|
|
|
|
value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value.join('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether the `obj` parameter is defined or not.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} obj
|
|
|
|
|
* @returns {boolean} true if the object is undefined
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _isUndefined(obj) {
|
|
|
|
|
return typeof obj === 'undefined';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parses the function arguments.
|
|
|
|
|
*
|
|
|
|
|
* This function helps to have optional arguments.
|
|
|
|
|
*
|
|
|
|
|
* @param {(Options|Function)} options
|
|
|
|
|
* @param {Function} callback
|
|
|
|
|
* @returns {Array} parsed arguments
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _parseArguments(options, callback) {
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
|
return [{}, options];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (_isUndefined(options)) {
|
|
|
|
|
return [{}, callback];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [options, callback];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates a new temporary name.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} opts
|
|
|
|
|
* @returns {string} the new random name according to opts
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _generateTmpName(opts) {
|
|
|
|
|
|
|
|
|
|
const tmpDir = _getTmpDir();
|
|
|
|
|
|
|
|
|
|
// fail early on missing tmp dir
|
|
|
|
|
if (isBlank(opts.dir) && isBlank(tmpDir)) {
|
|
|
|
|
throw new Error('No tmp dir specified');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (!isBlank(opts.name)) {
|
|
|
|
|
return path.join(opts.dir || tmpDir, opts.name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// mkstemps like template
|
|
|
|
|
// opts.template has already been guarded in tmpName() below
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (opts.template) {
|
|
|
|
|
var template = opts.template;
|
|
|
|
|
// make sure that we prepend the tmp path if none was given
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (path.basename(template) === template)
|
|
|
|
|
template = path.join(opts.dir || tmpDir, template);
|
|
|
|
|
return template.replace(TEMPLATE_PATTERN, _randomChars(6));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prefix and postfix
|
|
|
|
|
const name = [
|
|
|
|
|
(isBlank(opts.prefix) ? 'tmp-' : opts.prefix),
|
|
|
|
|
process.pid,
|
|
|
|
|
_randomChars(12),
|
|
|
|
|
(opts.postfix ? opts.postfix : '')
|
|
|
|
|
].join('');
|
|
|
|
|
|
|
|
|
|
return path.join(opts.dir || tmpDir, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets a temporary file name.
|
|
|
|
|
*
|
|
|
|
@@ -1885,20 +2458,18 @@ function _generateTmpName(opts) {
|
|
|
|
|
* @param {?tmpNameCallback} callback the callback function
|
|
|
|
|
*/
|
|
|
|
|
function tmpName(options, callback) {
|
|
|
|
|
var
|
|
|
|
|
const
|
|
|
|
|
args = _parseArguments(options, callback),
|
|
|
|
|
opts = args[0],
|
|
|
|
|
cb = args[1],
|
|
|
|
|
tries = !isBlank(opts.name) ? 1 : opts.tries || DEFAULT_TRIES;
|
|
|
|
|
cb = args[1];
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (isNaN(tries) || tries < 0)
|
|
|
|
|
return cb(new Error('Invalid tries'));
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
|
|
|
|
|
return cb(new Error('Invalid template provided'));
|
|
|
|
|
try {
|
|
|
|
|
_assertAndSanitizeOptions(opts);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return cb(err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let tries = opts.tries;
|
|
|
|
|
(function _getUniqueName() {
|
|
|
|
|
try {
|
|
|
|
|
const name = _generateTmpName(opts);
|
|
|
|
@@ -1929,19 +2500,13 @@ function tmpName(options, callback) {
|
|
|
|
|
* @throws {Error} if the options are invalid or could not generate a filename
|
|
|
|
|
*/
|
|
|
|
|
function tmpNameSync(options) {
|
|
|
|
|
var
|
|
|
|
|
const
|
|
|
|
|
args = _parseArguments(options),
|
|
|
|
|
opts = args[0],
|
|
|
|
|
tries = !isBlank(opts.name) ? 1 : opts.tries || DEFAULT_TRIES;
|
|
|
|
|
opts = args[0];
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (isNaN(tries) || tries < 0)
|
|
|
|
|
throw new Error('Invalid tries');
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
|
|
|
|
|
throw new Error('Invalid template provided');
|
|
|
|
|
_assertAndSanitizeOptions(opts);
|
|
|
|
|
|
|
|
|
|
let tries = opts.tries;
|
|
|
|
|
do {
|
|
|
|
|
const name = _generateTmpName(opts);
|
|
|
|
|
try {
|
|
|
|
@@ -1957,11 +2522,11 @@ function tmpNameSync(options) {
|
|
|
|
|
/**
|
|
|
|
|
* Creates and opens a temporary file.
|
|
|
|
|
*
|
|
|
|
|
* @param {(Options|fileCallback)} options the config options or the callback function
|
|
|
|
|
* @param {(Options|null|undefined|fileCallback)} options the config options or the callback function or null or undefined
|
|
|
|
|
* @param {?fileCallback} callback
|
|
|
|
|
*/
|
|
|
|
|
function file(options, callback) {
|
|
|
|
|
var
|
|
|
|
|
const
|
|
|
|
|
args = _parseArguments(options, callback),
|
|
|
|
|
opts = args[0],
|
|
|
|
|
cb = args[1];
|
|
|
|
@@ -1973,34 +2538,20 @@ function file(options, callback) {
|
|
|
|
|
|
|
|
|
|
// create and open the file
|
|
|
|
|
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
/* istanbu ignore else */
|
|
|
|
|
if (err) return cb(err);
|
|
|
|
|
|
|
|
|
|
if (opts.discardDescriptor) {
|
|
|
|
|
return fs.close(fd, function _discardCallback(err) {
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (err) {
|
|
|
|
|
// Low probability, and the file exists, so this could be
|
|
|
|
|
// ignored. If it isn't we certainly need to unlink the
|
|
|
|
|
// file, and if that fails too its error is more
|
|
|
|
|
// important.
|
|
|
|
|
try {
|
|
|
|
|
fs.unlinkSync(name);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (!isENOENT(e)) {
|
|
|
|
|
err = e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return cb(err);
|
|
|
|
|
}
|
|
|
|
|
cb(null, name, undefined, _prepareTmpFileRemoveCallback(name, -1, opts));
|
|
|
|
|
return fs.close(fd, function _discardCallback(possibleErr) {
|
|
|
|
|
// the chance of getting an error on close here is rather low and might occur in the most edgiest cases only
|
|
|
|
|
return cb(possibleErr, name, undefined, _prepareTmpFileRemoveCallback(name, -1, opts, false));
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// detachDescriptor passes the descriptor whereas discardDescriptor closes it, either way, we no longer care
|
|
|
|
|
// about the descriptor
|
|
|
|
|
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
|
|
|
|
|
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, false));
|
|
|
|
|
}
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (opts.detachDescriptor) {
|
|
|
|
|
return cb(null, name, fd, _prepareTmpFileRemoveCallback(name, -1, opts));
|
|
|
|
|
}
|
|
|
|
|
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, fd, opts));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@@ -2013,7 +2564,7 @@ function file(options, callback) {
|
|
|
|
|
* @throws {Error} if cannot create a file
|
|
|
|
|
*/
|
|
|
|
|
function fileSync(options) {
|
|
|
|
|
var
|
|
|
|
|
const
|
|
|
|
|
args = _parseArguments(options),
|
|
|
|
|
opts = args[0];
|
|
|
|
|
|
|
|
|
@@ -2029,7 +2580,7 @@ function fileSync(options) {
|
|
|
|
|
return {
|
|
|
|
|
name: name,
|
|
|
|
|
fd: fd,
|
|
|
|
|
removeCallback: _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts)
|
|
|
|
|
removeCallback: _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, true)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2040,7 +2591,7 @@ function fileSync(options) {
|
|
|
|
|
* @param {?dirCallback} callback
|
|
|
|
|
*/
|
|
|
|
|
function dir(options, callback) {
|
|
|
|
|
var
|
|
|
|
|
const
|
|
|
|
|
args = _parseArguments(options, callback),
|
|
|
|
|
opts = args[0],
|
|
|
|
|
cb = args[1];
|
|
|
|
@@ -2055,7 +2606,7 @@ function dir(options, callback) {
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (err) return cb(err);
|
|
|
|
|
|
|
|
|
|
cb(null, name, _prepareTmpDirRemoveCallback(name, opts));
|
|
|
|
|
cb(null, name, _prepareTmpDirRemoveCallback(name, opts, false));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@@ -2068,7 +2619,7 @@ function dir(options, callback) {
|
|
|
|
|
* @throws {Error} if it cannot create a directory
|
|
|
|
|
*/
|
|
|
|
|
function dirSync(options) {
|
|
|
|
|
var
|
|
|
|
|
const
|
|
|
|
|
args = _parseArguments(options),
|
|
|
|
|
opts = args[0];
|
|
|
|
|
|
|
|
|
@@ -2077,7 +2628,7 @@ function dirSync(options) {
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
name: name,
|
|
|
|
|
removeCallback: _prepareTmpDirRemoveCallback(name, opts)
|
|
|
|
|
removeCallback: _prepareTmpDirRemoveCallback(name, opts, true)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2090,15 +2641,15 @@ function dirSync(options) {
|
|
|
|
|
*/
|
|
|
|
|
function _removeFileAsync(fdPath, next) {
|
|
|
|
|
const _handler = function (err) {
|
|
|
|
|
if (err && !isENOENT(err)) {
|
|
|
|
|
if (err && !_isENOENT(err)) {
|
|
|
|
|
// reraise any unanticipated error
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
next();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (0 <= fdPath[0])
|
|
|
|
|
fs.close(fdPath[0], function (err) {
|
|
|
|
|
fs.close(fdPath[0], function () {
|
|
|
|
|
fs.unlink(fdPath[1], _handler);
|
|
|
|
|
});
|
|
|
|
|
else fs.unlink(fdPath[1], _handler);
|
|
|
|
@@ -2111,117 +2662,104 @@ function _removeFileAsync(fdPath, next) {
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _removeFileSync(fdPath) {
|
|
|
|
|
let rethrownException = null;
|
|
|
|
|
try {
|
|
|
|
|
if (0 <= fdPath[0]) fs.closeSync(fdPath[0]);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// reraise any unanticipated error
|
|
|
|
|
if (!isEBADF(e) && !isENOENT(e)) throw e;
|
|
|
|
|
if (!_isEBADF(e) && !_isENOENT(e)) throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
fs.unlinkSync(fdPath[1]);
|
|
|
|
|
}
|
|
|
|
|
catch (e) {
|
|
|
|
|
// reraise any unanticipated error
|
|
|
|
|
if (!isENOENT(e)) throw e;
|
|
|
|
|
if (!_isENOENT(e)) rethrownException = e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rethrownException !== null) {
|
|
|
|
|
throw rethrownException;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepares the callback for removal of the temporary file.
|
|
|
|
|
*
|
|
|
|
|
* Returns either a sync callback or a async callback depending on whether
|
|
|
|
|
* fileSync or file was called, which is expressed by the sync parameter.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} name the path of the file
|
|
|
|
|
* @param {number} fd file descriptor
|
|
|
|
|
* @param {Object} opts
|
|
|
|
|
* @returns {fileCallback}
|
|
|
|
|
* @param {boolean} sync
|
|
|
|
|
* @returns {fileCallback | fileCallbackSync}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _prepareTmpFileRemoveCallback(name, fd, opts) {
|
|
|
|
|
const removeCallbackSync = _prepareRemoveCallback(_removeFileSync, [fd, name]);
|
|
|
|
|
const removeCallback = _prepareRemoveCallback(_removeFileAsync, [fd, name], removeCallbackSync);
|
|
|
|
|
function _prepareTmpFileRemoveCallback(name, fd, opts, sync) {
|
|
|
|
|
const removeCallbackSync = _prepareRemoveCallback(_removeFileSync, [fd, name], sync);
|
|
|
|
|
const removeCallback = _prepareRemoveCallback(_removeFileAsync, [fd, name], sync, removeCallbackSync);
|
|
|
|
|
|
|
|
|
|
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
|
|
|
|
|
|
|
|
|
|
return removeCallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Simple wrapper for rimraf.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} dirPath
|
|
|
|
|
* @param {Function} next
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _rimrafRemoveDirWrapper(dirPath, next) {
|
|
|
|
|
rimraf(dirPath, next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Simple wrapper for rimraf.sync.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} dirPath
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _rimrafRemoveDirSyncWrapper(dirPath, next) {
|
|
|
|
|
try {
|
|
|
|
|
return next(null, rimraf.sync(dirPath));
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
return sync ? removeCallbackSync : removeCallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepares the callback for removal of the temporary directory.
|
|
|
|
|
*
|
|
|
|
|
* Returns either a sync callback or a async callback depending on whether
|
|
|
|
|
* tmpFileSync or tmpFile was called, which is expressed by the sync parameter.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @param {Object} opts
|
|
|
|
|
* @param {boolean} sync
|
|
|
|
|
* @returns {Function} the callback
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _prepareTmpDirRemoveCallback(name, opts) {
|
|
|
|
|
const removeFunction = opts.unsafeCleanup ? _rimrafRemoveDirWrapper : fs.rmdir.bind(fs);
|
|
|
|
|
const removeFunctionSync = opts.unsafeCleanup ? _rimrafRemoveDirSyncWrapper : fs.rmdirSync.bind(fs);
|
|
|
|
|
const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name);
|
|
|
|
|
const removeCallback = _prepareRemoveCallback(removeFunction, name, removeCallbackSync);
|
|
|
|
|
function _prepareTmpDirRemoveCallback(name, opts, sync) {
|
|
|
|
|
const removeFunction = opts.unsafeCleanup ? rimraf : fs.rmdir.bind(fs);
|
|
|
|
|
const removeFunctionSync = opts.unsafeCleanup ? FN_RIMRAF_SYNC : FN_RMDIR_SYNC;
|
|
|
|
|
const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name, sync);
|
|
|
|
|
const removeCallback = _prepareRemoveCallback(removeFunction, name, sync, removeCallbackSync);
|
|
|
|
|
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
|
|
|
|
|
|
|
|
|
|
return removeCallback;
|
|
|
|
|
return sync ? removeCallbackSync : removeCallback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a guarded function wrapping the removeFunction call.
|
|
|
|
|
*
|
|
|
|
|
* The cleanup callback is save to be called multiple times.
|
|
|
|
|
* Subsequent invocations will be ignored.
|
|
|
|
|
*
|
|
|
|
|
* @param {Function} removeFunction
|
|
|
|
|
* @param {Object} arg
|
|
|
|
|
* @returns {Function}
|
|
|
|
|
* @param {string} fileOrDirName
|
|
|
|
|
* @param {boolean} sync
|
|
|
|
|
* @param {cleanupCallbackSync?} cleanupCallbackSync
|
|
|
|
|
* @returns {cleanupCallback | cleanupCallbackSync}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _prepareRemoveCallback(removeFunction, arg, cleanupCallbackSync) {
|
|
|
|
|
var called = false;
|
|
|
|
|
function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCallbackSync) {
|
|
|
|
|
let called = false;
|
|
|
|
|
|
|
|
|
|
// if sync is true, the next parameter will be ignored
|
|
|
|
|
return function _cleanupCallback(next) {
|
|
|
|
|
next = next || function () {};
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (!called) {
|
|
|
|
|
// remove cleanupCallback from cache
|
|
|
|
|
const toRemove = cleanupCallbackSync || _cleanupCallback;
|
|
|
|
|
const index = _removeObjects.indexOf(toRemove);
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (index >= 0) _removeObjects.splice(index, 1);
|
|
|
|
|
|
|
|
|
|
called = true;
|
|
|
|
|
// sync?
|
|
|
|
|
if (removeFunction.length === 1) {
|
|
|
|
|
try {
|
|
|
|
|
removeFunction(arg);
|
|
|
|
|
return next(null);
|
|
|
|
|
}
|
|
|
|
|
catch (err) {
|
|
|
|
|
// if no next is provided and since we are
|
|
|
|
|
// in silent cleanup mode on process exit,
|
|
|
|
|
// we will ignore the error
|
|
|
|
|
return next(err);
|
|
|
|
|
}
|
|
|
|
|
} else return removeFunction(arg, next);
|
|
|
|
|
} else return next(new Error('cleanup callback has already been called'));
|
|
|
|
|
if (sync || removeFunction === FN_RMDIR_SYNC || removeFunction === FN_RIMRAF_SYNC) {
|
|
|
|
|
return removeFunction(fileOrDirName);
|
|
|
|
|
} else {
|
|
|
|
|
return removeFunction(fileOrDirName, next || function() {});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -2246,41 +2784,30 @@ function _garbageCollector() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper for testing against EBADF to compensate changes made to Node 7.x under Windows.
|
|
|
|
|
* Random name generator based on crypto.
|
|
|
|
|
* Adapted from http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
|
|
|
|
|
*
|
|
|
|
|
* @param {number} howMany
|
|
|
|
|
* @returns {string} the generated random name
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function isEBADF(error) {
|
|
|
|
|
return isExpectedError(error, -EBADF, 'EBADF');
|
|
|
|
|
}
|
|
|
|
|
function _randomChars(howMany) {
|
|
|
|
|
let
|
|
|
|
|
value = [],
|
|
|
|
|
rnd = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper for testing against ENOENT to compensate changes made to Node 7.x under Windows.
|
|
|
|
|
*/
|
|
|
|
|
function isENOENT(error) {
|
|
|
|
|
return isExpectedError(error, -ENOENT, 'ENOENT');
|
|
|
|
|
}
|
|
|
|
|
// make sure that we do not fail because we ran out of entropy
|
|
|
|
|
try {
|
|
|
|
|
rnd = crypto.randomBytes(howMany);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
rnd = crypto.pseudoRandomBytes(howMany);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper to determine whether the expected error code matches the actual code and errno,
|
|
|
|
|
* which will differ between the supported node versions.
|
|
|
|
|
*
|
|
|
|
|
* - Node >= 7.0:
|
|
|
|
|
* error.code {string}
|
|
|
|
|
* error.errno {string|number} any numerical value will be negated
|
|
|
|
|
*
|
|
|
|
|
* - Node >= 6.0 < 7.0:
|
|
|
|
|
* error.code {string}
|
|
|
|
|
* error.errno {number} negated
|
|
|
|
|
*
|
|
|
|
|
* - Node >= 4.0 < 6.0: introduces SystemError
|
|
|
|
|
* error.code {string}
|
|
|
|
|
* error.errno {number} negated
|
|
|
|
|
*
|
|
|
|
|
* - Node >= 0.10 < 4.0:
|
|
|
|
|
* error.code {number} negated
|
|
|
|
|
* error.errno n/a
|
|
|
|
|
*/
|
|
|
|
|
function isExpectedError(error, code, errno) {
|
|
|
|
|
return error.code === code || error.code === errno;
|
|
|
|
|
for (var i = 0; i < howMany; i++) {
|
|
|
|
|
value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value.join('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -2290,12 +2817,241 @@ function isExpectedError(error, code, errno) {
|
|
|
|
|
* @param {string} s
|
|
|
|
|
* @returns {Boolean} true whether the string s is blank, false otherwise
|
|
|
|
|
*/
|
|
|
|
|
function isBlank(s) {
|
|
|
|
|
return s === null || s === undefined || !s.trim();
|
|
|
|
|
function _isBlank(s) {
|
|
|
|
|
return s === null || _isUndefined(s) || !s.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Checks whether the `obj` parameter is defined or not.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} obj
|
|
|
|
|
* @returns {boolean} true if the object is undefined
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _isUndefined(obj) {
|
|
|
|
|
return typeof obj === 'undefined';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parses the function arguments.
|
|
|
|
|
*
|
|
|
|
|
* This function helps to have optional arguments.
|
|
|
|
|
*
|
|
|
|
|
* @param {(Options|null|undefined|Function)} options
|
|
|
|
|
* @param {?Function} callback
|
|
|
|
|
* @returns {Array} parsed arguments
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _parseArguments(options, callback) {
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
|
return [{}, options];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (_isUndefined(options)) {
|
|
|
|
|
return [{}, callback];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// copy options so we do not leak the changes we make internally
|
|
|
|
|
const actualOptions = {};
|
|
|
|
|
for (const key of Object.getOwnPropertyNames(options)) {
|
|
|
|
|
actualOptions[key] = options[key];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return [actualOptions, callback];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generates a new temporary name.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} opts
|
|
|
|
|
* @returns {string} the new random name according to opts
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _generateTmpName(opts) {
|
|
|
|
|
|
|
|
|
|
const tmpDir = opts.tmpdir;
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (!_isUndefined(opts.name))
|
|
|
|
|
return path.join(tmpDir, opts.dir, opts.name);
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (!_isUndefined(opts.template))
|
|
|
|
|
return path.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
|
|
|
|
|
|
|
|
|
|
// prefix and postfix
|
|
|
|
|
const name = [
|
|
|
|
|
opts.prefix ? opts.prefix : 'tmp',
|
|
|
|
|
'-',
|
|
|
|
|
process.pid,
|
|
|
|
|
'-',
|
|
|
|
|
_randomChars(12),
|
|
|
|
|
opts.postfix ? '-' + opts.postfix : ''
|
|
|
|
|
].join('');
|
|
|
|
|
|
|
|
|
|
return path.join(tmpDir, opts.dir, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Asserts whether the specified options are valid, also sanitizes options and provides sane defaults for missing
|
|
|
|
|
* options.
|
|
|
|
|
*
|
|
|
|
|
* @param {Options} options
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _assertAndSanitizeOptions(options) {
|
|
|
|
|
|
|
|
|
|
options.tmpdir = _getTmpDir(options);
|
|
|
|
|
|
|
|
|
|
const tmpDir = options.tmpdir;
|
|
|
|
|
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (!_isUndefined(options.name))
|
|
|
|
|
_assertIsRelative(options.name, 'name', tmpDir);
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (!_isUndefined(options.dir))
|
|
|
|
|
_assertIsRelative(options.dir, 'dir', tmpDir);
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (!_isUndefined(options.template)) {
|
|
|
|
|
_assertIsRelative(options.template, 'template', tmpDir);
|
|
|
|
|
if (!options.template.match(TEMPLATE_PATTERN))
|
|
|
|
|
throw new Error(`Invalid template, found "${options.template}".`);
|
|
|
|
|
}
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (!_isUndefined(options.tries) && isNaN(options.tries) || options.tries < 0)
|
|
|
|
|
throw new Error(`Invalid tries, found "${options.tries}".`);
|
|
|
|
|
|
|
|
|
|
// if a name was specified we will try once
|
|
|
|
|
options.tries = _isUndefined(options.name) ? options.tries || DEFAULT_TRIES : 1;
|
|
|
|
|
options.keep = !!options.keep;
|
|
|
|
|
options.detachDescriptor = !!options.detachDescriptor;
|
|
|
|
|
options.discardDescriptor = !!options.discardDescriptor;
|
|
|
|
|
options.unsafeCleanup = !!options.unsafeCleanup;
|
|
|
|
|
|
|
|
|
|
// sanitize dir, also keep (multiple) blanks if the user, purportedly sane, requests us to
|
|
|
|
|
options.dir = _isUndefined(options.dir) ? '' : path.relative(tmpDir, _resolvePath(options.dir, tmpDir));
|
|
|
|
|
options.template = _isUndefined(options.template) ? undefined : path.relative(tmpDir, _resolvePath(options.template, tmpDir));
|
|
|
|
|
// sanitize further if template is relative to options.dir
|
|
|
|
|
options.template = _isBlank(options.template) ? undefined : path.relative(options.dir, options.template);
|
|
|
|
|
|
|
|
|
|
// for completeness' sake only, also keep (multiple) blanks if the user, purportedly sane, requests us to
|
|
|
|
|
options.name = _isUndefined(options.name) ? undefined : _sanitizeName(options.name);
|
|
|
|
|
options.prefix = _isUndefined(options.prefix) ? '' : options.prefix;
|
|
|
|
|
options.postfix = _isUndefined(options.postfix) ? '' : options.postfix;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolve the specified path name in respect to tmpDir.
|
|
|
|
|
*
|
|
|
|
|
* The specified name might include relative path components, e.g. ../
|
|
|
|
|
* so we need to resolve in order to be sure that is is located inside tmpDir
|
|
|
|
|
*
|
|
|
|
|
* @param name
|
|
|
|
|
* @param tmpDir
|
|
|
|
|
* @returns {string}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _resolvePath(name, tmpDir) {
|
|
|
|
|
const sanitizedName = _sanitizeName(name);
|
|
|
|
|
if (sanitizedName.startsWith(tmpDir)) {
|
|
|
|
|
return path.resolve(sanitizedName);
|
|
|
|
|
} else {
|
|
|
|
|
return path.resolve(path.join(tmpDir, sanitizedName));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sanitize the specified path name by removing all quote characters.
|
|
|
|
|
*
|
|
|
|
|
* @param name
|
|
|
|
|
* @returns {string}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _sanitizeName(name) {
|
|
|
|
|
if (_isBlank(name)) {
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
return name.replace(/["']/g, '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Asserts whether specified name is relative to the specified tmpDir.
|
|
|
|
|
*
|
|
|
|
|
* @param {string} name
|
|
|
|
|
* @param {string} option
|
|
|
|
|
* @param {string} tmpDir
|
|
|
|
|
* @throws {Error}
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _assertIsRelative(name, option, tmpDir) {
|
|
|
|
|
if (option === 'name') {
|
|
|
|
|
// assert that name is not absolute and does not contain a path
|
|
|
|
|
if (path.isAbsolute(name))
|
|
|
|
|
throw new Error(`${option} option must not contain an absolute path, found "${name}".`);
|
|
|
|
|
// must not fail on valid .<name> or ..<name> or similar such constructs
|
|
|
|
|
let basename = path.basename(name);
|
|
|
|
|
if (basename === '..' || basename === '.' || basename !== name)
|
|
|
|
|
throw new Error(`${option} option must not contain a path, found "${name}".`);
|
|
|
|
|
}
|
|
|
|
|
else { // if (option === 'dir' || option === 'template') {
|
|
|
|
|
// assert that dir or template are relative to tmpDir
|
|
|
|
|
if (path.isAbsolute(name) && !name.startsWith(tmpDir)) {
|
|
|
|
|
throw new Error(`${option} option must be relative to "${tmpDir}", found "${name}".`);
|
|
|
|
|
}
|
|
|
|
|
let resolvedPath = _resolvePath(name, tmpDir);
|
|
|
|
|
if (!resolvedPath.startsWith(tmpDir))
|
|
|
|
|
throw new Error(`${option} option must be relative to "${tmpDir}", found "${resolvedPath}".`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper for testing against EBADF to compensate changes made to Node 7.x under Windows.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _isEBADF(error) {
|
|
|
|
|
return _isExpectedError(error, -EBADF, 'EBADF');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper for testing against ENOENT to compensate changes made to Node 7.x under Windows.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _isENOENT(error) {
|
|
|
|
|
return _isExpectedError(error, -ENOENT, 'ENOENT');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Helper to determine whether the expected error code matches the actual code and errno,
|
|
|
|
|
* which will differ between the supported node versions.
|
|
|
|
|
*
|
|
|
|
|
* - Node >= 7.0:
|
|
|
|
|
* error.code {string}
|
|
|
|
|
* error.errno {number} any numerical value will be negated
|
|
|
|
|
*
|
|
|
|
|
* CAVEAT
|
|
|
|
|
*
|
|
|
|
|
* On windows, the errno for EBADF is -4083 but os.constants.errno.EBADF is different and we must assume that ENOENT
|
|
|
|
|
* is no different here.
|
|
|
|
|
*
|
|
|
|
|
* @param {SystemError} error
|
|
|
|
|
* @param {number} errno
|
|
|
|
|
* @param {string} code
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _isExpectedError(error, errno, code) {
|
|
|
|
|
return IS_WIN32 ? error.code === code : error.code === code && error.errno === errno;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the graceful cleanup.
|
|
|
|
|
*
|
|
|
|
|
* If graceful cleanup is set, tmp will remove all controlled temporary objects on process exit, otherwise the
|
|
|
|
|
* temporary objects will remain in place, waiting to be cleaned up on system restart or otherwise scheduled temporary
|
|
|
|
|
* object removals.
|
|
|
|
|
*/
|
|
|
|
|
function setGracefulCleanup() {
|
|
|
|
|
_gracefulCleanup = true;
|
|
|
|
@@ -2305,120 +3061,38 @@ function setGracefulCleanup() {
|
|
|
|
|
* Returns the currently configured tmp dir from os.tmpdir().
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
* @param {?Options} options
|
|
|
|
|
* @returns {string} the currently configured tmp dir
|
|
|
|
|
*/
|
|
|
|
|
function _getTmpDir() {
|
|
|
|
|
return os.tmpdir();
|
|
|
|
|
function _getTmpDir(options) {
|
|
|
|
|
return path.resolve(_sanitizeName(options && options.tmpdir || os.tmpdir()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If there are multiple different versions of tmp in place, make sure that
|
|
|
|
|
* we recognize the old listeners.
|
|
|
|
|
*
|
|
|
|
|
* @param {Function} listener
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {Boolean} true whether listener is a legacy listener
|
|
|
|
|
*/
|
|
|
|
|
function _is_legacy_listener(listener) {
|
|
|
|
|
return (listener.name === '_exit' || listener.name === '_uncaughtExceptionThrown')
|
|
|
|
|
&& listener.toString().indexOf('_garbageCollector();') > -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Safely install SIGINT listener.
|
|
|
|
|
*
|
|
|
|
|
* NOTE: this will only work on OSX and Linux.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _safely_install_sigint_listener() {
|
|
|
|
|
|
|
|
|
|
const listeners = process.listeners(SIGINT);
|
|
|
|
|
const existingListeners = [];
|
|
|
|
|
for (let i = 0, length = listeners.length; i < length; i++) {
|
|
|
|
|
const lstnr = listeners[i];
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
if (lstnr.name === '_tmp$sigint_listener') {
|
|
|
|
|
existingListeners.push(lstnr);
|
|
|
|
|
process.removeListener(SIGINT, lstnr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
process.on(SIGINT, function _tmp$sigint_listener(doExit) {
|
|
|
|
|
for (let i = 0, length = existingListeners.length; i < length; i++) {
|
|
|
|
|
// let the existing listener do the garbage collection (e.g. jest sandbox)
|
|
|
|
|
try {
|
|
|
|
|
existingListeners[i](false);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
// force the garbage collector even it is called again in the exit listener
|
|
|
|
|
_garbageCollector();
|
|
|
|
|
} finally {
|
|
|
|
|
if (!!doExit) {
|
|
|
|
|
process.exit(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Safely install process exit listener.
|
|
|
|
|
*
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function _safely_install_exit_listener() {
|
|
|
|
|
const listeners = process.listeners(EXIT);
|
|
|
|
|
|
|
|
|
|
// collect any existing listeners
|
|
|
|
|
const existingListeners = [];
|
|
|
|
|
for (let i = 0, length = listeners.length; i < length; i++) {
|
|
|
|
|
const lstnr = listeners[i];
|
|
|
|
|
/* istanbul ignore else */
|
|
|
|
|
// TODO: remove support for legacy listeners once release 1.0.0 is out
|
|
|
|
|
if (lstnr.name === '_tmp$safe_listener' || _is_legacy_listener(lstnr)) {
|
|
|
|
|
// we must forget about the uncaughtException listener, hopefully it is ours
|
|
|
|
|
if (lstnr.name !== '_uncaughtExceptionThrown') {
|
|
|
|
|
existingListeners.push(lstnr);
|
|
|
|
|
}
|
|
|
|
|
process.removeListener(EXIT, lstnr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// TODO: what was the data parameter good for?
|
|
|
|
|
process.addListener(EXIT, function _tmp$safe_listener(data) {
|
|
|
|
|
for (let i = 0, length = existingListeners.length; i < length; i++) {
|
|
|
|
|
// let the existing listener do the garbage collection (e.g. jest sandbox)
|
|
|
|
|
try {
|
|
|
|
|
existingListeners[i](data);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_garbageCollector();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_safely_install_exit_listener();
|
|
|
|
|
_safely_install_sigint_listener();
|
|
|
|
|
// Install process exit listener
|
|
|
|
|
process.addListener(EXIT, _garbageCollector);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Configuration options.
|
|
|
|
|
*
|
|
|
|
|
* @typedef {Object} Options
|
|
|
|
|
* @property {?boolean} keep the temporary object (file or dir) will not be garbage collected
|
|
|
|
|
* @property {?number} tries the number of tries before give up the name generation
|
|
|
|
|
* @property (?int) mode the access mode, defaults are 0o700 for directories and 0o600 for files
|
|
|
|
|
* @property {?string} template the "mkstemp" like filename template
|
|
|
|
|
* @property {?string} name fix name
|
|
|
|
|
* @property {?string} dir the tmp directory to use
|
|
|
|
|
* @property {?string} name fixed name relative to tmpdir or the specified dir option
|
|
|
|
|
* @property {?string} dir tmp directory relative to the root tmp directory in use
|
|
|
|
|
* @property {?string} prefix prefix for the generated name
|
|
|
|
|
* @property {?string} postfix postfix for the generated name
|
|
|
|
|
* @property {?string} tmpdir the root tmp directory which overrides the os tmpdir
|
|
|
|
|
* @property {?boolean} unsafeCleanup recursively removes the created temporary directory, even when it's not empty
|
|
|
|
|
* @property {?boolean} detachDescriptor detaches the file descriptor, caller is responsible for closing the file, tmp will no longer try closing the file during garbage collection
|
|
|
|
|
* @property {?boolean} discardDescriptor discards the file descriptor (closes file, fd is -1), tmp will no longer try closing the file during garbage collection
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @typedef {Object} FileSyncObject
|
|
|
|
|
* @property {string} name the name of the file
|
|
|
|
|
* @property {string} fd the file descriptor
|
|
|
|
|
* @property {string} fd the file descriptor or -1 if the fd has been discarded
|
|
|
|
|
* @property {fileCallback} removeCallback the callback function to remove the file
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
@@ -2438,10 +3112,18 @@ _safely_install_sigint_listener();
|
|
|
|
|
* @callback fileCallback
|
|
|
|
|
* @param {?Error} err the error object if anything goes wrong
|
|
|
|
|
* @param {string} name the temporary file name
|
|
|
|
|
* @param {number} fd the file descriptor
|
|
|
|
|
* @param {number} fd the file descriptor or -1 if the fd had been discarded
|
|
|
|
|
* @param {cleanupCallback} fn the cleanup callback function
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @callback fileCallbackSync
|
|
|
|
|
* @param {?Error} err the error object if anything goes wrong
|
|
|
|
|
* @param {string} name the temporary file name
|
|
|
|
|
* @param {number} fd the file descriptor or -1 if the fd had been discarded
|
|
|
|
|
* @param {cleanupCallbackSync} fn the cleanup callback function
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @callback dirCallback
|
|
|
|
|
* @param {?Error} err the error object if anything goes wrong
|
|
|
|
@@ -2449,11 +3131,24 @@ _safely_install_sigint_listener();
|
|
|
|
|
* @param {cleanupCallback} fn the cleanup callback function
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @callback dirCallbackSync
|
|
|
|
|
* @param {?Error} err the error object if anything goes wrong
|
|
|
|
|
* @param {string} name the temporary file name
|
|
|
|
|
* @param {cleanupCallbackSync} fn the cleanup callback function
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the temporary created file or directory.
|
|
|
|
|
*
|
|
|
|
|
* @callback cleanupCallback
|
|
|
|
|
* @param {simpleCallback} [next] function to call after entry was removed
|
|
|
|
|
* @param {simpleCallback} [next] function to call whenever the tmp object needs to be removed
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the temporary created file or directory.
|
|
|
|
|
*
|
|
|
|
|
* @callback cleanupCallbackSync
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@@ -2465,7 +3160,7 @@ _safely_install_sigint_listener();
|
|
|
|
|
|
|
|
|
|
// exporting all the needed methods
|
|
|
|
|
|
|
|
|
|
// evaluate os.tmpdir() lazily, mainly for simplifying testing but it also will
|
|
|
|
|
// evaluate _getTmpDir() lazily, mainly for simplifying testing but it also will
|
|
|
|
|
// allow users to reconfigure the temporary directory
|
|
|
|
|
Object.defineProperty(module.exports, 'tmpdir', {
|
|
|
|
|
enumerable: true,
|
|
|
|
@@ -2495,6 +3190,7 @@ module.exports.setGracefulCleanup = setGracefulCleanup;
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.StatusReporter = void 0;
|
|
|
|
|
const core_1 = __webpack_require__(470);
|
|
|
|
|
/**
|
|
|
|
|
* Status Reporter that displays information about the progress/status of an artifact that is being uploaded or downloaded
|
|
|
|
@@ -2509,11 +3205,11 @@ class StatusReporter {
|
|
|
|
|
this.processedCount = 0;
|
|
|
|
|
this.largeFiles = new Map();
|
|
|
|
|
this.totalFileStatus = undefined;
|
|
|
|
|
this.largeFileStatus = undefined;
|
|
|
|
|
this.displayFrequencyInMilliseconds = displayFrequencyInMilliseconds;
|
|
|
|
|
}
|
|
|
|
|
setTotalNumberOfFilesToProcess(fileTotal) {
|
|
|
|
|
this.totalNumberOfFilesToProcess = fileTotal;
|
|
|
|
|
this.processedCount = 0;
|
|
|
|
|
}
|
|
|
|
|
start() {
|
|
|
|
|
// displays information about the total upload/download status
|
|
|
|
@@ -2522,30 +3218,17 @@ class StatusReporter {
|
|
|
|
|
const percentage = this.formatPercentage(this.processedCount, this.totalNumberOfFilesToProcess);
|
|
|
|
|
core_1.info(`Total file count: ${this.totalNumberOfFilesToProcess} ---- Processed file #${this.processedCount} (${percentage.slice(0, percentage.indexOf('.') + 2)}%)`);
|
|
|
|
|
}, this.displayFrequencyInMilliseconds);
|
|
|
|
|
// displays extra information about any large files that take a significant amount of time to upload or download every 1 second
|
|
|
|
|
this.largeFileStatus = setInterval(() => {
|
|
|
|
|
for (const value of Array.from(this.largeFiles.values())) {
|
|
|
|
|
core_1.info(value);
|
|
|
|
|
}
|
|
|
|
|
// delete all entries in the map after displaying the information so it will not be displayed again unless explicitly added
|
|
|
|
|
this.largeFiles.clear();
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
// if there is a large file that is being uploaded in chunks, this is used to display extra information about the status of the upload
|
|
|
|
|
updateLargeFileStatus(fileName, numerator, denominator) {
|
|
|
|
|
updateLargeFileStatus(fileName, chunkStartIndex, chunkEndIndex, totalUploadFileSize) {
|
|
|
|
|
// display 1 decimal place without any rounding
|
|
|
|
|
const percentage = this.formatPercentage(numerator, denominator);
|
|
|
|
|
const displayInformation = `Uploading ${fileName} (${percentage.slice(0, percentage.indexOf('.') + 2)}%)`;
|
|
|
|
|
// any previously added display information should be overwritten for the specific large file because a map is being used
|
|
|
|
|
this.largeFiles.set(fileName, displayInformation);
|
|
|
|
|
const percentage = this.formatPercentage(chunkEndIndex, totalUploadFileSize);
|
|
|
|
|
core_1.info(`Uploaded ${fileName} (${percentage.slice(0, percentage.indexOf('.') + 2)}%) bytes ${chunkStartIndex}:${chunkEndIndex}`);
|
|
|
|
|
}
|
|
|
|
|
stop() {
|
|
|
|
|
if (this.totalFileStatus) {
|
|
|
|
|
clearInterval(this.totalFileStatus);
|
|
|
|
|
}
|
|
|
|
|
if (this.largeFileStatus) {
|
|
|
|
|
clearInterval(this.largeFileStatus);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
incrementProcessedCount() {
|
|
|
|
|
this.processedCount++;
|
|
|
|
@@ -2560,6 +3243,74 @@ exports.StatusReporter = StatusReporter;
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 177:
|
|
|
|
|
/***/ (function(__unusedmodule, exports) {
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.checkBypass = exports.getProxyUrl = void 0;
|
|
|
|
|
function getProxyUrl(reqUrl) {
|
|
|
|
|
const usingSsl = reqUrl.protocol === 'https:';
|
|
|
|
|
if (checkBypass(reqUrl)) {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
const proxyVar = (() => {
|
|
|
|
|
if (usingSsl) {
|
|
|
|
|
return process.env['https_proxy'] || process.env['HTTPS_PROXY'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return process.env['http_proxy'] || process.env['HTTP_PROXY'];
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
if (proxyVar) {
|
|
|
|
|
return new URL(proxyVar);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.getProxyUrl = getProxyUrl;
|
|
|
|
|
function checkBypass(reqUrl) {
|
|
|
|
|
if (!reqUrl.hostname) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
|
|
|
|
if (!noProxy) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Determine the request port
|
|
|
|
|
let reqPort;
|
|
|
|
|
if (reqUrl.port) {
|
|
|
|
|
reqPort = Number(reqUrl.port);
|
|
|
|
|
}
|
|
|
|
|
else if (reqUrl.protocol === 'http:') {
|
|
|
|
|
reqPort = 80;
|
|
|
|
|
}
|
|
|
|
|
else if (reqUrl.protocol === 'https:') {
|
|
|
|
|
reqPort = 443;
|
|
|
|
|
}
|
|
|
|
|
// Format the request hostname and hostname with port
|
|
|
|
|
const upperReqHosts = [reqUrl.hostname.toUpperCase()];
|
|
|
|
|
if (typeof reqPort === 'number') {
|
|
|
|
|
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
|
|
|
|
}
|
|
|
|
|
// Compare request host against noproxy
|
|
|
|
|
for (const upperNoProxyItem of noProxy
|
|
|
|
|
.split(',')
|
|
|
|
|
.map(x => x.trim().toUpperCase())
|
|
|
|
|
.filter(x => x)) {
|
|
|
|
|
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
exports.checkBypass = checkBypass;
|
|
|
|
|
//# sourceMappingURL=proxy.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 211:
|
|
|
|
|
/***/ (function(module) {
|
|
|
|
|
|
|
|
|
@@ -2573,6 +3324,7 @@ module.exports = require("https");
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.create = void 0;
|
|
|
|
|
const artifact_client_1 = __webpack_require__(359);
|
|
|
|
|
/**
|
|
|
|
|
* Constructs an ArtifactClient
|
|
|
|
@@ -2583,72 +3335,6 @@ function create() {
|
|
|
|
|
exports.create = create;
|
|
|
|
|
//# sourceMappingURL=artifact-client.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 226:
|
|
|
|
|
/***/ (function(__unusedmodule, exports) {
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
class BasicCredentialHandler {
|
|
|
|
|
constructor(username, password) {
|
|
|
|
|
this.username = username;
|
|
|
|
|
this.password = password;
|
|
|
|
|
}
|
|
|
|
|
prepareRequest(options) {
|
|
|
|
|
options.headers['Authorization'] =
|
|
|
|
|
'Basic ' +
|
|
|
|
|
Buffer.from(this.username + ':' + this.password).toString('base64');
|
|
|
|
|
}
|
|
|
|
|
// This handler cannot handle 401
|
|
|
|
|
canHandleAuthentication(response) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
handleAuthentication(httpClient, requestInfo, objs) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.BasicCredentialHandler = BasicCredentialHandler;
|
|
|
|
|
class BearerCredentialHandler {
|
|
|
|
|
constructor(token) {
|
|
|
|
|
this.token = token;
|
|
|
|
|
}
|
|
|
|
|
// currently implements pre-authorization
|
|
|
|
|
// TODO: support preAuth = false where it hooks on 401
|
|
|
|
|
prepareRequest(options) {
|
|
|
|
|
options.headers['Authorization'] = 'Bearer ' + this.token;
|
|
|
|
|
}
|
|
|
|
|
// This handler cannot handle 401
|
|
|
|
|
canHandleAuthentication(response) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
handleAuthentication(httpClient, requestInfo, objs) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.BearerCredentialHandler = BearerCredentialHandler;
|
|
|
|
|
class PersonalAccessTokenCredentialHandler {
|
|
|
|
|
constructor(token) {
|
|
|
|
|
this.token = token;
|
|
|
|
|
}
|
|
|
|
|
// currently implements pre-authorization
|
|
|
|
|
// TODO: support preAuth = false where it hooks on 401
|
|
|
|
|
prepareRequest(options) {
|
|
|
|
|
options.headers['Authorization'] =
|
|
|
|
|
'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
|
|
|
|
|
}
|
|
|
|
|
// This handler cannot handle 401
|
|
|
|
|
canHandleAuthentication(response) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
handleAuthentication(httpClient, requestInfo, objs) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 245:
|
|
|
|
@@ -3749,6 +4435,25 @@ module.exports = require("assert");
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
@@ -3758,18 +4463,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
|
result["default"] = mod;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.DefaultArtifactClient = void 0;
|
|
|
|
|
const core = __importStar(__webpack_require__(470));
|
|
|
|
|
const upload_specification_1 = __webpack_require__(590);
|
|
|
|
|
const upload_http_client_1 = __webpack_require__(608);
|
|
|
|
|
const utils_1 = __webpack_require__(870);
|
|
|
|
|
const path_and_artifact_name_validation_1 = __webpack_require__(553);
|
|
|
|
|
const download_http_client_1 = __webpack_require__(855);
|
|
|
|
|
const download_specification_1 = __webpack_require__(532);
|
|
|
|
|
const config_variables_1 = __webpack_require__(401);
|
|
|
|
@@ -3786,7 +4486,9 @@ class DefaultArtifactClient {
|
|
|
|
|
*/
|
|
|
|
|
uploadArtifact(name, files, rootDirectory, options) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
utils_1.checkArtifactName(name);
|
|
|
|
|
core.info(`Starting artifact upload
|
|
|
|
|
For more detailed logs during the artifact upload process, enable step-debugging: https://docs.github.com/actions/monitoring-and-troubleshooting-workflows/enabling-debug-logging#enabling-step-debug-logging`);
|
|
|
|
|
path_and_artifact_name_validation_1.checkArtifactName(name);
|
|
|
|
|
// Get specification for the files being uploaded
|
|
|
|
|
const uploadSpecification = upload_specification_1.getUploadSpecification(name, rootDirectory, files);
|
|
|
|
|
const uploadResponse = {
|
|
|
|
@@ -3807,12 +4509,24 @@ class DefaultArtifactClient {
|
|
|
|
|
throw new Error('No URL provided by the Artifact Service to upload an artifact to');
|
|
|
|
|
}
|
|
|
|
|
core.debug(`Upload Resource URL: ${response.fileContainerResourceUrl}`);
|
|
|
|
|
core.info(`Container for artifact "${name}" successfully created. Starting upload of file(s)`);
|
|
|
|
|
// Upload each of the files that were found concurrently
|
|
|
|
|
const uploadResult = yield uploadHttpClient.uploadArtifactToFileContainer(response.fileContainerResourceUrl, uploadSpecification, options);
|
|
|
|
|
// Update the size of the artifact to indicate we are done uploading
|
|
|
|
|
// The uncompressed size is used for display when downloading a zip of the artifact from the UI
|
|
|
|
|
core.info(`File upload process has finished. Finalizing the artifact upload`);
|
|
|
|
|
yield uploadHttpClient.patchArtifactSize(uploadResult.totalSize, name);
|
|
|
|
|
core.info(`Finished uploading artifact ${name}. Reported size is ${uploadResult.uploadSize} bytes. There were ${uploadResult.failedItems.length} items that failed to upload`);
|
|
|
|
|
if (uploadResult.failedItems.length > 0) {
|
|
|
|
|
core.info(`Upload finished. There were ${uploadResult.failedItems.length} items that failed to upload`);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
core.info(`Artifact has been finalized. All files have been successfully uploaded!`);
|
|
|
|
|
}
|
|
|
|
|
core.info(`
|
|
|
|
|
The raw size of all the files that were specified for upload is ${uploadResult.totalSize} bytes
|
|
|
|
|
The size of all the files that were uploaded is ${uploadResult.uploadSize} bytes. This takes into account any gzip compression used to reduce the upload size, time and storage
|
|
|
|
|
|
|
|
|
|
Note: The size of downloaded zips can differ significantly from the reported size. For more information see: https://github.com/actions/upload-artifact#zipped-artifact-downloads \r\n`);
|
|
|
|
|
uploadResponse.artifactItems = uploadSpecification.map(item => item.absoluteFilePath);
|
|
|
|
|
uploadResponse.size = uploadResult.uploadSize;
|
|
|
|
|
uploadResponse.failedItems = uploadResult.failedItems;
|
|
|
|
@@ -3875,6 +4589,7 @@ class DefaultArtifactClient {
|
|
|
|
|
while (downloadedArtifacts < artifacts.count) {
|
|
|
|
|
const currentArtifactToDownload = artifacts.value[downloadedArtifacts];
|
|
|
|
|
downloadedArtifacts += 1;
|
|
|
|
|
core.info(`starting download of artifact ${currentArtifactToDownload.name} : ${downloadedArtifacts}/${artifacts.count}`);
|
|
|
|
|
// Get container entries for the specific artifact
|
|
|
|
|
const items = yield downloadHttpClient.getContainerItems(currentArtifactToDownload.name, currentArtifactToDownload.fileContainerResourceUrl);
|
|
|
|
|
const downloadSpecification = download_specification_1.getDownloadSpecification(currentArtifactToDownload.name, items.value, path, true);
|
|
|
|
@@ -4051,7 +4766,7 @@ function run() {
|
|
|
|
|
core.info(`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`);
|
|
|
|
|
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`);
|
|
|
|
|
if (searchResult.filesToUpload.length > 10000) {
|
|
|
|
|
core.warning(`There are over 10,000 files in this artifact, consider create an archive before upload to improve the upload performance.`);
|
|
|
|
|
core.warning(`There are over 10,000 files in this artifact, consider creating an archive before upload to improve the upload performance.`);
|
|
|
|
|
}
|
|
|
|
|
const artifactClient = artifact_1.create();
|
|
|
|
|
const options = {
|
|
|
|
@@ -4085,6 +4800,7 @@ run();
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.getRetentionDays = exports.getWorkSpaceDirectory = exports.getWorkFlowRunId = exports.getRuntimeUrl = exports.getRuntimeToken = exports.getDownloadFileConcurrency = exports.getInitialRetryIntervalInMilliseconds = exports.getRetryMultiplier = exports.getRetryLimit = exports.getUploadChunkSize = exports.getUploadFileConcurrency = void 0;
|
|
|
|
|
// The number of concurrent uploads that happens at the same time
|
|
|
|
|
function getUploadFileConcurrency() {
|
|
|
|
|
return 2;
|
|
|
|
@@ -4955,10 +5671,9 @@ Glob.prototype._stat2 = function (f, abs, er, stat, cb) {
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 413:
|
|
|
|
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
module.exports = __webpack_require__(141);
|
|
|
|
|
/***/ (function(module) {
|
|
|
|
|
|
|
|
|
|
module.exports = require("stream");
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
@@ -4969,6 +5684,618 @@ module.exports = require("crypto");
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 425:
|
|
|
|
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.HttpClient = exports.isHttps = exports.HttpClientResponse = exports.HttpClientError = exports.getProxyUrl = exports.MediaTypes = exports.Headers = exports.HttpCodes = void 0;
|
|
|
|
|
const http = __importStar(__webpack_require__(605));
|
|
|
|
|
const https = __importStar(__webpack_require__(211));
|
|
|
|
|
const pm = __importStar(__webpack_require__(177));
|
|
|
|
|
const tunnel = __importStar(__webpack_require__(988));
|
|
|
|
|
var HttpCodes;
|
|
|
|
|
(function (HttpCodes) {
|
|
|
|
|
HttpCodes[HttpCodes["OK"] = 200] = "OK";
|
|
|
|
|
HttpCodes[HttpCodes["MultipleChoices"] = 300] = "MultipleChoices";
|
|
|
|
|
HttpCodes[HttpCodes["MovedPermanently"] = 301] = "MovedPermanently";
|
|
|
|
|
HttpCodes[HttpCodes["ResourceMoved"] = 302] = "ResourceMoved";
|
|
|
|
|
HttpCodes[HttpCodes["SeeOther"] = 303] = "SeeOther";
|
|
|
|
|
HttpCodes[HttpCodes["NotModified"] = 304] = "NotModified";
|
|
|
|
|
HttpCodes[HttpCodes["UseProxy"] = 305] = "UseProxy";
|
|
|
|
|
HttpCodes[HttpCodes["SwitchProxy"] = 306] = "SwitchProxy";
|
|
|
|
|
HttpCodes[HttpCodes["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
|
|
|
HttpCodes[HttpCodes["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
|
|
|
HttpCodes[HttpCodes["BadRequest"] = 400] = "BadRequest";
|
|
|
|
|
HttpCodes[HttpCodes["Unauthorized"] = 401] = "Unauthorized";
|
|
|
|
|
HttpCodes[HttpCodes["PaymentRequired"] = 402] = "PaymentRequired";
|
|
|
|
|
HttpCodes[HttpCodes["Forbidden"] = 403] = "Forbidden";
|
|
|
|
|
HttpCodes[HttpCodes["NotFound"] = 404] = "NotFound";
|
|
|
|
|
HttpCodes[HttpCodes["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
|
|
|
HttpCodes[HttpCodes["NotAcceptable"] = 406] = "NotAcceptable";
|
|
|
|
|
HttpCodes[HttpCodes["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
|
|
|
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
|
|
|
|
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
|
|
|
|
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
|
|
|
|
HttpCodes[HttpCodes["TooManyRequests"] = 429] = "TooManyRequests";
|
|
|
|
|
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
|
|
|
|
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
|
|
|
|
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
|
|
|
|
HttpCodes[HttpCodes["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
|
|
|
HttpCodes[HttpCodes["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
|
|
|
})(HttpCodes = exports.HttpCodes || (exports.HttpCodes = {}));
|
|
|
|
|
var Headers;
|
|
|
|
|
(function (Headers) {
|
|
|
|
|
Headers["Accept"] = "accept";
|
|
|
|
|
Headers["ContentType"] = "content-type";
|
|
|
|
|
})(Headers = exports.Headers || (exports.Headers = {}));
|
|
|
|
|
var MediaTypes;
|
|
|
|
|
(function (MediaTypes) {
|
|
|
|
|
MediaTypes["ApplicationJson"] = "application/json";
|
|
|
|
|
})(MediaTypes = exports.MediaTypes || (exports.MediaTypes = {}));
|
|
|
|
|
/**
|
|
|
|
|
* Returns the proxy URL, depending upon the supplied url and proxy environment variables.
|
|
|
|
|
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
|
|
|
|
*/
|
|
|
|
|
function getProxyUrl(serverUrl) {
|
|
|
|
|
const proxyUrl = pm.getProxyUrl(new URL(serverUrl));
|
|
|
|
|
return proxyUrl ? proxyUrl.href : '';
|
|
|
|
|
}
|
|
|
|
|
exports.getProxyUrl = getProxyUrl;
|
|
|
|
|
const HttpRedirectCodes = [
|
|
|
|
|
HttpCodes.MovedPermanently,
|
|
|
|
|
HttpCodes.ResourceMoved,
|
|
|
|
|
HttpCodes.SeeOther,
|
|
|
|
|
HttpCodes.TemporaryRedirect,
|
|
|
|
|
HttpCodes.PermanentRedirect
|
|
|
|
|
];
|
|
|
|
|
const HttpResponseRetryCodes = [
|
|
|
|
|
HttpCodes.BadGateway,
|
|
|
|
|
HttpCodes.ServiceUnavailable,
|
|
|
|
|
HttpCodes.GatewayTimeout
|
|
|
|
|
];
|
|
|
|
|
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
|
|
|
|
const ExponentialBackoffCeiling = 10;
|
|
|
|
|
const ExponentialBackoffTimeSlice = 5;
|
|
|
|
|
class HttpClientError extends Error {
|
|
|
|
|
constructor(message, statusCode) {
|
|
|
|
|
super(message);
|
|
|
|
|
this.name = 'HttpClientError';
|
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
|
Object.setPrototypeOf(this, HttpClientError.prototype);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.HttpClientError = HttpClientError;
|
|
|
|
|
class HttpClientResponse {
|
|
|
|
|
constructor(message) {
|
|
|
|
|
this.message = message;
|
|
|
|
|
}
|
|
|
|
|
readBody() {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
let output = Buffer.alloc(0);
|
|
|
|
|
this.message.on('data', (chunk) => {
|
|
|
|
|
output = Buffer.concat([output, chunk]);
|
|
|
|
|
});
|
|
|
|
|
this.message.on('end', () => {
|
|
|
|
|
resolve(output.toString());
|
|
|
|
|
});
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.HttpClientResponse = HttpClientResponse;
|
|
|
|
|
function isHttps(requestUrl) {
|
|
|
|
|
const parsedUrl = new URL(requestUrl);
|
|
|
|
|
return parsedUrl.protocol === 'https:';
|
|
|
|
|
}
|
|
|
|
|
exports.isHttps = isHttps;
|
|
|
|
|
class HttpClient {
|
|
|
|
|
constructor(userAgent, handlers, requestOptions) {
|
|
|
|
|
this._ignoreSslError = false;
|
|
|
|
|
this._allowRedirects = true;
|
|
|
|
|
this._allowRedirectDowngrade = false;
|
|
|
|
|
this._maxRedirects = 50;
|
|
|
|
|
this._allowRetries = false;
|
|
|
|
|
this._maxRetries = 1;
|
|
|
|
|
this._keepAlive = false;
|
|
|
|
|
this._disposed = false;
|
|
|
|
|
this.userAgent = userAgent;
|
|
|
|
|
this.handlers = handlers || [];
|
|
|
|
|
this.requestOptions = requestOptions;
|
|
|
|
|
if (requestOptions) {
|
|
|
|
|
if (requestOptions.ignoreSslError != null) {
|
|
|
|
|
this._ignoreSslError = requestOptions.ignoreSslError;
|
|
|
|
|
}
|
|
|
|
|
this._socketTimeout = requestOptions.socketTimeout;
|
|
|
|
|
if (requestOptions.allowRedirects != null) {
|
|
|
|
|
this._allowRedirects = requestOptions.allowRedirects;
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.allowRedirectDowngrade != null) {
|
|
|
|
|
this._allowRedirectDowngrade = requestOptions.allowRedirectDowngrade;
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.maxRedirects != null) {
|
|
|
|
|
this._maxRedirects = Math.max(requestOptions.maxRedirects, 0);
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.keepAlive != null) {
|
|
|
|
|
this._keepAlive = requestOptions.keepAlive;
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.allowRetries != null) {
|
|
|
|
|
this._allowRetries = requestOptions.allowRetries;
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.maxRetries != null) {
|
|
|
|
|
this._maxRetries = requestOptions.maxRetries;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
options(requestUrl, additionalHeaders) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.request('OPTIONS', requestUrl, null, additionalHeaders || {});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
get(requestUrl, additionalHeaders) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.request('GET', requestUrl, null, additionalHeaders || {});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
del(requestUrl, additionalHeaders) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.request('DELETE', requestUrl, null, additionalHeaders || {});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
post(requestUrl, data, additionalHeaders) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.request('POST', requestUrl, data, additionalHeaders || {});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
patch(requestUrl, data, additionalHeaders) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.request('PATCH', requestUrl, data, additionalHeaders || {});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
put(requestUrl, data, additionalHeaders) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.request('PUT', requestUrl, data, additionalHeaders || {});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
head(requestUrl, additionalHeaders) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.request('HEAD', requestUrl, null, additionalHeaders || {});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
sendStream(verb, requestUrl, stream, additionalHeaders) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return this.request(verb, requestUrl, stream, additionalHeaders);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Gets a typed object from an endpoint
|
|
|
|
|
* Be aware that not found returns a null. Other errors (4xx, 5xx) reject the promise
|
|
|
|
|
*/
|
|
|
|
|
getJson(requestUrl, additionalHeaders = {}) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
additionalHeaders[Headers.Accept] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.Accept, MediaTypes.ApplicationJson);
|
|
|
|
|
const res = yield this.get(requestUrl, additionalHeaders);
|
|
|
|
|
return this._processResponse(res, this.requestOptions);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
postJson(requestUrl, obj, additionalHeaders = {}) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
const data = JSON.stringify(obj, null, 2);
|
|
|
|
|
additionalHeaders[Headers.Accept] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.Accept, MediaTypes.ApplicationJson);
|
|
|
|
|
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.ContentType, MediaTypes.ApplicationJson);
|
|
|
|
|
const res = yield this.post(requestUrl, data, additionalHeaders);
|
|
|
|
|
return this._processResponse(res, this.requestOptions);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
putJson(requestUrl, obj, additionalHeaders = {}) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
const data = JSON.stringify(obj, null, 2);
|
|
|
|
|
additionalHeaders[Headers.Accept] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.Accept, MediaTypes.ApplicationJson);
|
|
|
|
|
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.ContentType, MediaTypes.ApplicationJson);
|
|
|
|
|
const res = yield this.put(requestUrl, data, additionalHeaders);
|
|
|
|
|
return this._processResponse(res, this.requestOptions);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
patchJson(requestUrl, obj, additionalHeaders = {}) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
const data = JSON.stringify(obj, null, 2);
|
|
|
|
|
additionalHeaders[Headers.Accept] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.Accept, MediaTypes.ApplicationJson);
|
|
|
|
|
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.ContentType, MediaTypes.ApplicationJson);
|
|
|
|
|
const res = yield this.patch(requestUrl, data, additionalHeaders);
|
|
|
|
|
return this._processResponse(res, this.requestOptions);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Makes a raw http request.
|
|
|
|
|
* All other methods such as get, post, patch, and request ultimately call this.
|
|
|
|
|
* Prefer get, del, post and patch
|
|
|
|
|
*/
|
|
|
|
|
request(verb, requestUrl, data, headers) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
if (this._disposed) {
|
|
|
|
|
throw new Error('Client has already been disposed.');
|
|
|
|
|
}
|
|
|
|
|
const parsedUrl = new URL(requestUrl);
|
|
|
|
|
let info = this._prepareRequest(verb, parsedUrl, headers);
|
|
|
|
|
// Only perform retries on reads since writes may not be idempotent.
|
|
|
|
|
const maxTries = this._allowRetries && RetryableHttpVerbs.includes(verb)
|
|
|
|
|
? this._maxRetries + 1
|
|
|
|
|
: 1;
|
|
|
|
|
let numTries = 0;
|
|
|
|
|
let response;
|
|
|
|
|
do {
|
|
|
|
|
response = yield this.requestRaw(info, data);
|
|
|
|
|
// Check if it's an authentication challenge
|
|
|
|
|
if (response &&
|
|
|
|
|
response.message &&
|
|
|
|
|
response.message.statusCode === HttpCodes.Unauthorized) {
|
|
|
|
|
let authenticationHandler;
|
|
|
|
|
for (const handler of this.handlers) {
|
|
|
|
|
if (handler.canHandleAuthentication(response)) {
|
|
|
|
|
authenticationHandler = handler;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (authenticationHandler) {
|
|
|
|
|
return authenticationHandler.handleAuthentication(this, info, data);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// We have received an unauthorized response but have no handlers to handle it.
|
|
|
|
|
// Let the response return to the caller.
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let redirectsRemaining = this._maxRedirects;
|
|
|
|
|
while (response.message.statusCode &&
|
|
|
|
|
HttpRedirectCodes.includes(response.message.statusCode) &&
|
|
|
|
|
this._allowRedirects &&
|
|
|
|
|
redirectsRemaining > 0) {
|
|
|
|
|
const redirectUrl = response.message.headers['location'];
|
|
|
|
|
if (!redirectUrl) {
|
|
|
|
|
// if there's no location to redirect to, we won't
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
const parsedRedirectUrl = new URL(redirectUrl);
|
|
|
|
|
if (parsedUrl.protocol === 'https:' &&
|
|
|
|
|
parsedUrl.protocol !== parsedRedirectUrl.protocol &&
|
|
|
|
|
!this._allowRedirectDowngrade) {
|
|
|
|
|
throw new Error('Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.');
|
|
|
|
|
}
|
|
|
|
|
// we need to finish reading the response before reassigning response
|
|
|
|
|
// which will leak the open socket.
|
|
|
|
|
yield response.readBody();
|
|
|
|
|
// strip authorization header if redirected to a different hostname
|
|
|
|
|
if (parsedRedirectUrl.hostname !== parsedUrl.hostname) {
|
|
|
|
|
for (const header in headers) {
|
|
|
|
|
// header names are case insensitive
|
|
|
|
|
if (header.toLowerCase() === 'authorization') {
|
|
|
|
|
delete headers[header];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// let's make the request with the new redirectUrl
|
|
|
|
|
info = this._prepareRequest(verb, parsedRedirectUrl, headers);
|
|
|
|
|
response = yield this.requestRaw(info, data);
|
|
|
|
|
redirectsRemaining--;
|
|
|
|
|
}
|
|
|
|
|
if (!response.message.statusCode ||
|
|
|
|
|
!HttpResponseRetryCodes.includes(response.message.statusCode)) {
|
|
|
|
|
// If not a retry code, return immediately instead of retrying
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
numTries += 1;
|
|
|
|
|
if (numTries < maxTries) {
|
|
|
|
|
yield response.readBody();
|
|
|
|
|
yield this._performExponentialBackoff(numTries);
|
|
|
|
|
}
|
|
|
|
|
} while (numTries < maxTries);
|
|
|
|
|
return response;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Needs to be called if keepAlive is set to true in request options.
|
|
|
|
|
*/
|
|
|
|
|
dispose() {
|
|
|
|
|
if (this._agent) {
|
|
|
|
|
this._agent.destroy();
|
|
|
|
|
}
|
|
|
|
|
this._disposed = true;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Raw request.
|
|
|
|
|
* @param info
|
|
|
|
|
* @param data
|
|
|
|
|
*/
|
|
|
|
|
requestRaw(info, data) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
function callbackForResult(err, res) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
}
|
|
|
|
|
else if (!res) {
|
|
|
|
|
// If `err` is not passed, then `res` must be passed.
|
|
|
|
|
reject(new Error('Unknown error'));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
resolve(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.requestRawWithCallback(info, data, callbackForResult);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Raw request with callback.
|
|
|
|
|
* @param info
|
|
|
|
|
* @param data
|
|
|
|
|
* @param onResult
|
|
|
|
|
*/
|
|
|
|
|
requestRawWithCallback(info, data, onResult) {
|
|
|
|
|
if (typeof data === 'string') {
|
|
|
|
|
if (!info.options.headers) {
|
|
|
|
|
info.options.headers = {};
|
|
|
|
|
}
|
|
|
|
|
info.options.headers['Content-Length'] = Buffer.byteLength(data, 'utf8');
|
|
|
|
|
}
|
|
|
|
|
let callbackCalled = false;
|
|
|
|
|
function handleResult(err, res) {
|
|
|
|
|
if (!callbackCalled) {
|
|
|
|
|
callbackCalled = true;
|
|
|
|
|
onResult(err, res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const req = info.httpModule.request(info.options, (msg) => {
|
|
|
|
|
const res = new HttpClientResponse(msg);
|
|
|
|
|
handleResult(undefined, res);
|
|
|
|
|
});
|
|
|
|
|
let socket;
|
|
|
|
|
req.on('socket', sock => {
|
|
|
|
|
socket = sock;
|
|
|
|
|
});
|
|
|
|
|
// If we ever get disconnected, we want the socket to timeout eventually
|
|
|
|
|
req.setTimeout(this._socketTimeout || 3 * 60000, () => {
|
|
|
|
|
if (socket) {
|
|
|
|
|
socket.end();
|
|
|
|
|
}
|
|
|
|
|
handleResult(new Error(`Request timeout: ${info.options.path}`));
|
|
|
|
|
});
|
|
|
|
|
req.on('error', function (err) {
|
|
|
|
|
// err has statusCode property
|
|
|
|
|
// res should have headers
|
|
|
|
|
handleResult(err);
|
|
|
|
|
});
|
|
|
|
|
if (data && typeof data === 'string') {
|
|
|
|
|
req.write(data, 'utf8');
|
|
|
|
|
}
|
|
|
|
|
if (data && typeof data !== 'string') {
|
|
|
|
|
data.on('close', function () {
|
|
|
|
|
req.end();
|
|
|
|
|
});
|
|
|
|
|
data.pipe(req);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
req.end();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Gets an http agent. This function is useful when you need an http agent that handles
|
|
|
|
|
* routing through a proxy server - depending upon the url and proxy environment variables.
|
|
|
|
|
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
|
|
|
|
*/
|
|
|
|
|
getAgent(serverUrl) {
|
|
|
|
|
const parsedUrl = new URL(serverUrl);
|
|
|
|
|
return this._getAgent(parsedUrl);
|
|
|
|
|
}
|
|
|
|
|
_prepareRequest(method, requestUrl, headers) {
|
|
|
|
|
const info = {};
|
|
|
|
|
info.parsedUrl = requestUrl;
|
|
|
|
|
const usingSsl = info.parsedUrl.protocol === 'https:';
|
|
|
|
|
info.httpModule = usingSsl ? https : http;
|
|
|
|
|
const defaultPort = usingSsl ? 443 : 80;
|
|
|
|
|
info.options = {};
|
|
|
|
|
info.options.host = info.parsedUrl.hostname;
|
|
|
|
|
info.options.port = info.parsedUrl.port
|
|
|
|
|
? parseInt(info.parsedUrl.port)
|
|
|
|
|
: defaultPort;
|
|
|
|
|
info.options.path =
|
|
|
|
|
(info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
|
|
|
|
|
info.options.method = method;
|
|
|
|
|
info.options.headers = this._mergeHeaders(headers);
|
|
|
|
|
if (this.userAgent != null) {
|
|
|
|
|
info.options.headers['user-agent'] = this.userAgent;
|
|
|
|
|
}
|
|
|
|
|
info.options.agent = this._getAgent(info.parsedUrl);
|
|
|
|
|
// gives handlers an opportunity to participate
|
|
|
|
|
if (this.handlers) {
|
|
|
|
|
for (const handler of this.handlers) {
|
|
|
|
|
handler.prepareRequest(info.options);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
_mergeHeaders(headers) {
|
|
|
|
|
if (this.requestOptions && this.requestOptions.headers) {
|
|
|
|
|
return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers || {}));
|
|
|
|
|
}
|
|
|
|
|
return lowercaseKeys(headers || {});
|
|
|
|
|
}
|
|
|
|
|
_getExistingOrDefaultHeader(additionalHeaders, header, _default) {
|
|
|
|
|
let clientHeader;
|
|
|
|
|
if (this.requestOptions && this.requestOptions.headers) {
|
|
|
|
|
clientHeader = lowercaseKeys(this.requestOptions.headers)[header];
|
|
|
|
|
}
|
|
|
|
|
return additionalHeaders[header] || clientHeader || _default;
|
|
|
|
|
}
|
|
|
|
|
_getAgent(parsedUrl) {
|
|
|
|
|
let agent;
|
|
|
|
|
const proxyUrl = pm.getProxyUrl(parsedUrl);
|
|
|
|
|
const useProxy = proxyUrl && proxyUrl.hostname;
|
|
|
|
|
if (this._keepAlive && useProxy) {
|
|
|
|
|
agent = this._proxyAgent;
|
|
|
|
|
}
|
|
|
|
|
if (this._keepAlive && !useProxy) {
|
|
|
|
|
agent = this._agent;
|
|
|
|
|
}
|
|
|
|
|
// if agent is already assigned use that agent.
|
|
|
|
|
if (agent) {
|
|
|
|
|
return agent;
|
|
|
|
|
}
|
|
|
|
|
const usingSsl = parsedUrl.protocol === 'https:';
|
|
|
|
|
let maxSockets = 100;
|
|
|
|
|
if (this.requestOptions) {
|
|
|
|
|
maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets;
|
|
|
|
|
}
|
|
|
|
|
// This is `useProxy` again, but we need to check `proxyURl` directly for TypeScripts's flow analysis.
|
|
|
|
|
if (proxyUrl && proxyUrl.hostname) {
|
|
|
|
|
const agentOptions = {
|
|
|
|
|
maxSockets,
|
|
|
|
|
keepAlive: this._keepAlive,
|
|
|
|
|
proxy: Object.assign(Object.assign({}, ((proxyUrl.username || proxyUrl.password) && {
|
|
|
|
|
proxyAuth: `${proxyUrl.username}:${proxyUrl.password}`
|
|
|
|
|
})), { host: proxyUrl.hostname, port: proxyUrl.port })
|
|
|
|
|
};
|
|
|
|
|
let tunnelAgent;
|
|
|
|
|
const overHttps = proxyUrl.protocol === 'https:';
|
|
|
|
|
if (usingSsl) {
|
|
|
|
|
tunnelAgent = overHttps ? tunnel.httpsOverHttps : tunnel.httpsOverHttp;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
tunnelAgent = overHttps ? tunnel.httpOverHttps : tunnel.httpOverHttp;
|
|
|
|
|
}
|
|
|
|
|
agent = tunnelAgent(agentOptions);
|
|
|
|
|
this._proxyAgent = agent;
|
|
|
|
|
}
|
|
|
|
|
// if reusing agent across request and tunneling agent isn't assigned create a new agent
|
|
|
|
|
if (this._keepAlive && !agent) {
|
|
|
|
|
const options = { keepAlive: this._keepAlive, maxSockets };
|
|
|
|
|
agent = usingSsl ? new https.Agent(options) : new http.Agent(options);
|
|
|
|
|
this._agent = agent;
|
|
|
|
|
}
|
|
|
|
|
// if not using private agent and tunnel agent isn't setup then use global agent
|
|
|
|
|
if (!agent) {
|
|
|
|
|
agent = usingSsl ? https.globalAgent : http.globalAgent;
|
|
|
|
|
}
|
|
|
|
|
if (usingSsl && this._ignoreSslError) {
|
|
|
|
|
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
|
|
|
|
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
|
|
|
|
// we have to cast it to any and change it directly
|
|
|
|
|
agent.options = Object.assign(agent.options || {}, {
|
|
|
|
|
rejectUnauthorized: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return agent;
|
|
|
|
|
}
|
|
|
|
|
_performExponentialBackoff(retryNumber) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber);
|
|
|
|
|
const ms = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber);
|
|
|
|
|
return new Promise(resolve => setTimeout(() => resolve(), ms));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
_processResponse(res, options) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
const statusCode = res.message.statusCode || 0;
|
|
|
|
|
const response = {
|
|
|
|
|
statusCode,
|
|
|
|
|
result: null,
|
|
|
|
|
headers: {}
|
|
|
|
|
};
|
|
|
|
|
// not found leads to null obj returned
|
|
|
|
|
if (statusCode === HttpCodes.NotFound) {
|
|
|
|
|
resolve(response);
|
|
|
|
|
}
|
|
|
|
|
// get the result from the body
|
|
|
|
|
function dateTimeDeserializer(key, value) {
|
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
|
const a = new Date(value);
|
|
|
|
|
if (!isNaN(a.valueOf())) {
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
let obj;
|
|
|
|
|
let contents;
|
|
|
|
|
try {
|
|
|
|
|
contents = yield res.readBody();
|
|
|
|
|
if (contents && contents.length > 0) {
|
|
|
|
|
if (options && options.deserializeDates) {
|
|
|
|
|
obj = JSON.parse(contents, dateTimeDeserializer);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
obj = JSON.parse(contents);
|
|
|
|
|
}
|
|
|
|
|
response.result = obj;
|
|
|
|
|
}
|
|
|
|
|
response.headers = res.message.headers;
|
|
|
|
|
}
|
|
|
|
|
catch (err) {
|
|
|
|
|
// Invalid resource (contents not json); leaving result obj null
|
|
|
|
|
}
|
|
|
|
|
// note that 3xx redirects are handled by the http layer.
|
|
|
|
|
if (statusCode > 299) {
|
|
|
|
|
let msg;
|
|
|
|
|
// if exception/error in body, attempt to get better error
|
|
|
|
|
if (obj && obj.message) {
|
|
|
|
|
msg = obj.message;
|
|
|
|
|
}
|
|
|
|
|
else if (contents && contents.length > 0) {
|
|
|
|
|
// it may be the case that the exception is in the body message as string
|
|
|
|
|
msg = contents;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
msg = `Failed request: (${statusCode})`;
|
|
|
|
|
}
|
|
|
|
|
const err = new HttpClientError(msg, statusCode);
|
|
|
|
|
err.result = response.result;
|
|
|
|
|
reject(err);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
resolve(response);
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.HttpClient = HttpClient;
|
|
|
|
|
const lowercaseKeys = (obj) => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {});
|
|
|
|
|
//# sourceMappingURL=index.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 431:
|
|
|
|
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
@@ -5061,6 +6388,7 @@ function escapeProperty(s) {
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.HttpManager = void 0;
|
|
|
|
|
const utils_1 = __webpack_require__(870);
|
|
|
|
|
/**
|
|
|
|
|
* Used for managing http clients during either upload or download
|
|
|
|
@@ -5343,6 +6671,25 @@ exports.getState = getState;
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
@@ -5352,14 +6699,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
|
result["default"] = mod;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.retryHttpClientRequest = exports.retry = void 0;
|
|
|
|
|
const utils_1 = __webpack_require__(870);
|
|
|
|
|
const core = __importStar(__webpack_require__(470));
|
|
|
|
|
const config_variables_1 = __webpack_require__(401);
|
|
|
|
@@ -5425,14 +6766,27 @@ exports.retryHttpClientRequest = retryHttpClientRequest;
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
|
result["default"] = mod;
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.getDownloadSpecification = void 0;
|
|
|
|
|
const path = __importStar(__webpack_require__(622));
|
|
|
|
|
/**
|
|
|
|
|
* Creates a specification for a set of files that will be downloaded
|
|
|
|
@@ -5488,919 +6842,165 @@ exports.getDownloadSpecification = getDownloadSpecification;
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 539:
|
|
|
|
|
/***/ 553:
|
|
|
|
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
const http = __webpack_require__(605);
|
|
|
|
|
const https = __webpack_require__(211);
|
|
|
|
|
const pm = __webpack_require__(950);
|
|
|
|
|
let tunnel;
|
|
|
|
|
var HttpCodes;
|
|
|
|
|
(function (HttpCodes) {
|
|
|
|
|
HttpCodes[HttpCodes["OK"] = 200] = "OK";
|
|
|
|
|
HttpCodes[HttpCodes["MultipleChoices"] = 300] = "MultipleChoices";
|
|
|
|
|
HttpCodes[HttpCodes["MovedPermanently"] = 301] = "MovedPermanently";
|
|
|
|
|
HttpCodes[HttpCodes["ResourceMoved"] = 302] = "ResourceMoved";
|
|
|
|
|
HttpCodes[HttpCodes["SeeOther"] = 303] = "SeeOther";
|
|
|
|
|
HttpCodes[HttpCodes["NotModified"] = 304] = "NotModified";
|
|
|
|
|
HttpCodes[HttpCodes["UseProxy"] = 305] = "UseProxy";
|
|
|
|
|
HttpCodes[HttpCodes["SwitchProxy"] = 306] = "SwitchProxy";
|
|
|
|
|
HttpCodes[HttpCodes["TemporaryRedirect"] = 307] = "TemporaryRedirect";
|
|
|
|
|
HttpCodes[HttpCodes["PermanentRedirect"] = 308] = "PermanentRedirect";
|
|
|
|
|
HttpCodes[HttpCodes["BadRequest"] = 400] = "BadRequest";
|
|
|
|
|
HttpCodes[HttpCodes["Unauthorized"] = 401] = "Unauthorized";
|
|
|
|
|
HttpCodes[HttpCodes["PaymentRequired"] = 402] = "PaymentRequired";
|
|
|
|
|
HttpCodes[HttpCodes["Forbidden"] = 403] = "Forbidden";
|
|
|
|
|
HttpCodes[HttpCodes["NotFound"] = 404] = "NotFound";
|
|
|
|
|
HttpCodes[HttpCodes["MethodNotAllowed"] = 405] = "MethodNotAllowed";
|
|
|
|
|
HttpCodes[HttpCodes["NotAcceptable"] = 406] = "NotAcceptable";
|
|
|
|
|
HttpCodes[HttpCodes["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
|
|
|
|
|
HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout";
|
|
|
|
|
HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict";
|
|
|
|
|
HttpCodes[HttpCodes["Gone"] = 410] = "Gone";
|
|
|
|
|
HttpCodes[HttpCodes["TooManyRequests"] = 429] = "TooManyRequests";
|
|
|
|
|
HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError";
|
|
|
|
|
HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented";
|
|
|
|
|
HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway";
|
|
|
|
|
HttpCodes[HttpCodes["ServiceUnavailable"] = 503] = "ServiceUnavailable";
|
|
|
|
|
HttpCodes[HttpCodes["GatewayTimeout"] = 504] = "GatewayTimeout";
|
|
|
|
|
})(HttpCodes = exports.HttpCodes || (exports.HttpCodes = {}));
|
|
|
|
|
var Headers;
|
|
|
|
|
(function (Headers) {
|
|
|
|
|
Headers["Accept"] = "accept";
|
|
|
|
|
Headers["ContentType"] = "content-type";
|
|
|
|
|
})(Headers = exports.Headers || (exports.Headers = {}));
|
|
|
|
|
var MediaTypes;
|
|
|
|
|
(function (MediaTypes) {
|
|
|
|
|
MediaTypes["ApplicationJson"] = "application/json";
|
|
|
|
|
})(MediaTypes = exports.MediaTypes || (exports.MediaTypes = {}));
|
|
|
|
|
exports.checkArtifactFilePath = exports.checkArtifactName = void 0;
|
|
|
|
|
const core_1 = __webpack_require__(470);
|
|
|
|
|
/**
|
|
|
|
|
* Returns the proxy URL, depending upon the supplied url and proxy environment variables.
|
|
|
|
|
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
|
|
|
|
* Invalid characters that cannot be in the artifact name or an uploaded file. Will be rejected
|
|
|
|
|
* from the server if attempted to be sent over. These characters are not allowed due to limitations with certain
|
|
|
|
|
* file systems such as NTFS. To maintain platform-agnostic behavior, all characters that are not supported by an
|
|
|
|
|
* individual filesystem/platform will not be supported on all fileSystems/platforms
|
|
|
|
|
*
|
|
|
|
|
* FilePaths can include characters such as \ and / which are not permitted in the artifact name alone
|
|
|
|
|
*/
|
|
|
|
|
function getProxyUrl(serverUrl) {
|
|
|
|
|
let proxyUrl = pm.getProxyUrl(new URL(serverUrl));
|
|
|
|
|
return proxyUrl ? proxyUrl.href : '';
|
|
|
|
|
const invalidArtifactFilePathCharacters = new Map([
|
|
|
|
|
['"', ' Double quote "'],
|
|
|
|
|
[':', ' Colon :'],
|
|
|
|
|
['<', ' Less than <'],
|
|
|
|
|
['>', ' Greater than >'],
|
|
|
|
|
['|', ' Vertical bar |'],
|
|
|
|
|
['*', ' Asterisk *'],
|
|
|
|
|
['?', ' Question mark ?'],
|
|
|
|
|
['\r', ' Carriage return \\r'],
|
|
|
|
|
['\n', ' Line feed \\n']
|
|
|
|
|
]);
|
|
|
|
|
const invalidArtifactNameCharacters = new Map([
|
|
|
|
|
...invalidArtifactFilePathCharacters,
|
|
|
|
|
['\\', ' Backslash \\'],
|
|
|
|
|
['/', ' Forward slash /']
|
|
|
|
|
]);
|
|
|
|
|
/**
|
|
|
|
|
* Scans the name of the artifact to make sure there are no illegal characters
|
|
|
|
|
*/
|
|
|
|
|
function checkArtifactName(name) {
|
|
|
|
|
if (!name) {
|
|
|
|
|
throw new Error(`Artifact name: ${name}, is incorrectly provided`);
|
|
|
|
|
}
|
|
|
|
|
for (const [invalidCharacterKey, errorMessageForCharacter] of invalidArtifactNameCharacters) {
|
|
|
|
|
if (name.includes(invalidCharacterKey)) {
|
|
|
|
|
throw new Error(`Artifact name is not valid: ${name}. Contains the following character: ${errorMessageForCharacter}
|
|
|
|
|
|
|
|
|
|
Invalid characters include: ${Array.from(invalidArtifactNameCharacters.values()).toString()}
|
|
|
|
|
|
|
|
|
|
These characters are not allowed in the artifact name due to limitations with certain file systems such as NTFS. To maintain file system agnostic behavior, these characters are intentionally not allowed to prevent potential problems with downloads on different file systems.`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
core_1.info(`Artifact name is valid!`);
|
|
|
|
|
}
|
|
|
|
|
exports.getProxyUrl = getProxyUrl;
|
|
|
|
|
const HttpRedirectCodes = [
|
|
|
|
|
HttpCodes.MovedPermanently,
|
|
|
|
|
HttpCodes.ResourceMoved,
|
|
|
|
|
HttpCodes.SeeOther,
|
|
|
|
|
HttpCodes.TemporaryRedirect,
|
|
|
|
|
HttpCodes.PermanentRedirect
|
|
|
|
|
];
|
|
|
|
|
const HttpResponseRetryCodes = [
|
|
|
|
|
HttpCodes.BadGateway,
|
|
|
|
|
HttpCodes.ServiceUnavailable,
|
|
|
|
|
HttpCodes.GatewayTimeout
|
|
|
|
|
];
|
|
|
|
|
const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD'];
|
|
|
|
|
const ExponentialBackoffCeiling = 10;
|
|
|
|
|
const ExponentialBackoffTimeSlice = 5;
|
|
|
|
|
class HttpClientError extends Error {
|
|
|
|
|
constructor(message, statusCode) {
|
|
|
|
|
super(message);
|
|
|
|
|
this.name = 'HttpClientError';
|
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
|
Object.setPrototypeOf(this, HttpClientError.prototype);
|
|
|
|
|
exports.checkArtifactName = checkArtifactName;
|
|
|
|
|
/**
|
|
|
|
|
* Scans the name of the filePath used to make sure there are no illegal characters
|
|
|
|
|
*/
|
|
|
|
|
function checkArtifactFilePath(path) {
|
|
|
|
|
if (!path) {
|
|
|
|
|
throw new Error(`Artifact path: ${path}, is incorrectly provided`);
|
|
|
|
|
}
|
|
|
|
|
for (const [invalidCharacterKey, errorMessageForCharacter] of invalidArtifactFilePathCharacters) {
|
|
|
|
|
if (path.includes(invalidCharacterKey)) {
|
|
|
|
|
throw new Error(`Artifact path is not valid: ${path}. Contains the following character: ${errorMessageForCharacter}
|
|
|
|
|
|
|
|
|
|
Invalid characters include: ${Array.from(invalidArtifactFilePathCharacters.values()).toString()}
|
|
|
|
|
|
|
|
|
|
The following characters are not allowed in files that are uploaded due to limitations with certain file systems such as NTFS. To maintain file system agnostic behavior, these characters are intentionally not allowed to prevent potential problems with downloads on different file systems.
|
|
|
|
|
`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.HttpClientError = HttpClientError;
|
|
|
|
|
class HttpClientResponse {
|
|
|
|
|
constructor(message) {
|
|
|
|
|
this.message = message;
|
|
|
|
|
}
|
|
|
|
|
readBody() {
|
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
let output = Buffer.alloc(0);
|
|
|
|
|
this.message.on('data', (chunk) => {
|
|
|
|
|
output = Buffer.concat([output, chunk]);
|
|
|
|
|
});
|
|
|
|
|
this.message.on('end', () => {
|
|
|
|
|
resolve(output.toString());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.HttpClientResponse = HttpClientResponse;
|
|
|
|
|
function isHttps(requestUrl) {
|
|
|
|
|
let parsedUrl = new URL(requestUrl);
|
|
|
|
|
return parsedUrl.protocol === 'https:';
|
|
|
|
|
}
|
|
|
|
|
exports.isHttps = isHttps;
|
|
|
|
|
class HttpClient {
|
|
|
|
|
constructor(userAgent, handlers, requestOptions) {
|
|
|
|
|
this._ignoreSslError = false;
|
|
|
|
|
this._allowRedirects = true;
|
|
|
|
|
this._allowRedirectDowngrade = false;
|
|
|
|
|
this._maxRedirects = 50;
|
|
|
|
|
this._allowRetries = false;
|
|
|
|
|
this._maxRetries = 1;
|
|
|
|
|
this._keepAlive = false;
|
|
|
|
|
this._disposed = false;
|
|
|
|
|
this.userAgent = userAgent;
|
|
|
|
|
this.handlers = handlers || [];
|
|
|
|
|
this.requestOptions = requestOptions;
|
|
|
|
|
if (requestOptions) {
|
|
|
|
|
if (requestOptions.ignoreSslError != null) {
|
|
|
|
|
this._ignoreSslError = requestOptions.ignoreSslError;
|
|
|
|
|
}
|
|
|
|
|
this._socketTimeout = requestOptions.socketTimeout;
|
|
|
|
|
if (requestOptions.allowRedirects != null) {
|
|
|
|
|
this._allowRedirects = requestOptions.allowRedirects;
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.allowRedirectDowngrade != null) {
|
|
|
|
|
this._allowRedirectDowngrade = requestOptions.allowRedirectDowngrade;
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.maxRedirects != null) {
|
|
|
|
|
this._maxRedirects = Math.max(requestOptions.maxRedirects, 0);
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.keepAlive != null) {
|
|
|
|
|
this._keepAlive = requestOptions.keepAlive;
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.allowRetries != null) {
|
|
|
|
|
this._allowRetries = requestOptions.allowRetries;
|
|
|
|
|
}
|
|
|
|
|
if (requestOptions.maxRetries != null) {
|
|
|
|
|
this._maxRetries = requestOptions.maxRetries;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
options(requestUrl, additionalHeaders) {
|
|
|
|
|
return this.request('OPTIONS', requestUrl, null, additionalHeaders || {});
|
|
|
|
|
}
|
|
|
|
|
get(requestUrl, additionalHeaders) {
|
|
|
|
|
return this.request('GET', requestUrl, null, additionalHeaders || {});
|
|
|
|
|
}
|
|
|
|
|
del(requestUrl, additionalHeaders) {
|
|
|
|
|
return this.request('DELETE', requestUrl, null, additionalHeaders || {});
|
|
|
|
|
}
|
|
|
|
|
post(requestUrl, data, additionalHeaders) {
|
|
|
|
|
return this.request('POST', requestUrl, data, additionalHeaders || {});
|
|
|
|
|
}
|
|
|
|
|
patch(requestUrl, data, additionalHeaders) {
|
|
|
|
|
return this.request('PATCH', requestUrl, data, additionalHeaders || {});
|
|
|
|
|
}
|
|
|
|
|
put(requestUrl, data, additionalHeaders) {
|
|
|
|
|
return this.request('PUT', requestUrl, data, additionalHeaders || {});
|
|
|
|
|
}
|
|
|
|
|
head(requestUrl, additionalHeaders) {
|
|
|
|
|
return this.request('HEAD', requestUrl, null, additionalHeaders || {});
|
|
|
|
|
}
|
|
|
|
|
sendStream(verb, requestUrl, stream, additionalHeaders) {
|
|
|
|
|
return this.request(verb, requestUrl, stream, additionalHeaders);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Gets a typed object from an endpoint
|
|
|
|
|
* Be aware that not found returns a null. Other errors (4xx, 5xx) reject the promise
|
|
|
|
|
*/
|
|
|
|
|
async getJson(requestUrl, additionalHeaders = {}) {
|
|
|
|
|
additionalHeaders[Headers.Accept] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.Accept, MediaTypes.ApplicationJson);
|
|
|
|
|
let res = await this.get(requestUrl, additionalHeaders);
|
|
|
|
|
return this._processResponse(res, this.requestOptions);
|
|
|
|
|
}
|
|
|
|
|
async postJson(requestUrl, obj, additionalHeaders = {}) {
|
|
|
|
|
let data = JSON.stringify(obj, null, 2);
|
|
|
|
|
additionalHeaders[Headers.Accept] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.Accept, MediaTypes.ApplicationJson);
|
|
|
|
|
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.ContentType, MediaTypes.ApplicationJson);
|
|
|
|
|
let res = await this.post(requestUrl, data, additionalHeaders);
|
|
|
|
|
return this._processResponse(res, this.requestOptions);
|
|
|
|
|
}
|
|
|
|
|
async putJson(requestUrl, obj, additionalHeaders = {}) {
|
|
|
|
|
let data = JSON.stringify(obj, null, 2);
|
|
|
|
|
additionalHeaders[Headers.Accept] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.Accept, MediaTypes.ApplicationJson);
|
|
|
|
|
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.ContentType, MediaTypes.ApplicationJson);
|
|
|
|
|
let res = await this.put(requestUrl, data, additionalHeaders);
|
|
|
|
|
return this._processResponse(res, this.requestOptions);
|
|
|
|
|
}
|
|
|
|
|
async patchJson(requestUrl, obj, additionalHeaders = {}) {
|
|
|
|
|
let data = JSON.stringify(obj, null, 2);
|
|
|
|
|
additionalHeaders[Headers.Accept] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.Accept, MediaTypes.ApplicationJson);
|
|
|
|
|
additionalHeaders[Headers.ContentType] = this._getExistingOrDefaultHeader(additionalHeaders, Headers.ContentType, MediaTypes.ApplicationJson);
|
|
|
|
|
let res = await this.patch(requestUrl, data, additionalHeaders);
|
|
|
|
|
return this._processResponse(res, this.requestOptions);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Makes a raw http request.
|
|
|
|
|
* All other methods such as get, post, patch, and request ultimately call this.
|
|
|
|
|
* Prefer get, del, post and patch
|
|
|
|
|
*/
|
|
|
|
|
async request(verb, requestUrl, data, headers) {
|
|
|
|
|
if (this._disposed) {
|
|
|
|
|
throw new Error('Client has already been disposed.');
|
|
|
|
|
}
|
|
|
|
|
let parsedUrl = new URL(requestUrl);
|
|
|
|
|
let info = this._prepareRequest(verb, parsedUrl, headers);
|
|
|
|
|
// Only perform retries on reads since writes may not be idempotent.
|
|
|
|
|
let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1
|
|
|
|
|
? this._maxRetries + 1
|
|
|
|
|
: 1;
|
|
|
|
|
let numTries = 0;
|
|
|
|
|
let response;
|
|
|
|
|
while (numTries < maxTries) {
|
|
|
|
|
response = await this.requestRaw(info, data);
|
|
|
|
|
// Check if it's an authentication challenge
|
|
|
|
|
if (response &&
|
|
|
|
|
response.message &&
|
|
|
|
|
response.message.statusCode === HttpCodes.Unauthorized) {
|
|
|
|
|
let authenticationHandler;
|
|
|
|
|
for (let i = 0; i < this.handlers.length; i++) {
|
|
|
|
|
if (this.handlers[i].canHandleAuthentication(response)) {
|
|
|
|
|
authenticationHandler = this.handlers[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (authenticationHandler) {
|
|
|
|
|
return authenticationHandler.handleAuthentication(this, info, data);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// We have received an unauthorized response but have no handlers to handle it.
|
|
|
|
|
// Let the response return to the caller.
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let redirectsRemaining = this._maxRedirects;
|
|
|
|
|
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 &&
|
|
|
|
|
this._allowRedirects &&
|
|
|
|
|
redirectsRemaining > 0) {
|
|
|
|
|
const redirectUrl = response.message.headers['location'];
|
|
|
|
|
if (!redirectUrl) {
|
|
|
|
|
// if there's no location to redirect to, we won't
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
let parsedRedirectUrl = new URL(redirectUrl);
|
|
|
|
|
if (parsedUrl.protocol == 'https:' &&
|
|
|
|
|
parsedUrl.protocol != parsedRedirectUrl.protocol &&
|
|
|
|
|
!this._allowRedirectDowngrade) {
|
|
|
|
|
throw new Error('Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.');
|
|
|
|
|
}
|
|
|
|
|
// we need to finish reading the response before reassigning response
|
|
|
|
|
// which will leak the open socket.
|
|
|
|
|
await response.readBody();
|
|
|
|
|
// strip authorization header if redirected to a different hostname
|
|
|
|
|
if (parsedRedirectUrl.hostname !== parsedUrl.hostname) {
|
|
|
|
|
for (let header in headers) {
|
|
|
|
|
// header names are case insensitive
|
|
|
|
|
if (header.toLowerCase() === 'authorization') {
|
|
|
|
|
delete headers[header];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// let's make the request with the new redirectUrl
|
|
|
|
|
info = this._prepareRequest(verb, parsedRedirectUrl, headers);
|
|
|
|
|
response = await this.requestRaw(info, data);
|
|
|
|
|
redirectsRemaining--;
|
|
|
|
|
}
|
|
|
|
|
if (HttpResponseRetryCodes.indexOf(response.message.statusCode) == -1) {
|
|
|
|
|
// If not a retry code, return immediately instead of retrying
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
numTries += 1;
|
|
|
|
|
if (numTries < maxTries) {
|
|
|
|
|
await response.readBody();
|
|
|
|
|
await this._performExponentialBackoff(numTries);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Needs to be called if keepAlive is set to true in request options.
|
|
|
|
|
*/
|
|
|
|
|
dispose() {
|
|
|
|
|
if (this._agent) {
|
|
|
|
|
this._agent.destroy();
|
|
|
|
|
}
|
|
|
|
|
this._disposed = true;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Raw request.
|
|
|
|
|
* @param info
|
|
|
|
|
* @param data
|
|
|
|
|
*/
|
|
|
|
|
requestRaw(info, data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let callbackForResult = function (err, res) {
|
|
|
|
|
if (err) {
|
|
|
|
|
reject(err);
|
|
|
|
|
}
|
|
|
|
|
resolve(res);
|
|
|
|
|
};
|
|
|
|
|
this.requestRawWithCallback(info, data, callbackForResult);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Raw request with callback.
|
|
|
|
|
* @param info
|
|
|
|
|
* @param data
|
|
|
|
|
* @param onResult
|
|
|
|
|
*/
|
|
|
|
|
requestRawWithCallback(info, data, onResult) {
|
|
|
|
|
let socket;
|
|
|
|
|
if (typeof data === 'string') {
|
|
|
|
|
info.options.headers['Content-Length'] = Buffer.byteLength(data, 'utf8');
|
|
|
|
|
}
|
|
|
|
|
let callbackCalled = false;
|
|
|
|
|
let handleResult = (err, res) => {
|
|
|
|
|
if (!callbackCalled) {
|
|
|
|
|
callbackCalled = true;
|
|
|
|
|
onResult(err, res);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let req = info.httpModule.request(info.options, (msg) => {
|
|
|
|
|
let res = new HttpClientResponse(msg);
|
|
|
|
|
handleResult(null, res);
|
|
|
|
|
});
|
|
|
|
|
req.on('socket', sock => {
|
|
|
|
|
socket = sock;
|
|
|
|
|
});
|
|
|
|
|
// If we ever get disconnected, we want the socket to timeout eventually
|
|
|
|
|
req.setTimeout(this._socketTimeout || 3 * 60000, () => {
|
|
|
|
|
if (socket) {
|
|
|
|
|
socket.end();
|
|
|
|
|
}
|
|
|
|
|
handleResult(new Error('Request timeout: ' + info.options.path), null);
|
|
|
|
|
});
|
|
|
|
|
req.on('error', function (err) {
|
|
|
|
|
// err has statusCode property
|
|
|
|
|
// res should have headers
|
|
|
|
|
handleResult(err, null);
|
|
|
|
|
});
|
|
|
|
|
if (data && typeof data === 'string') {
|
|
|
|
|
req.write(data, 'utf8');
|
|
|
|
|
}
|
|
|
|
|
if (data && typeof data !== 'string') {
|
|
|
|
|
data.on('close', function () {
|
|
|
|
|
req.end();
|
|
|
|
|
});
|
|
|
|
|
data.pipe(req);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
req.end();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Gets an http agent. This function is useful when you need an http agent that handles
|
|
|
|
|
* routing through a proxy server - depending upon the url and proxy environment variables.
|
|
|
|
|
* @param serverUrl The server URL where the request will be sent. For example, https://api.github.com
|
|
|
|
|
*/
|
|
|
|
|
getAgent(serverUrl) {
|
|
|
|
|
let parsedUrl = new URL(serverUrl);
|
|
|
|
|
return this._getAgent(parsedUrl);
|
|
|
|
|
}
|
|
|
|
|
_prepareRequest(method, requestUrl, headers) {
|
|
|
|
|
const info = {};
|
|
|
|
|
info.parsedUrl = requestUrl;
|
|
|
|
|
const usingSsl = info.parsedUrl.protocol === 'https:';
|
|
|
|
|
info.httpModule = usingSsl ? https : http;
|
|
|
|
|
const defaultPort = usingSsl ? 443 : 80;
|
|
|
|
|
info.options = {};
|
|
|
|
|
info.options.host = info.parsedUrl.hostname;
|
|
|
|
|
info.options.port = info.parsedUrl.port
|
|
|
|
|
? parseInt(info.parsedUrl.port)
|
|
|
|
|
: defaultPort;
|
|
|
|
|
info.options.path =
|
|
|
|
|
(info.parsedUrl.pathname || '') + (info.parsedUrl.search || '');
|
|
|
|
|
info.options.method = method;
|
|
|
|
|
info.options.headers = this._mergeHeaders(headers);
|
|
|
|
|
if (this.userAgent != null) {
|
|
|
|
|
info.options.headers['user-agent'] = this.userAgent;
|
|
|
|
|
}
|
|
|
|
|
info.options.agent = this._getAgent(info.parsedUrl);
|
|
|
|
|
// gives handlers an opportunity to participate
|
|
|
|
|
if (this.handlers) {
|
|
|
|
|
this.handlers.forEach(handler => {
|
|
|
|
|
handler.prepareRequest(info.options);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return info;
|
|
|
|
|
}
|
|
|
|
|
_mergeHeaders(headers) {
|
|
|
|
|
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {});
|
|
|
|
|
if (this.requestOptions && this.requestOptions.headers) {
|
|
|
|
|
return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers));
|
|
|
|
|
}
|
|
|
|
|
return lowercaseKeys(headers || {});
|
|
|
|
|
}
|
|
|
|
|
_getExistingOrDefaultHeader(additionalHeaders, header, _default) {
|
|
|
|
|
const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {});
|
|
|
|
|
let clientHeader;
|
|
|
|
|
if (this.requestOptions && this.requestOptions.headers) {
|
|
|
|
|
clientHeader = lowercaseKeys(this.requestOptions.headers)[header];
|
|
|
|
|
}
|
|
|
|
|
return additionalHeaders[header] || clientHeader || _default;
|
|
|
|
|
}
|
|
|
|
|
_getAgent(parsedUrl) {
|
|
|
|
|
let agent;
|
|
|
|
|
let proxyUrl = pm.getProxyUrl(parsedUrl);
|
|
|
|
|
let useProxy = proxyUrl && proxyUrl.hostname;
|
|
|
|
|
if (this._keepAlive && useProxy) {
|
|
|
|
|
agent = this._proxyAgent;
|
|
|
|
|
}
|
|
|
|
|
if (this._keepAlive && !useProxy) {
|
|
|
|
|
agent = this._agent;
|
|
|
|
|
}
|
|
|
|
|
// if agent is already assigned use that agent.
|
|
|
|
|
if (!!agent) {
|
|
|
|
|
return agent;
|
|
|
|
|
}
|
|
|
|
|
const usingSsl = parsedUrl.protocol === 'https:';
|
|
|
|
|
let maxSockets = 100;
|
|
|
|
|
if (!!this.requestOptions) {
|
|
|
|
|
maxSockets = this.requestOptions.maxSockets || http.globalAgent.maxSockets;
|
|
|
|
|
}
|
|
|
|
|
if (useProxy) {
|
|
|
|
|
// If using proxy, need tunnel
|
|
|
|
|
if (!tunnel) {
|
|
|
|
|
tunnel = __webpack_require__(413);
|
|
|
|
|
}
|
|
|
|
|
const agentOptions = {
|
|
|
|
|
maxSockets: maxSockets,
|
|
|
|
|
keepAlive: this._keepAlive,
|
|
|
|
|
proxy: {
|
|
|
|
|
...((proxyUrl.username || proxyUrl.password) && {
|
|
|
|
|
proxyAuth: `${proxyUrl.username}:${proxyUrl.password}`
|
|
|
|
|
}),
|
|
|
|
|
host: proxyUrl.hostname,
|
|
|
|
|
port: proxyUrl.port
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let tunnelAgent;
|
|
|
|
|
const overHttps = proxyUrl.protocol === 'https:';
|
|
|
|
|
if (usingSsl) {
|
|
|
|
|
tunnelAgent = overHttps ? tunnel.httpsOverHttps : tunnel.httpsOverHttp;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
tunnelAgent = overHttps ? tunnel.httpOverHttps : tunnel.httpOverHttp;
|
|
|
|
|
}
|
|
|
|
|
agent = tunnelAgent(agentOptions);
|
|
|
|
|
this._proxyAgent = agent;
|
|
|
|
|
}
|
|
|
|
|
// if reusing agent across request and tunneling agent isn't assigned create a new agent
|
|
|
|
|
if (this._keepAlive && !agent) {
|
|
|
|
|
const options = { keepAlive: this._keepAlive, maxSockets: maxSockets };
|
|
|
|
|
agent = usingSsl ? new https.Agent(options) : new http.Agent(options);
|
|
|
|
|
this._agent = agent;
|
|
|
|
|
}
|
|
|
|
|
// if not using private agent and tunnel agent isn't setup then use global agent
|
|
|
|
|
if (!agent) {
|
|
|
|
|
agent = usingSsl ? https.globalAgent : http.globalAgent;
|
|
|
|
|
}
|
|
|
|
|
if (usingSsl && this._ignoreSslError) {
|
|
|
|
|
// we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process
|
|
|
|
|
// http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options
|
|
|
|
|
// we have to cast it to any and change it directly
|
|
|
|
|
agent.options = Object.assign(agent.options || {}, {
|
|
|
|
|
rejectUnauthorized: false
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return agent;
|
|
|
|
|
}
|
|
|
|
|
_performExponentialBackoff(retryNumber) {
|
|
|
|
|
retryNumber = Math.min(ExponentialBackoffCeiling, retryNumber);
|
|
|
|
|
const ms = ExponentialBackoffTimeSlice * Math.pow(2, retryNumber);
|
|
|
|
|
return new Promise(resolve => setTimeout(() => resolve(), ms));
|
|
|
|
|
}
|
|
|
|
|
static dateTimeDeserializer(key, value) {
|
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
|
let a = new Date(value);
|
|
|
|
|
if (!isNaN(a.valueOf())) {
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
async _processResponse(res, options) {
|
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
const statusCode = res.message.statusCode;
|
|
|
|
|
const response = {
|
|
|
|
|
statusCode: statusCode,
|
|
|
|
|
result: null,
|
|
|
|
|
headers: {}
|
|
|
|
|
};
|
|
|
|
|
// not found leads to null obj returned
|
|
|
|
|
if (statusCode == HttpCodes.NotFound) {
|
|
|
|
|
resolve(response);
|
|
|
|
|
}
|
|
|
|
|
let obj;
|
|
|
|
|
let contents;
|
|
|
|
|
// get the result from the body
|
|
|
|
|
try {
|
|
|
|
|
contents = await res.readBody();
|
|
|
|
|
if (contents && contents.length > 0) {
|
|
|
|
|
if (options && options.deserializeDates) {
|
|
|
|
|
obj = JSON.parse(contents, HttpClient.dateTimeDeserializer);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
obj = JSON.parse(contents);
|
|
|
|
|
}
|
|
|
|
|
response.result = obj;
|
|
|
|
|
}
|
|
|
|
|
response.headers = res.message.headers;
|
|
|
|
|
}
|
|
|
|
|
catch (err) {
|
|
|
|
|
// Invalid resource (contents not json); leaving result obj null
|
|
|
|
|
}
|
|
|
|
|
// note that 3xx redirects are handled by the http layer.
|
|
|
|
|
if (statusCode > 299) {
|
|
|
|
|
let msg;
|
|
|
|
|
// if exception/error in body, attempt to get better error
|
|
|
|
|
if (obj && obj.message) {
|
|
|
|
|
msg = obj.message;
|
|
|
|
|
}
|
|
|
|
|
else if (contents && contents.length > 0) {
|
|
|
|
|
// it may be the case that the exception is in the body message as string
|
|
|
|
|
msg = contents;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
msg = 'Failed request: (' + statusCode + ')';
|
|
|
|
|
}
|
|
|
|
|
let err = new HttpClientError(msg, statusCode);
|
|
|
|
|
err.result = response.result;
|
|
|
|
|
reject(err);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
resolve(response);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.HttpClient = HttpClient;
|
|
|
|
|
|
|
|
|
|
exports.checkArtifactFilePath = checkArtifactFilePath;
|
|
|
|
|
//# sourceMappingURL=path-and-artifact-name-validation.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 569:
|
|
|
|
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
|
|
|
|
/***/ 554:
|
|
|
|
|
/***/ (function(__unusedmodule, exports) {
|
|
|
|
|
|
|
|
|
|
module.exports = rimraf
|
|
|
|
|
rimraf.sync = rimrafSync
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var assert = __webpack_require__(357)
|
|
|
|
|
var path = __webpack_require__(622)
|
|
|
|
|
var fs = __webpack_require__(747)
|
|
|
|
|
var glob = __webpack_require__(402)
|
|
|
|
|
var _0666 = parseInt('666', 8)
|
|
|
|
|
|
|
|
|
|
var defaultGlobOpts = {
|
|
|
|
|
nosort: true,
|
|
|
|
|
silent: true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// for EMFILE handling
|
|
|
|
|
var timeout = 0
|
|
|
|
|
|
|
|
|
|
var isWindows = (process.platform === "win32")
|
|
|
|
|
|
|
|
|
|
function defaults (options) {
|
|
|
|
|
var methods = [
|
|
|
|
|
'unlink',
|
|
|
|
|
'chmod',
|
|
|
|
|
'stat',
|
|
|
|
|
'lstat',
|
|
|
|
|
'rmdir',
|
|
|
|
|
'readdir'
|
|
|
|
|
]
|
|
|
|
|
methods.forEach(function(m) {
|
|
|
|
|
options[m] = options[m] || fs[m]
|
|
|
|
|
m = m + 'Sync'
|
|
|
|
|
options[m] = options[m] || fs[m]
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
options.maxBusyTries = options.maxBusyTries || 3
|
|
|
|
|
options.emfileWait = options.emfileWait || 1000
|
|
|
|
|
if (options.glob === false) {
|
|
|
|
|
options.disableGlob = true
|
|
|
|
|
}
|
|
|
|
|
options.disableGlob = options.disableGlob || false
|
|
|
|
|
options.glob = options.glob || defaultGlobOpts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function rimraf (p, options, cb) {
|
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
|
cb = options
|
|
|
|
|
options = {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(p, 'rimraf: missing path')
|
|
|
|
|
assert.equal(typeof p, 'string', 'rimraf: path should be a string')
|
|
|
|
|
assert.equal(typeof cb, 'function', 'rimraf: callback function required')
|
|
|
|
|
assert(options, 'rimraf: invalid options argument provided')
|
|
|
|
|
assert.equal(typeof options, 'object', 'rimraf: options should be object')
|
|
|
|
|
|
|
|
|
|
defaults(options)
|
|
|
|
|
|
|
|
|
|
var busyTries = 0
|
|
|
|
|
var errState = null
|
|
|
|
|
var n = 0
|
|
|
|
|
|
|
|
|
|
if (options.disableGlob || !glob.hasMagic(p))
|
|
|
|
|
return afterGlob(null, [p])
|
|
|
|
|
|
|
|
|
|
options.lstat(p, function (er, stat) {
|
|
|
|
|
if (!er)
|
|
|
|
|
return afterGlob(null, [p])
|
|
|
|
|
|
|
|
|
|
glob(p, options.glob, afterGlob)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function next (er) {
|
|
|
|
|
errState = errState || er
|
|
|
|
|
if (--n === 0)
|
|
|
|
|
cb(errState)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function afterGlob (er, results) {
|
|
|
|
|
if (er)
|
|
|
|
|
return cb(er)
|
|
|
|
|
|
|
|
|
|
n = results.length
|
|
|
|
|
if (n === 0)
|
|
|
|
|
return cb()
|
|
|
|
|
|
|
|
|
|
results.forEach(function (p) {
|
|
|
|
|
rimraf_(p, options, function CB (er) {
|
|
|
|
|
if (er) {
|
|
|
|
|
if ((er.code === "EBUSY" || er.code === "ENOTEMPTY" || er.code === "EPERM") &&
|
|
|
|
|
busyTries < options.maxBusyTries) {
|
|
|
|
|
busyTries ++
|
|
|
|
|
var time = busyTries * 100
|
|
|
|
|
// try again, with the same exact callback as this one.
|
|
|
|
|
return setTimeout(function () {
|
|
|
|
|
rimraf_(p, options, CB)
|
|
|
|
|
}, time)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this one won't happen if graceful-fs is used.
|
|
|
|
|
if (er.code === "EMFILE" && timeout < options.emfileWait) {
|
|
|
|
|
return setTimeout(function () {
|
|
|
|
|
rimraf_(p, options, CB)
|
|
|
|
|
}, timeout ++)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// already gone
|
|
|
|
|
if (er.code === "ENOENT") er = null
|
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
|
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
|
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.PersonalAccessTokenCredentialHandler = exports.BearerCredentialHandler = exports.BasicCredentialHandler = void 0;
|
|
|
|
|
class BasicCredentialHandler {
|
|
|
|
|
constructor(username, password) {
|
|
|
|
|
this.username = username;
|
|
|
|
|
this.password = password;
|
|
|
|
|
}
|
|
|
|
|
prepareRequest(options) {
|
|
|
|
|
if (!options.headers) {
|
|
|
|
|
throw Error('The request has no headers');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
timeout = 0
|
|
|
|
|
next(er)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Two possible strategies.
|
|
|
|
|
// 1. Assume it's a file. unlink it, then do the dir stuff on EPERM or EISDIR
|
|
|
|
|
// 2. Assume it's a directory. readdir, then do the file stuff on ENOTDIR
|
|
|
|
|
//
|
|
|
|
|
// Both result in an extra syscall when you guess wrong. However, there
|
|
|
|
|
// are likely far more normal files in the world than directories. This
|
|
|
|
|
// is based on the assumption that a the average number of files per
|
|
|
|
|
// directory is >= 1.
|
|
|
|
|
//
|
|
|
|
|
// If anyone ever complains about this, then I guess the strategy could
|
|
|
|
|
// be made configurable somehow. But until then, YAGNI.
|
|
|
|
|
function rimraf_ (p, options, cb) {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
assert(typeof cb === 'function')
|
|
|
|
|
|
|
|
|
|
// sunos lets the root user unlink directories, which is... weird.
|
|
|
|
|
// so we have to lstat here and make sure it's not a dir.
|
|
|
|
|
options.lstat(p, function (er, st) {
|
|
|
|
|
if (er && er.code === "ENOENT")
|
|
|
|
|
return cb(null)
|
|
|
|
|
|
|
|
|
|
// Windows can EPERM on stat. Life is suffering.
|
|
|
|
|
if (er && er.code === "EPERM" && isWindows)
|
|
|
|
|
fixWinEPERM(p, options, er, cb)
|
|
|
|
|
|
|
|
|
|
if (st && st.isDirectory())
|
|
|
|
|
return rmdir(p, options, er, cb)
|
|
|
|
|
|
|
|
|
|
options.unlink(p, function (er) {
|
|
|
|
|
if (er) {
|
|
|
|
|
if (er.code === "ENOENT")
|
|
|
|
|
return cb(null)
|
|
|
|
|
if (er.code === "EPERM")
|
|
|
|
|
return (isWindows)
|
|
|
|
|
? fixWinEPERM(p, options, er, cb)
|
|
|
|
|
: rmdir(p, options, er, cb)
|
|
|
|
|
if (er.code === "EISDIR")
|
|
|
|
|
return rmdir(p, options, er, cb)
|
|
|
|
|
}
|
|
|
|
|
return cb(er)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fixWinEPERM (p, options, er, cb) {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
assert(typeof cb === 'function')
|
|
|
|
|
if (er)
|
|
|
|
|
assert(er instanceof Error)
|
|
|
|
|
|
|
|
|
|
options.chmod(p, _0666, function (er2) {
|
|
|
|
|
if (er2)
|
|
|
|
|
cb(er2.code === "ENOENT" ? null : er)
|
|
|
|
|
else
|
|
|
|
|
options.stat(p, function(er3, stats) {
|
|
|
|
|
if (er3)
|
|
|
|
|
cb(er3.code === "ENOENT" ? null : er)
|
|
|
|
|
else if (stats.isDirectory())
|
|
|
|
|
rmdir(p, options, er, cb)
|
|
|
|
|
else
|
|
|
|
|
options.unlink(p, cb)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fixWinEPERMSync (p, options, er) {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
if (er)
|
|
|
|
|
assert(er instanceof Error)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
options.chmodSync(p, _0666)
|
|
|
|
|
} catch (er2) {
|
|
|
|
|
if (er2.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
throw er
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var stats = options.statSync(p)
|
|
|
|
|
} catch (er3) {
|
|
|
|
|
if (er3.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
else
|
|
|
|
|
throw er
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stats.isDirectory())
|
|
|
|
|
rmdirSync(p, options, er)
|
|
|
|
|
else
|
|
|
|
|
options.unlinkSync(p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function rmdir (p, options, originalEr, cb) {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
if (originalEr)
|
|
|
|
|
assert(originalEr instanceof Error)
|
|
|
|
|
assert(typeof cb === 'function')
|
|
|
|
|
|
|
|
|
|
// try to rmdir first, and only readdir on ENOTEMPTY or EEXIST (SunOS)
|
|
|
|
|
// if we guessed wrong, and it's not a directory, then
|
|
|
|
|
// raise the original error.
|
|
|
|
|
options.rmdir(p, function (er) {
|
|
|
|
|
if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM"))
|
|
|
|
|
rmkids(p, options, cb)
|
|
|
|
|
else if (er && er.code === "ENOTDIR")
|
|
|
|
|
cb(originalEr)
|
|
|
|
|
else
|
|
|
|
|
cb(er)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function rmkids(p, options, cb) {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
assert(typeof cb === 'function')
|
|
|
|
|
|
|
|
|
|
options.readdir(p, function (er, files) {
|
|
|
|
|
if (er)
|
|
|
|
|
return cb(er)
|
|
|
|
|
var n = files.length
|
|
|
|
|
if (n === 0)
|
|
|
|
|
return options.rmdir(p, cb)
|
|
|
|
|
var errState
|
|
|
|
|
files.forEach(function (f) {
|
|
|
|
|
rimraf(path.join(p, f), options, function (er) {
|
|
|
|
|
if (errState)
|
|
|
|
|
return
|
|
|
|
|
if (er)
|
|
|
|
|
return cb(errState = er)
|
|
|
|
|
if (--n === 0)
|
|
|
|
|
options.rmdir(p, cb)
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this looks simpler, and is strictly *faster*, but will
|
|
|
|
|
// tie up the JavaScript thread and fail on excessively
|
|
|
|
|
// deep directory trees.
|
|
|
|
|
function rimrafSync (p, options) {
|
|
|
|
|
options = options || {}
|
|
|
|
|
defaults(options)
|
|
|
|
|
|
|
|
|
|
assert(p, 'rimraf: missing path')
|
|
|
|
|
assert.equal(typeof p, 'string', 'rimraf: path should be a string')
|
|
|
|
|
assert(options, 'rimraf: missing options')
|
|
|
|
|
assert.equal(typeof options, 'object', 'rimraf: options should be object')
|
|
|
|
|
|
|
|
|
|
var results
|
|
|
|
|
|
|
|
|
|
if (options.disableGlob || !glob.hasMagic(p)) {
|
|
|
|
|
results = [p]
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
options.lstatSync(p)
|
|
|
|
|
results = [p]
|
|
|
|
|
} catch (er) {
|
|
|
|
|
results = glob.sync(p, options.glob)
|
|
|
|
|
options.headers['Authorization'] = `Basic ${Buffer.from(`${this.username}:${this.password}`).toString('base64')}`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!results.length)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < results.length; i++) {
|
|
|
|
|
var p = results[i]
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
var st = options.lstatSync(p)
|
|
|
|
|
} catch (er) {
|
|
|
|
|
if (er.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
// Windows can EPERM on stat. Life is suffering.
|
|
|
|
|
if (er.code === "EPERM" && isWindows)
|
|
|
|
|
fixWinEPERMSync(p, options, er)
|
|
|
|
|
// This handler cannot handle 401
|
|
|
|
|
canHandleAuthentication() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// sunos lets the root user unlink directories, which is... weird.
|
|
|
|
|
if (st && st.isDirectory())
|
|
|
|
|
rmdirSync(p, options, null)
|
|
|
|
|
else
|
|
|
|
|
options.unlinkSync(p)
|
|
|
|
|
} catch (er) {
|
|
|
|
|
if (er.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
if (er.code === "EPERM")
|
|
|
|
|
return isWindows ? fixWinEPERMSync(p, options, er) : rmdirSync(p, options, er)
|
|
|
|
|
if (er.code !== "EISDIR")
|
|
|
|
|
throw er
|
|
|
|
|
|
|
|
|
|
rmdirSync(p, options, er)
|
|
|
|
|
handleAuthentication() {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
throw new Error('not implemented');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function rmdirSync (p, options, originalEr) {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
if (originalEr)
|
|
|
|
|
assert(originalEr instanceof Error)
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
options.rmdirSync(p)
|
|
|
|
|
} catch (er) {
|
|
|
|
|
if (er.code === "ENOENT")
|
|
|
|
|
return
|
|
|
|
|
if (er.code === "ENOTDIR")
|
|
|
|
|
throw originalEr
|
|
|
|
|
if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")
|
|
|
|
|
rmkidsSync(p, options)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function rmkidsSync (p, options) {
|
|
|
|
|
assert(p)
|
|
|
|
|
assert(options)
|
|
|
|
|
options.readdirSync(p).forEach(function (f) {
|
|
|
|
|
rimrafSync(path.join(p, f), options)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// We only end up here once we got ENOTEMPTY at least once, and
|
|
|
|
|
// at this point, we are guaranteed to have removed all the kids.
|
|
|
|
|
// So, we know that it won't be ENOENT or ENOTDIR or anything else.
|
|
|
|
|
// try really hard to delete stuff on windows, because it has a
|
|
|
|
|
// PROFOUNDLY annoying habit of not closing handles promptly when
|
|
|
|
|
// files are deleted, resulting in spurious ENOTEMPTY errors.
|
|
|
|
|
var retries = isWindows ? 100 : 1
|
|
|
|
|
var i = 0
|
|
|
|
|
do {
|
|
|
|
|
var threw = true
|
|
|
|
|
try {
|
|
|
|
|
var ret = options.rmdirSync(p, options)
|
|
|
|
|
threw = false
|
|
|
|
|
return ret
|
|
|
|
|
} finally {
|
|
|
|
|
if (++i < retries && threw)
|
|
|
|
|
continue
|
|
|
|
|
exports.BasicCredentialHandler = BasicCredentialHandler;
|
|
|
|
|
class BearerCredentialHandler {
|
|
|
|
|
constructor(token) {
|
|
|
|
|
this.token = token;
|
|
|
|
|
}
|
|
|
|
|
// currently implements pre-authorization
|
|
|
|
|
// TODO: support preAuth = false where it hooks on 401
|
|
|
|
|
prepareRequest(options) {
|
|
|
|
|
if (!options.headers) {
|
|
|
|
|
throw Error('The request has no headers');
|
|
|
|
|
}
|
|
|
|
|
options.headers['Authorization'] = `Bearer ${this.token}`;
|
|
|
|
|
}
|
|
|
|
|
// This handler cannot handle 401
|
|
|
|
|
canHandleAuthentication() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
handleAuthentication() {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
throw new Error('not implemented');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} while (true)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exports.BearerCredentialHandler = BearerCredentialHandler;
|
|
|
|
|
class PersonalAccessTokenCredentialHandler {
|
|
|
|
|
constructor(token) {
|
|
|
|
|
this.token = token;
|
|
|
|
|
}
|
|
|
|
|
// currently implements pre-authorization
|
|
|
|
|
// TODO: support preAuth = false where it hooks on 401
|
|
|
|
|
prepareRequest(options) {
|
|
|
|
|
if (!options.headers) {
|
|
|
|
|
throw Error('The request has no headers');
|
|
|
|
|
}
|
|
|
|
|
options.headers['Authorization'] = `Basic ${Buffer.from(`PAT:${this.token}`).toString('base64')}`;
|
|
|
|
|
}
|
|
|
|
|
// This handler cannot handle 401
|
|
|
|
|
canHandleAuthentication() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
handleAuthentication() {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
throw new Error('not implemented');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler;
|
|
|
|
|
//# sourceMappingURL=auth.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
@@ -6605,18 +7205,31 @@ exports.getInputs = getInputs;
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
|
result["default"] = mod;
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.getUploadSpecification = void 0;
|
|
|
|
|
const fs = __importStar(__webpack_require__(747));
|
|
|
|
|
const core_1 = __webpack_require__(470);
|
|
|
|
|
const path_1 = __webpack_require__(622);
|
|
|
|
|
const utils_1 = __webpack_require__(870);
|
|
|
|
|
const path_and_artifact_name_validation_1 = __webpack_require__(553);
|
|
|
|
|
/**
|
|
|
|
|
* Creates a specification that describes how each file that is part of the artifact will be uploaded
|
|
|
|
|
* @param artifactName the name of the artifact being uploaded. Used during upload to denote where the artifact is stored on the server
|
|
|
|
@@ -6624,7 +7237,7 @@ const utils_1 = __webpack_require__(870);
|
|
|
|
|
* @param artifactFiles a list of absolute file paths that denote what should be uploaded as part of the artifact
|
|
|
|
|
*/
|
|
|
|
|
function getUploadSpecification(artifactName, rootDirectory, artifactFiles) {
|
|
|
|
|
utils_1.checkArtifactName(artifactName);
|
|
|
|
|
// artifact name was checked earlier on, no need to check again
|
|
|
|
|
const specifications = [];
|
|
|
|
|
if (!fs.existsSync(rootDirectory)) {
|
|
|
|
|
throw new Error(`Provided rootDirectory ${rootDirectory} does not exist`);
|
|
|
|
@@ -6667,7 +7280,7 @@ function getUploadSpecification(artifactName, rootDirectory, artifactFiles) {
|
|
|
|
|
}
|
|
|
|
|
// Check for forbidden characters in file paths that will be rejected during upload
|
|
|
|
|
const uploadPath = file.replace(rootDirectory, '');
|
|
|
|
|
utils_1.checkArtifactFilePath(uploadPath);
|
|
|
|
|
path_and_artifact_name_validation_1.checkArtifactFilePath(uploadPath);
|
|
|
|
|
/*
|
|
|
|
|
uploadFilePath denotes where the file will be uploaded in the file container on the server. During a run, if multiple artifacts are uploaded, they will all
|
|
|
|
|
be saved in the same container. The artifact name is used as the root directory in the container to separate and distinguish uploaded artifacts
|
|
|
|
@@ -6825,6 +7438,25 @@ module.exports = require("http");
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
@@ -6834,25 +7466,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
|
result["default"] = mod;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.UploadHttpClient = void 0;
|
|
|
|
|
const fs = __importStar(__webpack_require__(747));
|
|
|
|
|
const core = __importStar(__webpack_require__(470));
|
|
|
|
|
const tmp = __importStar(__webpack_require__(875));
|
|
|
|
|
const stream = __importStar(__webpack_require__(794));
|
|
|
|
|
const stream = __importStar(__webpack_require__(413));
|
|
|
|
|
const utils_1 = __webpack_require__(870);
|
|
|
|
|
const config_variables_1 = __webpack_require__(401);
|
|
|
|
|
const util_1 = __webpack_require__(669);
|
|
|
|
|
const url_1 = __webpack_require__(835);
|
|
|
|
|
const perf_hooks_1 = __webpack_require__(630);
|
|
|
|
|
const status_reporter_1 = __webpack_require__(176);
|
|
|
|
|
const http_client_1 = __webpack_require__(539);
|
|
|
|
|
const http_client_1 = __webpack_require__(425);
|
|
|
|
|
const http_manager_1 = __webpack_require__(452);
|
|
|
|
|
const upload_gzip_1 = __webpack_require__(647);
|
|
|
|
|
const requestUtils_1 = __webpack_require__(489);
|
|
|
|
@@ -6987,27 +7613,33 @@ class UploadHttpClient {
|
|
|
|
|
*/
|
|
|
|
|
uploadFileAsync(httpClientIndex, parameters) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
const totalFileSize = (yield stat(parameters.file)).size;
|
|
|
|
|
const fileStat = yield stat(parameters.file);
|
|
|
|
|
const totalFileSize = fileStat.size;
|
|
|
|
|
const isFIFO = fileStat.isFIFO();
|
|
|
|
|
let offset = 0;
|
|
|
|
|
let isUploadSuccessful = true;
|
|
|
|
|
let failedChunkSizes = 0;
|
|
|
|
|
let uploadFileSize = 0;
|
|
|
|
|
let isGzip = true;
|
|
|
|
|
// the file that is being uploaded is less than 64k in size, to increase throughput and to minimize disk I/O
|
|
|
|
|
// the file that is being uploaded is less than 64k in size to increase throughput and to minimize disk I/O
|
|
|
|
|
// for creating a new GZip file, an in-memory buffer is used for compression
|
|
|
|
|
if (totalFileSize < 65536) {
|
|
|
|
|
// with named pipes the file size is reported as zero in that case don't read the file in memory
|
|
|
|
|
if (!isFIFO && totalFileSize < 65536) {
|
|
|
|
|
core.debug(`${parameters.file} is less than 64k in size. Creating a gzip file in-memory to potentially reduce the upload size`);
|
|
|
|
|
const buffer = yield upload_gzip_1.createGZipFileInBuffer(parameters.file);
|
|
|
|
|
//An open stream is needed in the event of a failure and we need to retry. If a NodeJS.ReadableStream is directly passed in,
|
|
|
|
|
// An open stream is needed in the event of a failure and we need to retry. If a NodeJS.ReadableStream is directly passed in,
|
|
|
|
|
// it will not properly get reset to the start of the stream if a chunk upload needs to be retried
|
|
|
|
|
let openUploadStream;
|
|
|
|
|
if (totalFileSize < buffer.byteLength) {
|
|
|
|
|
// compression did not help with reducing the size, use a readable stream from the original file for upload
|
|
|
|
|
core.debug(`The gzip file created for ${parameters.file} did not help with reducing the size of the file. The original file will be uploaded as-is`);
|
|
|
|
|
openUploadStream = () => fs.createReadStream(parameters.file);
|
|
|
|
|
isGzip = false;
|
|
|
|
|
uploadFileSize = totalFileSize;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// create a readable stream using a PassThrough stream that is both readable and writable
|
|
|
|
|
core.debug(`A gzip file created for ${parameters.file} helped with reducing the size of the original file. The file will be uploaded using gzip.`);
|
|
|
|
|
openUploadStream = () => {
|
|
|
|
|
const passThrough = new stream.PassThrough();
|
|
|
|
|
passThrough.end(buffer);
|
|
|
|
@@ -7032,25 +7664,27 @@ class UploadHttpClient {
|
|
|
|
|
// the file that is being uploaded is greater than 64k in size, a temporary file gets created on disk using the
|
|
|
|
|
// npm tmp-promise package and this file gets used to create a GZipped file
|
|
|
|
|
const tempFile = yield tmp.file();
|
|
|
|
|
core.debug(`${parameters.file} is greater than 64k in size. Creating a gzip file on-disk ${tempFile.path} to potentially reduce the upload size`);
|
|
|
|
|
// create a GZip file of the original file being uploaded, the original file should not be modified in any way
|
|
|
|
|
uploadFileSize = yield upload_gzip_1.createGZipFileOnDisk(parameters.file, tempFile.path);
|
|
|
|
|
let uploadFilePath = tempFile.path;
|
|
|
|
|
// compression did not help with size reduction, use the original file for upload and delete the temp GZip file
|
|
|
|
|
if (totalFileSize < uploadFileSize) {
|
|
|
|
|
// for named pipes totalFileSize is zero, this assumes compression did help
|
|
|
|
|
if (!isFIFO && totalFileSize < uploadFileSize) {
|
|
|
|
|
core.debug(`The gzip file created for ${parameters.file} did not help with reducing the size of the file. The original file will be uploaded as-is`);
|
|
|
|
|
uploadFileSize = totalFileSize;
|
|
|
|
|
uploadFilePath = parameters.file;
|
|
|
|
|
isGzip = false;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
core.debug(`The gzip file created for ${parameters.file} is smaller than the original file. The file will be uploaded using gzip.`);
|
|
|
|
|
}
|
|
|
|
|
let abortFileUpload = false;
|
|
|
|
|
// upload only a single chunk at a time
|
|
|
|
|
while (offset < uploadFileSize) {
|
|
|
|
|
const chunkSize = Math.min(uploadFileSize - offset, parameters.maxChunkSize);
|
|
|
|
|
// if an individual file is greater than 100MB (1024*1024*100) in size, display extra information about the upload status
|
|
|
|
|
if (uploadFileSize > 104857600) {
|
|
|
|
|
this.statusReporter.updateLargeFileStatus(parameters.file, offset, uploadFileSize);
|
|
|
|
|
}
|
|
|
|
|
const start = offset;
|
|
|
|
|
const end = offset + chunkSize - 1;
|
|
|
|
|
const startChunkIndex = offset;
|
|
|
|
|
const endChunkIndex = offset + chunkSize - 1;
|
|
|
|
|
offset += parameters.maxChunkSize;
|
|
|
|
|
if (abortFileUpload) {
|
|
|
|
|
// if we don't want to continue in the event of an error, any pending upload chunks will be marked as failed
|
|
|
|
@@ -7058,10 +7692,10 @@ class UploadHttpClient {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
const result = yield this.uploadChunk(httpClientIndex, parameters.resourceUrl, () => fs.createReadStream(uploadFilePath, {
|
|
|
|
|
start,
|
|
|
|
|
end,
|
|
|
|
|
start: startChunkIndex,
|
|
|
|
|
end: endChunkIndex,
|
|
|
|
|
autoClose: false
|
|
|
|
|
}), start, end, uploadFileSize, isGzip, totalFileSize);
|
|
|
|
|
}), startChunkIndex, endChunkIndex, uploadFileSize, isGzip, totalFileSize);
|
|
|
|
|
if (!result) {
|
|
|
|
|
// Chunk failed to upload, report as failed and do not continue uploading any more chunks for the file. It is possible that part of a chunk was
|
|
|
|
|
// successfully uploaded so the server may report a different size for what was uploaded
|
|
|
|
@@ -7070,9 +7704,16 @@ class UploadHttpClient {
|
|
|
|
|
core.warning(`Aborting upload for ${parameters.file} due to failure`);
|
|
|
|
|
abortFileUpload = true;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// if an individual file is greater than 8MB (1024*1024*8) in size, display extra information about the upload status
|
|
|
|
|
if (uploadFileSize > 8388608) {
|
|
|
|
|
this.statusReporter.updateLargeFileStatus(parameters.file, startChunkIndex, endChunkIndex, uploadFileSize);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Delete the temporary file that was created as part of the upload. If the temp file does not get manually deleted by
|
|
|
|
|
// calling cleanup, it gets removed when the node process exits. For more info see: https://www.npmjs.com/package/tmp-promise#about
|
|
|
|
|
core.debug(`deleting temporary gzip file ${tempFile.path}`);
|
|
|
|
|
yield tempFile.cleanup();
|
|
|
|
|
return {
|
|
|
|
|
isSuccess: isUploadSuccessful,
|
|
|
|
@@ -7097,8 +7738,10 @@ class UploadHttpClient {
|
|
|
|
|
*/
|
|
|
|
|
uploadChunk(httpClientIndex, resourceUrl, openStream, start, end, uploadFileSize, isGzip, totalFileSize) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
// open a new stream and read it to compute the digest
|
|
|
|
|
const digest = yield utils_1.digestForStream(openStream());
|
|
|
|
|
// prepare all the necessary headers before making any http call
|
|
|
|
|
const headers = utils_1.getUploadHeaders('application/octet-stream', true, isGzip, totalFileSize, end - start + 1, utils_1.getContentRange(start, end, uploadFileSize));
|
|
|
|
|
const headers = utils_1.getUploadHeaders('application/octet-stream', true, isGzip, totalFileSize, end - start + 1, utils_1.getContentRange(start, end, uploadFileSize), digest);
|
|
|
|
|
const uploadChunkRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
const client = this.uploadHttpManager.getClient(httpClientIndex);
|
|
|
|
|
return yield client.sendStream('PUT', resourceUrl, openStream(), headers);
|
|
|
|
@@ -7306,6 +7949,25 @@ module.exports = require("net");
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
@@ -7322,18 +7984,25 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
|
|
|
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
|
|
|
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
|
|
|
};
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
|
result["default"] = mod;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.createGZipFileInBuffer = exports.createGZipFileOnDisk = void 0;
|
|
|
|
|
const fs = __importStar(__webpack_require__(747));
|
|
|
|
|
const zlib = __importStar(__webpack_require__(761));
|
|
|
|
|
const util_1 = __webpack_require__(669);
|
|
|
|
|
const stat = util_1.promisify(fs.stat);
|
|
|
|
|
/**
|
|
|
|
|
* GZipping certain files that are already compressed will likely not yield further size reductions. Creating large temporary gzip
|
|
|
|
|
* files then will just waste a lot of time before ultimately being discarded (especially for very large files).
|
|
|
|
|
* If any of these types of files are encountered then on-disk gzip creation will be skipped and the original file will be uploaded as-is
|
|
|
|
|
*/
|
|
|
|
|
const gzipExemptFileExtensions = [
|
|
|
|
|
'.gzip',
|
|
|
|
|
'.zip',
|
|
|
|
|
'.tar.lz',
|
|
|
|
|
'.tar.gz',
|
|
|
|
|
'.tar.bz2',
|
|
|
|
|
'.7z'
|
|
|
|
|
];
|
|
|
|
|
/**
|
|
|
|
|
* Creates a Gzip compressed file of an original file at the provided temporary filepath location
|
|
|
|
|
* @param {string} originalFilePath filepath of whatever will be compressed. The original file will be unmodified
|
|
|
|
@@ -7342,6 +8011,12 @@ const stat = util_1.promisify(fs.stat);
|
|
|
|
|
*/
|
|
|
|
|
function createGZipFileOnDisk(originalFilePath, tempFilePath) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
for (const gzipExemptExtension of gzipExemptFileExtensions) {
|
|
|
|
|
if (originalFilePath.endsWith(gzipExemptExtension)) {
|
|
|
|
|
// return a really large number so that the original file gets uploaded
|
|
|
|
|
return Number.MAX_SAFE_INTEGER;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const inputStream = fs.createReadStream(originalFilePath);
|
|
|
|
|
const gzip = zlib.createGzip();
|
|
|
|
@@ -7572,13 +8247,6 @@ module.exports = require("zlib");
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 794:
|
|
|
|
|
/***/ (function(module) {
|
|
|
|
|
|
|
|
|
|
module.exports = require("stream");
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 835:
|
|
|
|
|
/***/ (function(module) {
|
|
|
|
|
|
|
|
|
@@ -7591,6 +8259,25 @@ module.exports = require("url");
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
|
|
|
}) : (function(o, m, k, k2) {
|
|
|
|
|
if (k2 === undefined) k2 = k;
|
|
|
|
|
o[k2] = m[k];
|
|
|
|
|
}));
|
|
|
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
|
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
|
|
|
}) : function(o, v) {
|
|
|
|
|
o["default"] = v;
|
|
|
|
|
});
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
|
|
|
__setModuleDefault(result, mod);
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
|
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
|
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
|
|
@@ -7600,14 +8287,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
|
var result = {};
|
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
|
result["default"] = mod;
|
|
|
|
|
return result;
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
exports.DownloadHttpClient = void 0;
|
|
|
|
|
const fs = __importStar(__webpack_require__(747));
|
|
|
|
|
const core = __importStar(__webpack_require__(470));
|
|
|
|
|
const zlib = __importStar(__webpack_require__(761));
|
|
|
|
@@ -7759,9 +8440,6 @@ class DownloadHttpClient {
|
|
|
|
|
let response;
|
|
|
|
|
try {
|
|
|
|
|
response = yield makeDownloadRequest();
|
|
|
|
|
if (core.isDebug()) {
|
|
|
|
|
utils_1.displayHttpDiagnostics(response);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (error) {
|
|
|
|
|
// if an error is caught, it is usually indicative of a timeout so retry the download
|
|
|
|
@@ -8129,12 +8807,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
|
|
|
};
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
const core_1 = __webpack_require__(470);
|
|
|
|
|
exports.digestForStream = exports.sleep = exports.getProperRetention = exports.rmFile = exports.getFileSize = exports.createEmptyFilesForArtifact = exports.createDirectoriesForArtifact = exports.displayHttpDiagnostics = exports.getArtifactUrl = exports.createHttpClient = exports.getUploadHeaders = exports.getDownloadHeaders = exports.getContentRange = exports.tryGetRetryAfterValueTimeInMilliseconds = exports.isThrottledStatusCode = exports.isRetryableStatusCode = exports.isForbiddenStatusCode = exports.isSuccessStatusCode = exports.getApiVersion = exports.parseEnvNumber = exports.getExponentialRetryTimeInMilliseconds = void 0;
|
|
|
|
|
const crypto_1 = __importDefault(__webpack_require__(417));
|
|
|
|
|
const fs_1 = __webpack_require__(747);
|
|
|
|
|
const http_client_1 = __webpack_require__(539);
|
|
|
|
|
const auth_1 = __webpack_require__(226);
|
|
|
|
|
const core_1 = __webpack_require__(470);
|
|
|
|
|
const http_client_1 = __webpack_require__(425);
|
|
|
|
|
const auth_1 = __webpack_require__(554);
|
|
|
|
|
const config_variables_1 = __webpack_require__(401);
|
|
|
|
|
const crc64_1 = __importDefault(__webpack_require__(112));
|
|
|
|
|
/**
|
|
|
|
|
* Returns a retry time in milliseconds that exponentially gets larger
|
|
|
|
|
* depending on the amount of retries that have been attempted
|
|
|
|
@@ -8149,7 +8833,7 @@ function getExponentialRetryTimeInMilliseconds(retryCount) {
|
|
|
|
|
const minTime = config_variables_1.getInitialRetryIntervalInMilliseconds() * config_variables_1.getRetryMultiplier() * retryCount;
|
|
|
|
|
const maxTime = minTime * config_variables_1.getRetryMultiplier();
|
|
|
|
|
// returns a random number between the minTime (inclusive) and the maxTime (exclusive)
|
|
|
|
|
return Math.random() * (maxTime - minTime) + minTime;
|
|
|
|
|
return Math.trunc(Math.random() * (maxTime - minTime) + minTime);
|
|
|
|
|
}
|
|
|
|
|
exports.getExponentialRetryTimeInMilliseconds = getExponentialRetryTimeInMilliseconds;
|
|
|
|
|
/**
|
|
|
|
@@ -8190,8 +8874,9 @@ function isRetryableStatusCode(statusCode) {
|
|
|
|
|
}
|
|
|
|
|
const retryableStatusCodes = [
|
|
|
|
|
http_client_1.HttpCodes.BadGateway,
|
|
|
|
|
http_client_1.HttpCodes.ServiceUnavailable,
|
|
|
|
|
http_client_1.HttpCodes.GatewayTimeout,
|
|
|
|
|
http_client_1.HttpCodes.InternalServerError,
|
|
|
|
|
http_client_1.HttpCodes.ServiceUnavailable,
|
|
|
|
|
http_client_1.HttpCodes.TooManyRequests,
|
|
|
|
|
413 // Payload Too Large
|
|
|
|
|
];
|
|
|
|
@@ -8274,7 +8959,7 @@ exports.getDownloadHeaders = getDownloadHeaders;
|
|
|
|
|
* @param {string} contentRange the range of the content that is being uploaded
|
|
|
|
|
* @returns appropriate headers to make a specific http call during artifact upload
|
|
|
|
|
*/
|
|
|
|
|
function getUploadHeaders(contentType, isKeepAlive, isGzip, uncompressedLength, contentLength, contentRange) {
|
|
|
|
|
function getUploadHeaders(contentType, isKeepAlive, isGzip, uncompressedLength, contentLength, contentRange, digest) {
|
|
|
|
|
const requestOptions = {};
|
|
|
|
|
requestOptions['Accept'] = `application/json;api-version=${getApiVersion()}`;
|
|
|
|
|
if (contentType) {
|
|
|
|
@@ -8295,6 +8980,10 @@ function getUploadHeaders(contentType, isKeepAlive, isGzip, uncompressedLength,
|
|
|
|
|
if (contentRange) {
|
|
|
|
|
requestOptions['Content-Range'] = contentRange;
|
|
|
|
|
}
|
|
|
|
|
if (digest) {
|
|
|
|
|
requestOptions['x-actions-results-crc64'] = digest.crc64;
|
|
|
|
|
requestOptions['x-actions-results-md5'] = digest.md5;
|
|
|
|
|
}
|
|
|
|
|
return requestOptions;
|
|
|
|
|
}
|
|
|
|
|
exports.getUploadHeaders = getUploadHeaders;
|
|
|
|
@@ -8327,48 +9016,6 @@ Header Information: ${JSON.stringify(response.message.headers, undefined, 2)}
|
|
|
|
|
###### End Diagnostic HTTP information ######`);
|
|
|
|
|
}
|
|
|
|
|
exports.displayHttpDiagnostics = displayHttpDiagnostics;
|
|
|
|
|
/**
|
|
|
|
|
* Invalid characters that cannot be in the artifact name or an uploaded file. Will be rejected
|
|
|
|
|
* from the server if attempted to be sent over. These characters are not allowed due to limitations with certain
|
|
|
|
|
* file systems such as NTFS. To maintain platform-agnostic behavior, all characters that are not supported by an
|
|
|
|
|
* individual filesystem/platform will not be supported on all fileSystems/platforms
|
|
|
|
|
*
|
|
|
|
|
* FilePaths can include characters such as \ and / which are not permitted in the artifact name alone
|
|
|
|
|
*/
|
|
|
|
|
const invalidArtifactFilePathCharacters = ['"', ':', '<', '>', '|', '*', '?'];
|
|
|
|
|
const invalidArtifactNameCharacters = [
|
|
|
|
|
...invalidArtifactFilePathCharacters,
|
|
|
|
|
'\\',
|
|
|
|
|
'/'
|
|
|
|
|
];
|
|
|
|
|
/**
|
|
|
|
|
* Scans the name of the artifact to make sure there are no illegal characters
|
|
|
|
|
*/
|
|
|
|
|
function checkArtifactName(name) {
|
|
|
|
|
if (!name) {
|
|
|
|
|
throw new Error(`Artifact name: ${name}, is incorrectly provided`);
|
|
|
|
|
}
|
|
|
|
|
for (const invalidChar of invalidArtifactNameCharacters) {
|
|
|
|
|
if (name.includes(invalidChar)) {
|
|
|
|
|
throw new Error(`Artifact name is not valid: ${name}. Contains character: "${invalidChar}". Invalid artifact name characters include: ${invalidArtifactNameCharacters.toString()}.`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.checkArtifactName = checkArtifactName;
|
|
|
|
|
/**
|
|
|
|
|
* Scans the name of the filePath used to make sure there are no illegal characters
|
|
|
|
|
*/
|
|
|
|
|
function checkArtifactFilePath(path) {
|
|
|
|
|
if (!path) {
|
|
|
|
|
throw new Error(`Artifact path: ${path}, is incorrectly provided`);
|
|
|
|
|
}
|
|
|
|
|
for (const invalidChar of invalidArtifactFilePathCharacters) {
|
|
|
|
|
if (path.includes(invalidChar)) {
|
|
|
|
|
throw new Error(`Artifact path is not valid: ${path}. Contains character: "${invalidChar}". Invalid characters include: ${invalidArtifactFilePathCharacters.toString()}.`);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
exports.checkArtifactFilePath = checkArtifactFilePath;
|
|
|
|
|
function createDirectoriesForArtifact(directories) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
for (const directory of directories) {
|
|
|
|
@@ -8422,6 +9069,25 @@ function sleep(milliseconds) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
exports.sleep = sleep;
|
|
|
|
|
function digestForStream(stream) {
|
|
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
const crc64 = new crc64_1.default();
|
|
|
|
|
const md5 = crypto_1.default.createHash('md5');
|
|
|
|
|
stream
|
|
|
|
|
.on('data', data => {
|
|
|
|
|
crc64.update(data);
|
|
|
|
|
md5.update(data);
|
|
|
|
|
})
|
|
|
|
|
.on('end', () => resolve({
|
|
|
|
|
crc64: crc64.digest('base64'),
|
|
|
|
|
md5: md5.digest('base64')
|
|
|
|
|
}))
|
|
|
|
|
.on('error', reject);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
exports.digestForStream = digestForStream;
|
|
|
|
|
//# sourceMappingURL=utils.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
@@ -8429,7 +9095,10 @@ exports.sleep = sleep;
|
|
|
|
|
/***/ 875:
|
|
|
|
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
const {promisify} = __webpack_require__(669);
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { promisify } = __webpack_require__(669);
|
|
|
|
|
const tmp = __webpack_require__(150);
|
|
|
|
|
|
|
|
|
|
// file
|
|
|
|
@@ -8737,71 +9406,6 @@ class Pattern {
|
|
|
|
|
exports.Pattern = Pattern;
|
|
|
|
|
//# sourceMappingURL=internal-pattern.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 950:
|
|
|
|
|
/***/ (function(__unusedmodule, exports) {
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
function getProxyUrl(reqUrl) {
|
|
|
|
|
let usingSsl = reqUrl.protocol === 'https:';
|
|
|
|
|
let proxyUrl;
|
|
|
|
|
if (checkBypass(reqUrl)) {
|
|
|
|
|
return proxyUrl;
|
|
|
|
|
}
|
|
|
|
|
let proxyVar;
|
|
|
|
|
if (usingSsl) {
|
|
|
|
|
proxyVar = process.env['https_proxy'] || process.env['HTTPS_PROXY'];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY'];
|
|
|
|
|
}
|
|
|
|
|
if (proxyVar) {
|
|
|
|
|
proxyUrl = new URL(proxyVar);
|
|
|
|
|
}
|
|
|
|
|
return proxyUrl;
|
|
|
|
|
}
|
|
|
|
|
exports.getProxyUrl = getProxyUrl;
|
|
|
|
|
function checkBypass(reqUrl) {
|
|
|
|
|
if (!reqUrl.hostname) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
let noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
|
|
|
|
if (!noProxy) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Determine the request port
|
|
|
|
|
let reqPort;
|
|
|
|
|
if (reqUrl.port) {
|
|
|
|
|
reqPort = Number(reqUrl.port);
|
|
|
|
|
}
|
|
|
|
|
else if (reqUrl.protocol === 'http:') {
|
|
|
|
|
reqPort = 80;
|
|
|
|
|
}
|
|
|
|
|
else if (reqUrl.protocol === 'https:') {
|
|
|
|
|
reqPort = 443;
|
|
|
|
|
}
|
|
|
|
|
// Format the request hostname and hostname with port
|
|
|
|
|
let upperReqHosts = [reqUrl.hostname.toUpperCase()];
|
|
|
|
|
if (typeof reqPort === 'number') {
|
|
|
|
|
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
|
|
|
|
}
|
|
|
|
|
// Compare request host against noproxy
|
|
|
|
|
for (let upperNoProxyItem of noProxy
|
|
|
|
|
.split(',')
|
|
|
|
|
.map(x => x.trim().toUpperCase())
|
|
|
|
|
.filter(x => x)) {
|
|
|
|
|
if (upperReqHosts.some(x => x === upperNoProxyItem)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
exports.checkBypass = checkBypass;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 972:
|
|
|
|
@@ -8984,6 +9588,14 @@ function safeTrimTrailingSeparator(p) {
|
|
|
|
|
exports.safeTrimTrailingSeparator = safeTrimTrailingSeparator;
|
|
|
|
|
//# sourceMappingURL=internal-path-helper.js.map
|
|
|
|
|
|
|
|
|
|
/***/ }),
|
|
|
|
|
|
|
|
|
|
/***/ 988:
|
|
|
|
|
/***/ (function(module, __unusedexports, __webpack_require__) {
|
|
|
|
|
|
|
|
|
|
module.exports = __webpack_require__(141);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***/ })
|
|
|
|
|
|
|
|
|
|
/******/ });
|