UNPKG

2.83 kBJavaScriptView Raw
1/**
2 * Copyright 2017-2018 F5 Networks, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17'use strict';
18
19/* eslint-disable no-console */
20
21const assert = require('assert');
22const options = require('commander');
23const localCryptoUtil = require('../lib/localCryptoUtil');
24
25(function run() {
26 const runner = {
27
28 /**
29 * Runs the decryptDataInFile script
30 *
31 * Notes:
32 *
33 * + Only runs locally on a BIG-IP. Cannot run on a remote BIG-IP.
34 * + Uses tmsh rather than iControl REST so that we do not need to take in a password
35 *
36 * @param {String[]} argv - The process arguments
37 * @param {Function} cb - Optional cb to call when done
38 */
39 run(argv, cb) {
40 try {
41 options
42 .version('4.23.0-beta.3')
43 .option(
44 '--data-file <data_file>',
45 'Full path to file with data'
46 )
47 .option(
48 '--symmetric',
49 'Symmetric encryption used, decrypt accordingly'
50 )
51 .parse(argv);
52
53 assert.ok(options.dataFile, '--data-file must be specified');
54
55 localCryptoUtil.decryptDataFromFile(
56 options.dataFile,
57 {
58 symmetric: options.symmetric
59 }
60 )
61 .then((data) => {
62 console.log(data);
63 if (cb) {
64 cb(data);
65 }
66 })
67 .catch((err) => {
68 console.log('Decryption failed:', err.message);
69 if (cb) {
70 cb(err);
71 }
72 });
73 } catch (err) {
74 console.log('Decryption error:', err);
75 if (cb) {
76 cb(err);
77 }
78 }
79 }
80 };
81
82 module.exports = runner;
83
84 // If we're called from the command line, run
85 // This allows for test code to call us as a module
86 if (!module.parent) {
87 runner.run(process.argv);
88 }
89}());