mirror of
https://github.com/crazy-max/ghaction-import-gpg.git
synced 2024-11-22 21:10:58 -05:00
Enhanced tests
This commit is contained in:
parent
db752f495e
commit
ffa7f19242
5 changed files with 74 additions and 128 deletions
|
@ -6,6 +6,10 @@ const userInfo = {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
flag: 'r'
|
flag: 'r'
|
||||||
}),
|
}),
|
||||||
|
pgp_base64: fs.readFileSync('.github/test-key-base64.pgp', {
|
||||||
|
encoding: 'utf8',
|
||||||
|
flag: 'r'
|
||||||
|
}),
|
||||||
passphrase: fs.readFileSync('.github/test-key.pass', {
|
passphrase: fs.readFileSync('.github/test-key.pass', {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
flag: 'r'
|
flag: 'r'
|
||||||
|
@ -47,7 +51,7 @@ describe('gpg', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('imports key (as base64 string) to GnuPG', async () => {
|
it('imports key (as base64 string) to GnuPG', async () => {
|
||||||
await gpg.importKey(Buffer.from(userInfo.pgp).toString('base64')).then(output => {
|
await gpg.importKey(userInfo.pgp_base64).then(output => {
|
||||||
console.log(output);
|
console.log(output);
|
||||||
expect(output).not.toEqual('');
|
expect(output).not.toEqual('');
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,10 @@ const userInfo = {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
flag: 'r'
|
flag: 'r'
|
||||||
}),
|
}),
|
||||||
|
pgp_base64: fs.readFileSync('.github/test-key-base64.pgp', {
|
||||||
|
encoding: 'utf8',
|
||||||
|
flag: 'r'
|
||||||
|
}),
|
||||||
passphrase: fs.readFileSync('.github/test-key.pass', {
|
passphrase: fs.readFileSync('.github/test-key.pass', {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
flag: 'r'
|
flag: 'r'
|
||||||
|
@ -28,7 +32,7 @@ describe('openpgp', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('returns a PGP private key from a base64 armored string', async () => {
|
it('returns a PGP private key from a base64 armored string', async () => {
|
||||||
await openpgp.readPrivateKey(Buffer.from(userInfo.pgp).toString('base64')).then(privateKey => {
|
await openpgp.readPrivateKey(userInfo.pgp_base64).then(privateKey => {
|
||||||
expect(privateKey.keyID).toEqual(userInfo.keyID);
|
expect(privateKey.keyID).toEqual(userInfo.keyID);
|
||||||
expect(privateKey.name).toEqual(userInfo.name);
|
expect(privateKey.name).toEqual(userInfo.name);
|
||||||
expect(privateKey.email).toEqual(userInfo.email);
|
expect(privateKey.email).toEqual(userInfo.email);
|
||||||
|
@ -46,4 +50,17 @@ describe('openpgp', () => {
|
||||||
});
|
});
|
||||||
}, 30000);
|
}, 30000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isArmored', () => {
|
||||||
|
it('returns true for armored key string', async () => {
|
||||||
|
await openpgp.isArmored(userInfo.pgp).then(armored => {
|
||||||
|
expect(armored).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('returns false for base64 key string', async () => {
|
||||||
|
await openpgp.isArmored(userInfo.pgp_base64).then(armored => {
|
||||||
|
expect(armored).toEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
163
dist/index.js
generated
vendored
163
dist/index.js
generated
vendored
|
@ -967,27 +967,14 @@ module.exports = require("child_process");
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// From https://github.com/actions/checkout/blob/master/src/state-helper.ts
|
// From https://github.com/actions/checkout/blob/master/src/state-helper.ts
|
||||||
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) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
if (mod && mod.__esModule) return mod;
|
if (mod && mod.__esModule) return mod;
|
||||||
var result = {};
|
var result = {};
|
||||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
__setModuleDefault(result, mod);
|
result["default"] = mod;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.IsPost = void 0;
|
|
||||||
const coreCommand = __importStar(__webpack_require__(431));
|
const coreCommand = __importStar(__webpack_require__(431));
|
||||||
/**
|
/**
|
||||||
* Indicates whether the POST action is running
|
* Indicates whether the POST action is running
|
||||||
|
@ -1007,25 +994,6 @@ if (!exports.IsPost) {
|
||||||
|
|
||||||
"use strict";
|
"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)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
@ -1035,6 +1003,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const git = __importStar(__webpack_require__(453));
|
const git = __importStar(__webpack_require__(453));
|
||||||
|
@ -1155,25 +1130,6 @@ else {
|
||||||
|
|
||||||
"use strict";
|
"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)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
@ -1183,12 +1139,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.killAgent = exports.deleteKey = exports.presetPassphrase = exports.configureAgent = exports.getKeygrip = exports.importKey = exports.getDirs = exports.getVersion = exports.agentConfig = void 0;
|
|
||||||
const fs = __importStar(__webpack_require__(747));
|
const fs = __importStar(__webpack_require__(747));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const os = __importStar(__webpack_require__(87));
|
const os = __importStar(__webpack_require__(87));
|
||||||
const exec = __importStar(__webpack_require__(807));
|
const exec = __importStar(__webpack_require__(807));
|
||||||
|
const openpgp = __importStar(__webpack_require__(781));
|
||||||
exports.agentConfig = `default-cache-ttl 7200
|
exports.agentConfig = `default-cache-ttl 7200
|
||||||
max-cache-ttl 31536000
|
max-cache-ttl 31536000
|
||||||
allow-preset-passphrase`;
|
allow-preset-passphrase`;
|
||||||
|
@ -1273,8 +1236,7 @@ exports.getDirs = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
exports.importKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
exports.importKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const keyFolder = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-import-gpg-'));
|
const keyFolder = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-import-gpg-'));
|
||||||
const keyPath = `${keyFolder}/key.pgp`;
|
const keyPath = `${keyFolder}/key.pgp`;
|
||||||
const armored = key.trimLeft().startsWith('---') ? key : Buffer.from(key, 'base64').toString();
|
fs.writeFileSync(keyPath, (yield openpgp.isArmored(key)) ? key : Buffer.from(key, 'base64').toString(), { mode: 0o600 });
|
||||||
fs.writeFileSync(keyPath, armored, { mode: 0o600 });
|
|
||||||
return yield exec
|
return yield exec
|
||||||
.exec('gpg', ['--import', '--batch', '--yes', keyPath], true)
|
.exec('gpg', ['--import', '--batch', '--yes', keyPath], true)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
|
@ -1448,25 +1410,6 @@ function escapeProperty(s) {
|
||||||
|
|
||||||
"use strict";
|
"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)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
@ -1476,8 +1419,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.setConfig = void 0;
|
|
||||||
const exec = __importStar(__webpack_require__(807));
|
const exec = __importStar(__webpack_require__(807));
|
||||||
const git = (args = []) => __awaiter(void 0, void 0, void 0, function* () {
|
const git = (args = []) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
return yield exec.exec(`git`, args, true).then(res => {
|
return yield exec.exec(`git`, args, true).then(res => {
|
||||||
|
@ -45690,25 +45639,6 @@ module.exports = require("fs");
|
||||||
|
|
||||||
"use strict";
|
"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)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
@ -45718,15 +45648,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
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;
|
||||||
|
};
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.generateKeyPair = exports.readPrivateKey = void 0;
|
|
||||||
const openpgp = __importStar(__webpack_require__(724));
|
const openpgp = __importStar(__webpack_require__(724));
|
||||||
const addressparser_1 = __importDefault(__webpack_require__(977));
|
const addressparser_1 = __importDefault(__webpack_require__(977));
|
||||||
exports.readPrivateKey = (armoredText) => __awaiter(void 0, void 0, void 0, function* () {
|
exports.readPrivateKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const { keys: [privateKey], err: err } = yield openpgp.key.readArmored(isArmored(armoredText) ? armoredText : Buffer.from(armoredText, 'base64').toString());
|
const { keys: [privateKey], err: err } = yield openpgp.key.readArmored((yield exports.isArmored(key)) ? key : Buffer.from(key, 'base64').toString());
|
||||||
if (err === null || err === void 0 ? void 0 : err.length) {
|
if (err === null || err === void 0 ? void 0 : err.length) {
|
||||||
throw err[0];
|
throw err[0];
|
||||||
}
|
}
|
||||||
|
@ -45755,7 +45691,9 @@ exports.generateKeyPair = (name, email, passphrase, numBits = 4096) => __awaiter
|
||||||
privateKey: keyPair.privateKeyArmored.replace(/\r\n/g, '\n').trim()
|
privateKey: keyPair.privateKeyArmored.replace(/\r\n/g, '\n').trim()
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
const isArmored = (text) => text.trimLeft().startsWith('---');
|
exports.isArmored = (text) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
return text.trimLeft().startsWith('---');
|
||||||
|
});
|
||||||
//# sourceMappingURL=openpgp.js.map
|
//# sourceMappingURL=openpgp.js.map
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
@ -45765,25 +45703,6 @@ const isArmored = (text) => text.trimLeft().startsWith('---');
|
||||||
|
|
||||||
"use strict";
|
"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)) __createBinding(result, mod, k);
|
|
||||||
__setModuleDefault(result, mod);
|
|
||||||
return result;
|
|
||||||
};
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
@ -45793,8 +45712,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.exec = void 0;
|
|
||||||
const actionsExec = __importStar(__webpack_require__(986));
|
const actionsExec = __importStar(__webpack_require__(986));
|
||||||
exports.exec = (command, args = [], silent) => __awaiter(void 0, void 0, void 0, function* () {
|
exports.exec = (command, args = [], silent) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
let stdout = '';
|
let stdout = '';
|
||||||
|
|
|
@ -2,6 +2,7 @@ import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as exec from './exec';
|
import * as exec from './exec';
|
||||||
|
import * as openpgp from './openpgp';
|
||||||
|
|
||||||
export const agentConfig = `default-cache-ttl 7200
|
export const agentConfig = `default-cache-ttl 7200
|
||||||
max-cache-ttl 31536000
|
max-cache-ttl 31536000
|
||||||
|
@ -105,10 +106,7 @@ export const getDirs = async (): Promise<Dirs> => {
|
||||||
export const importKey = async (key: string): Promise<string> => {
|
export const importKey = async (key: string): Promise<string> => {
|
||||||
const keyFolder: string = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-import-gpg-'));
|
const keyFolder: string = fs.mkdtempSync(path.join(os.tmpdir(), 'ghaction-import-gpg-'));
|
||||||
const keyPath: string = `${keyFolder}/key.pgp`;
|
const keyPath: string = `${keyFolder}/key.pgp`;
|
||||||
|
fs.writeFileSync(keyPath, (await openpgp.isArmored(key)) ? key : Buffer.from(key, 'base64').toString(), {mode: 0o600});
|
||||||
const armored: string = key.trimLeft().startsWith('---') ? key : Buffer.from(key, 'base64').toString();
|
|
||||||
|
|
||||||
fs.writeFileSync(keyPath, armored, {mode: 0o600});
|
|
||||||
|
|
||||||
return await exec
|
return await exec
|
||||||
.exec('gpg', ['--import', '--batch', '--yes', keyPath], true)
|
.exec('gpg', ['--import', '--batch', '--yes', keyPath], true)
|
||||||
|
|
|
@ -14,11 +14,11 @@ export interface KeyPair {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const readPrivateKey = async (armoredText: string): Promise<PrivateKey> => {
|
export const readPrivateKey = async (key: string): Promise<PrivateKey> => {
|
||||||
const {
|
const {
|
||||||
keys: [privateKey],
|
keys: [privateKey],
|
||||||
err: err
|
err: err
|
||||||
} = await openpgp.key.readArmored(isArmored(armoredText) ? armoredText : Buffer.from(armoredText, 'base64').toString());
|
} = await openpgp.key.readArmored((await isArmored(key)) ? key : Buffer.from(key, 'base64').toString());
|
||||||
|
|
||||||
if (err?.length) {
|
if (err?.length) {
|
||||||
throw err[0];
|
throw err[0];
|
||||||
|
@ -53,4 +53,6 @@ export const generateKeyPair = async (name: string, email: string, passphrase: s
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const isArmored = (text: string) => text.trimLeft().startsWith('---');
|
export const isArmored = async (text: string): Promise<boolean> => {
|
||||||
|
return text.trimLeft().startsWith('---');
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue