const fs = require('fs');
const process = require('process');
const jwt = require('jsonwebtoken');

// sign with RSA SHA256
// FIXME: move to env var
const cert = fs.readFileSync('private-key.pem');  // get private key

module.exports = generate;

function generate() {
  const payload = {
    // issued at time
    iat: Math.floor(new Date() / 1000),
    // JWT expiration time
    exp: (Math.floor(new Date() / 1000) + 60) * 5,
    // Integration's GitHub identifier
    iss: process.env.INTEGRATION_ID
  };

  return jwt.sign(payload, cert, {algorithm: 'RS256'});
}

const fs = require('fs');
const process = require('process');
const jwt = require('jsonwebtoken');

const cert = process.env.PRIVATE_KEY || fs.readFileSync('private-key.pem');

module.exports = generate;

function generate() {
  const payload = {
    // issued at time
    iat: Math.floor(new Date() / 1000),
    // JWT expiration time
    exp: (Math.floor(new Date() / 1000) + 60) * 5,
    // Integration's GitHub identifier
    iss: process.env.INTEGRATION_ID
  };

  // sign with RSA SHA256
  return jwt.sign(payload, cert, {algorithm: 'RS256'});
}

Load private key from env if possible
Load private key from env if possible
