// Retrieve Google Signin Keys (with cache control) function getGoogleKeyByKeyId(keyId) { if (cache[keyId] && cache.expiresAt > new Date()) { return cache[keyId]; } return new Promise((resolve, reject) => { https.get(`https://www.googleapis.com/oauth2/v3/certs`, res => { let data = ''; res.on('data', chunk => { data += chunk.toString('utf8'); }); res.on('end', () => { const {keys} = JSON.parse(data); const pems = keys.reduce((pems, {n: modulus, e: exposant, kid}) => Object.assign(pems, {[kid]: rsaPublicKeyToPEM(modulus, exposant)}), {}); if (res.headers['cache-control']) { var expire = res.headers['cache-control'].match(/max-age=([0-9]+)/); if (expire) { cache = Object.assign({}, pems, {expiresAt: new Date((new Date()).getTime() + Number(expire[1]) * 1000)}); } } resolve(pems[keyId]); }); }).on('error', reject); }); }
function getPipInstaller() { // install pip return new Promise((resolve, reject) => { const pipFilePath = path.join(__dirname, "get-pip.py"); if (fs.existsSync(pipFilePath)) return resolve(pipFilePath); const file = fs.createWriteStream(pipFilePath); const request = https.get(pipUrl, function(response) { response.pipe(file); file.on("finish", function() { file.close(() => { resolve(pipFilePath); }); }); file.on("error", function(err) { fs.unlink(pipFilePath); reject(err); }); }); }); }
function getPipInstaller() { // install pip return new Promise((resolve, reject) => { const pipFilePath = path.join(__dirname, "get-pip.py"); if (fs.existsSync(pipFilePath)) return resolve(pipFilePath); const file = fs.createWriteStream(pipFilePath); const request = https.get(pipUrl, function(response) { response.pipe(file); file.on("finish", function() { file.close(() => { resolve(pipFilePath); }); }); file.on("error", function(err) { fs.unlink(pipFilePath); reject(err); }); }); }); }