mirror of
https://github.com/crazy-max/ghaction-import-gpg.git
synced 2024-12-24 20:22:07 -05:00
Use built-in getExecOutput
(#102)
Co-authored-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
93f53be329
commit
dd220e93c3
5 changed files with 180 additions and 205 deletions
137
dist/index.js
generated
vendored
137
dist/index.js
generated
vendored
|
@ -64,68 +64,6 @@ exports.setOutput = setOutput;
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 757:
|
|
||||||
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
||||||
|
|
||||||
"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.prototype.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.exec = void 0;
|
|
||||||
const actionsExec = __importStar(__webpack_require__(514));
|
|
||||||
exports.exec = (command, args = [], silent) => __awaiter(void 0, void 0, void 0, function* () {
|
|
||||||
let stdout = '';
|
|
||||||
let stderr = '';
|
|
||||||
const options = {
|
|
||||||
silent: silent,
|
|
||||||
ignoreReturnCode: true
|
|
||||||
};
|
|
||||||
options.listeners = {
|
|
||||||
stdout: (data) => {
|
|
||||||
stdout += data.toString();
|
|
||||||
},
|
|
||||||
stderr: (data) => {
|
|
||||||
stderr += data.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const returnCode = yield actionsExec.exec(command, args, options);
|
|
||||||
return {
|
|
||||||
success: returnCode === 0,
|
|
||||||
stdout: stdout.trim(),
|
|
||||||
stderr: stderr.trim()
|
|
||||||
};
|
|
||||||
});
|
|
||||||
//# sourceMappingURL=exec.js.map
|
|
||||||
|
|
||||||
/***/ }),
|
|
||||||
|
|
||||||
/***/ 374:
|
/***/ 374:
|
||||||
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
@ -161,10 +99,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.setConfig = void 0;
|
exports.setConfig = void 0;
|
||||||
const exec = __importStar(__webpack_require__(757));
|
const exec = __importStar(__webpack_require__(514));
|
||||||
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
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput(`git`, args, {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
return res.stdout.trim();
|
return res.stdout.trim();
|
||||||
|
@ -215,10 +158,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.killAgent = exports.deleteKey = exports.presetPassphrase = exports.configureAgent = exports.getKeygrips = exports.importKey = exports.getDirs = exports.getVersion = exports.agentConfig = void 0;
|
exports.killAgent = exports.deleteKey = exports.presetPassphrase = exports.configureAgent = exports.getKeygrips = exports.importKey = exports.getDirs = exports.getVersion = exports.agentConfig = void 0;
|
||||||
|
const exec = __importStar(__webpack_require__(514));
|
||||||
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__(757));
|
|
||||||
const openpgp = __importStar(__webpack_require__(666));
|
const openpgp = __importStar(__webpack_require__(666));
|
||||||
exports.agentConfig = `default-cache-ttl 7200
|
exports.agentConfig = `default-cache-ttl 7200
|
||||||
max-cache-ttl 31536000
|
max-cache-ttl 31536000
|
||||||
|
@ -234,8 +177,13 @@ const getGnupgHome = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
return homedir;
|
return homedir;
|
||||||
});
|
});
|
||||||
const gpgConnectAgent = (command) => __awaiter(void 0, void 0, void 0, function* () {
|
const gpgConnectAgent = (command) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
return yield exec.exec(`gpg-connect-agent "${command}" /bye`, [], true).then(res => {
|
return yield exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput(`gpg-connect-agent "${command}" /bye`, [], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
||||||
|
@ -247,8 +195,13 @@ const gpgConnectAgent = (command) => __awaiter(void 0, void 0, void 0, function*
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
return yield exec.exec('gpg', ['--version'], true).then(res => {
|
return yield exec
|
||||||
if (res.stderr != '') {
|
.getExecOutput('gpg', ['--version'], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
let gnupgVersion = '';
|
let gnupgVersion = '';
|
||||||
|
@ -271,8 +224,13 @@ exports.getVersion = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
exports.getDirs = () => __awaiter(void 0, void 0, void 0, function* () {
|
exports.getDirs = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
return yield exec.exec('gpgconf', ['--list-dirs'], true).then(res => {
|
return yield exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('gpgconf', ['--list-dirs'], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
let libdir = '';
|
let libdir = '';
|
||||||
|
@ -306,9 +264,12 @@ exports.importKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const keyPath = `${keyFolder}/key.pgp`;
|
const keyPath = `${keyFolder}/key.pgp`;
|
||||||
fs.writeFileSync(keyPath, (yield openpgp.isArmored(key)) ? key : Buffer.from(key, 'base64').toString(), { mode: 0o600 });
|
fs.writeFileSync(keyPath, (yield openpgp.isArmored(key)) ? key : Buffer.from(key, 'base64').toString(), { mode: 0o600 });
|
||||||
return yield exec
|
return yield exec
|
||||||
.exec('gpg', ['--import', '--batch', '--yes', keyPath], true)
|
.getExecOutput('gpg', ['--import', '--batch', '--yes', keyPath], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
if (res.stderr != '') {
|
if (res.stderr != '') {
|
||||||
|
@ -321,10 +282,12 @@ exports.importKey = (key) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
exports.getKeygrips = (fingerprint) => __awaiter(void 0, void 0, void 0, function* () {
|
exports.getKeygrips = (fingerprint) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
return yield exec.exec('gpg', ['--batch', '--with-colons', '--with-keygrip', '--list-secret-keys', fingerprint], true).then(res => {
|
return yield exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('gpg', ['--batch', '--with-colons', '--with-keygrip', '--list-secret-keys', fingerprint], {
|
||||||
throw new Error(res.stderr);
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
let keygrips = [];
|
let keygrips = [];
|
||||||
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
||||||
if (line.startsWith('grp')) {
|
if (line.startsWith('grp')) {
|
||||||
|
@ -348,13 +311,23 @@ exports.presetPassphrase = (keygrip, passphrase) => __awaiter(void 0, void 0, vo
|
||||||
return yield gpgConnectAgent(`KEYINFO ${keygrip}`);
|
return yield gpgConnectAgent(`KEYINFO ${keygrip}`);
|
||||||
});
|
});
|
||||||
exports.deleteKey = (fingerprint) => __awaiter(void 0, void 0, void 0, function* () {
|
exports.deleteKey = (fingerprint) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
yield exec.exec('gpg', ['--batch', '--yes', '--delete-secret-keys', fingerprint], true).then(res => {
|
yield exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('gpg', ['--batch', '--yes', '--delete-secret-keys', fingerprint], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
yield exec.exec('gpg', ['--batch', '--yes', '--delete-keys', fingerprint], true).then(res => {
|
yield exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('gpg', ['--batch', '--yes', '--delete-keys', fingerprint], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
|
restoreMocks: true,
|
||||||
coverageDirectory: 'coverage',
|
coverageDirectory: 'coverage',
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
|
|
34
src/exec.ts
34
src/exec.ts
|
@ -1,34 +0,0 @@
|
||||||
import * as actionsExec from '@actions/exec';
|
|
||||||
import {ExecOptions} from '@actions/exec';
|
|
||||||
|
|
||||||
export interface ExecResult {
|
|
||||||
success: boolean;
|
|
||||||
stdout: string;
|
|
||||||
stderr: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const exec = async (command: string, args: string[] = [], silent: boolean): Promise<ExecResult> => {
|
|
||||||
let stdout: string = '';
|
|
||||||
let stderr: string = '';
|
|
||||||
|
|
||||||
const options: ExecOptions = {
|
|
||||||
silent: silent,
|
|
||||||
ignoreReturnCode: true
|
|
||||||
};
|
|
||||||
options.listeners = {
|
|
||||||
stdout: (data: Buffer) => {
|
|
||||||
stdout += data.toString();
|
|
||||||
},
|
|
||||||
stderr: (data: Buffer) => {
|
|
||||||
stderr += data.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const returnCode: number = await actionsExec.exec(command, args, options);
|
|
||||||
|
|
||||||
return {
|
|
||||||
success: returnCode === 0,
|
|
||||||
stdout: stdout.trim(),
|
|
||||||
stderr: stderr.trim()
|
|
||||||
};
|
|
||||||
};
|
|
19
src/git.ts
19
src/git.ts
|
@ -1,12 +1,17 @@
|
||||||
import * as exec from './exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
const git = async (args: string[] = []): Promise<string> => {
|
const git = async (args: string[] = []): Promise<string> => {
|
||||||
return await exec.exec(`git`, args, true).then(res => {
|
return await exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput(`git`, args, {
|
||||||
throw new Error(res.stderr);
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
return res.stdout.trim();
|
})
|
||||||
});
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr);
|
||||||
|
}
|
||||||
|
return res.stdout.trim();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function setConfig(key: string, value: string): Promise<void> {
|
export async function setConfig(key: string, value: string): Promise<void> {
|
||||||
|
|
194
src/gpg.ts
194
src/gpg.ts
|
@ -1,7 +1,7 @@
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
import * as fs from 'fs';
|
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 openpgp from './openpgp';
|
import * as openpgp from './openpgp';
|
||||||
|
|
||||||
export const agentConfig = `default-cache-ttl 7200
|
export const agentConfig = `default-cache-ttl 7200
|
||||||
|
@ -32,75 +32,90 @@ const getGnupgHome = async (): Promise<string> => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const gpgConnectAgent = async (command: string): Promise<string> => {
|
const gpgConnectAgent = async (command: string): Promise<string> => {
|
||||||
return await exec.exec(`gpg-connect-agent "${command}" /bye`, [], true).then(res => {
|
return await exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput(`gpg-connect-agent "${command}" /bye`, [], {
|
||||||
throw new Error(res.stderr);
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
})
|
||||||
if (line.startsWith('ERR')) {
|
.then(res => {
|
||||||
throw new Error(line);
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
}
|
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
||||||
return res.stdout.trim();
|
if (line.startsWith('ERR')) {
|
||||||
});
|
throw new Error(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res.stdout.trim();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getVersion = async (): Promise<Version> => {
|
export const getVersion = async (): Promise<Version> => {
|
||||||
return await exec.exec('gpg', ['--version'], true).then(res => {
|
return await exec
|
||||||
if (res.stderr != '') {
|
.getExecOutput('gpg', ['--version'], {
|
||||||
throw new Error(res.stderr);
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
|
})
|
||||||
let gnupgVersion: string = '';
|
.then(res => {
|
||||||
let libgcryptVersion: string = '';
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr);
|
||||||
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
|
||||||
if (line.startsWith('gpg (GnuPG) ')) {
|
|
||||||
gnupgVersion = line.substr('gpg (GnuPG) '.length).trim();
|
|
||||||
} else if (line.startsWith('gpg (GnuPG/MacGPG2) ')) {
|
|
||||||
gnupgVersion = line.substr('gpg (GnuPG/MacGPG2) '.length).trim();
|
|
||||||
} else if (line.startsWith('libgcrypt ')) {
|
|
||||||
libgcryptVersion = line.substr('libgcrypt '.length).trim();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
let gnupgVersion: string = '';
|
||||||
gnupg: gnupgVersion,
|
let libgcryptVersion: string = '';
|
||||||
libgcrypt: libgcryptVersion
|
|
||||||
};
|
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
||||||
});
|
if (line.startsWith('gpg (GnuPG) ')) {
|
||||||
|
gnupgVersion = line.substr('gpg (GnuPG) '.length).trim();
|
||||||
|
} else if (line.startsWith('gpg (GnuPG/MacGPG2) ')) {
|
||||||
|
gnupgVersion = line.substr('gpg (GnuPG/MacGPG2) '.length).trim();
|
||||||
|
} else if (line.startsWith('libgcrypt ')) {
|
||||||
|
libgcryptVersion = line.substr('libgcrypt '.length).trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
gnupg: gnupgVersion,
|
||||||
|
libgcrypt: libgcryptVersion
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getDirs = async (): Promise<Dirs> => {
|
export const getDirs = async (): Promise<Dirs> => {
|
||||||
return await exec.exec('gpgconf', ['--list-dirs'], true).then(res => {
|
return await exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('gpgconf', ['--list-dirs'], {
|
||||||
throw new Error(res.stderr);
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
|
})
|
||||||
let libdir: string = '';
|
.then(res => {
|
||||||
let libexecdir: string = '';
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
let datadir: string = '';
|
throw new Error(res.stderr);
|
||||||
let homedir: string = '';
|
|
||||||
|
|
||||||
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
|
||||||
if (line.startsWith('libdir:')) {
|
|
||||||
libdir = line.substr('libdir:'.length).replace('%3a', ':').trim();
|
|
||||||
} else if (line.startsWith('libexecdir:')) {
|
|
||||||
libexecdir = line.substr('libexecdir:'.length).replace('%3a', ':').trim();
|
|
||||||
} else if (line.startsWith('datadir:')) {
|
|
||||||
datadir = line.substr('datadir:'.length).replace('%3a', ':').trim();
|
|
||||||
} else if (line.startsWith('homedir:')) {
|
|
||||||
homedir = line.substr('homedir:'.length).replace('%3a', ':').trim();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
let libdir: string = '';
|
||||||
libdir: libdir,
|
let libexecdir: string = '';
|
||||||
libexecdir: libexecdir,
|
let datadir: string = '';
|
||||||
datadir: datadir,
|
let homedir: string = '';
|
||||||
homedir: homedir
|
|
||||||
};
|
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
||||||
});
|
if (line.startsWith('libdir:')) {
|
||||||
|
libdir = line.substr('libdir:'.length).replace('%3a', ':').trim();
|
||||||
|
} else if (line.startsWith('libexecdir:')) {
|
||||||
|
libexecdir = line.substr('libexecdir:'.length).replace('%3a', ':').trim();
|
||||||
|
} else if (line.startsWith('datadir:')) {
|
||||||
|
datadir = line.substr('datadir:'.length).replace('%3a', ':').trim();
|
||||||
|
} else if (line.startsWith('homedir:')) {
|
||||||
|
homedir = line.substr('homedir:'.length).replace('%3a', ':').trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
libdir: libdir,
|
||||||
|
libexecdir: libexecdir,
|
||||||
|
datadir: datadir,
|
||||||
|
homedir: homedir
|
||||||
|
};
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const importKey = async (key: string): Promise<string> => {
|
export const importKey = async (key: string): Promise<string> => {
|
||||||
|
@ -109,9 +124,12 @@ export const importKey = async (key: string): Promise<string> => {
|
||||||
fs.writeFileSync(keyPath, (await openpgp.isArmored(key)) ? key : Buffer.from(key, 'base64').toString(), {mode: 0o600});
|
fs.writeFileSync(keyPath, (await openpgp.isArmored(key)) ? key : Buffer.from(key, 'base64').toString(), {mode: 0o600});
|
||||||
|
|
||||||
return await exec
|
return await exec
|
||||||
.exec('gpg', ['--import', '--batch', '--yes', keyPath], true)
|
.getExecOutput('gpg', ['--import', '--batch', '--yes', keyPath], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
if (res.stderr != '') {
|
if (res.stderr != '') {
|
||||||
|
@ -125,18 +143,20 @@ export const importKey = async (key: string): Promise<string> => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getKeygrips = async (fingerprint: string): Promise<Array<string>> => {
|
export const getKeygrips = async (fingerprint: string): Promise<Array<string>> => {
|
||||||
return await exec.exec('gpg', ['--batch', '--with-colons', '--with-keygrip', '--list-secret-keys', fingerprint], true).then(res => {
|
return await exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('gpg', ['--batch', '--with-colons', '--with-keygrip', '--list-secret-keys', fingerprint], {
|
||||||
throw new Error(res.stderr);
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
let keygrips: Array<string> = [];
|
})
|
||||||
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
.then(res => {
|
||||||
if (line.startsWith('grp')) {
|
let keygrips: Array<string> = [];
|
||||||
keygrips.push(line.replace(/(grp|:)/g, '').trim());
|
for (let line of res.stdout.replace(/\r/g, '').trim().split(/\n/g)) {
|
||||||
|
if (line.startsWith('grp')) {
|
||||||
|
keygrips.push(line.replace(/(grp|:)/g, '').trim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return keygrips;
|
||||||
return keygrips;
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const configureAgent = async (config: string): Promise<void> => {
|
export const configureAgent = async (config: string): Promise<void> => {
|
||||||
|
@ -154,16 +174,26 @@ export const presetPassphrase = async (keygrip: string, passphrase: string): Pro
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deleteKey = async (fingerprint: string): Promise<void> => {
|
export const deleteKey = async (fingerprint: string): Promise<void> => {
|
||||||
await exec.exec('gpg', ['--batch', '--yes', '--delete-secret-keys', fingerprint], true).then(res => {
|
await exec
|
||||||
if (res.stderr != '' && !res.success) {
|
.getExecOutput('gpg', ['--batch', '--yes', '--delete-secret-keys', fingerprint], {
|
||||||
throw new Error(res.stderr);
|
ignoreReturnCode: true,
|
||||||
}
|
silent: true
|
||||||
});
|
})
|
||||||
await exec.exec('gpg', ['--batch', '--yes', '--delete-keys', fingerprint], true).then(res => {
|
.then(res => {
|
||||||
if (res.stderr != '' && !res.success) {
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
throw new Error(res.stderr);
|
throw new Error(res.stderr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
await exec
|
||||||
|
.getExecOutput('gpg', ['--batch', '--yes', '--delete-keys', fingerprint], {
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
silent: true
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (res.stderr.length > 0 && res.exitCode != 0) {
|
||||||
|
throw new Error(res.stderr);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const killAgent = async (): Promise<void> => {
|
export const killAgent = async (): Promise<void> => {
|
||||||
|
|
Loading…
Reference in a new issue