/************************************************************************* * * Troven CONFIDENTIAL * __________________ * * (c) 2017-2020 Troven Ventures Pty Ltd * All Rights Reserved. * * NOTICE: All information contained herein is, and remains * the property of Troven Pty Ltd and its licensors, * if any. The intellectual and technical concepts contained * herein are proprietary to Troven Pty Ltd * and its suppliers and may be covered by International and Regional Patents, * patents in process, and are protected by trade secret or copyright law. * Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained * from Troven Pty Ltd. */ import {IChassisPlugin, IChassisContext, IChassisSecrets} from "../interfaces"; import * as _ from "lodash"; /** * secrets * --------- * Used when a method is not found * * @type {{name: string, title: string, fn: module.exports.fn}} */ export default class SecretsPlugin implements IChassisPlugin { name = "secrets"; title = "ENV-based secrets"; install(_context: IChassisContext) { let options = _.extend( { "unlockKey": "" }, _context.config.secrets ) _context.secrets = new SimpleSecrets(options, options.unlockKey); } } class SimpleSecrets implements IChassisSecrets { constructor(protected options: any, unlockKey?: string) { unlockKey && this.unlock(unlockKey); } unlock(_ignored: string): void { } get(name: string): Promise { return new Promise( (resolve, rejects) => { let _secret = process.env[name] _secret?resolve(_secret):rejects(); }); } }