@leverege/build-tools 2.2.2 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,92 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- const commandLineArgs = require('command-line-args');
5
-
6
- const commandLineUsage = require('command-line-usage');
7
-
8
- const Cloudflare = require('./CloudflareAPI');
9
-
10
- const defaultConfig = {
11
- account: 'leverege',
12
- proxy: true
13
- };
14
- const sections = [{
15
- content: 'Wraps Cloudflare to modify DNS configs for new UI/Servers'
16
- }, {
17
- header: 'Options',
18
- optionList: [{
19
- name: 'account',
20
- alias: 'a',
21
- description: 'Cloudflare account to use'
22
- }, {
23
- name: 'ipaddress',
24
- alias: 'i',
25
- description: 'IP address to point DNS account to (e.g. 35.178.29.10)'
26
- }, {
27
- name: 'url',
28
- alias: 'u',
29
- description: 'URL name (e.g. myserver)'
30
- }, {
31
- name: 'proxy',
32
- alias: 'p',
33
- description: 'Turn on Cloudflare proxy (optional)'
34
- }, {
35
- name: 'help',
36
- description: 'Print this usage guide.'
37
- }]
38
- }];
39
- const usage = commandLineUsage(sections);
40
- const optionDefinitions = [{
41
- name: 'account',
42
- alias: 'a',
43
- type: String,
44
- defaultValue: defaultConfig.account
45
- }, {
46
- name: 'ipaddress',
47
- alias: 'i',
48
- type: String
49
- }, {
50
- name: 'url',
51
- alias: 'u',
52
- type: String
53
- }, {
54
- name: 'proxy',
55
- alias: 'p',
56
- type: Boolean,
57
- defaultValue: defaultConfig.proxy
58
- }, {
59
- name: 'help',
60
- alias: 'h',
61
- type: Boolean
62
- }];
63
- const args = commandLineArgs(optionDefinitions);
64
-
65
- async function main() {
66
- if (args.help) {
67
- console.log(usage);
68
- }
69
-
70
- if (!args.url || !args.ipaddress) {
71
- console.log('\n*******************************************');
72
- console.log('** **');
73
- console.log('** Need to specify URL and/or IP address **');
74
- console.log('** **');
75
- console.log('*******************************************');
76
- console.log(usage);
77
- } else {
78
- const CF = new Cloudflare({ ...defaultConfig,
79
- args
80
- });
81
-
82
- try {
83
- await CF.createDNSRecord();
84
- console.log('Successfully created a new DNS record');
85
- console.log('It may take a few minutes for DNS to propagate');
86
- } catch (ex) {
87
- console.error(ex.message);
88
- }
89
- }
90
- }
91
-
92
- main();
@@ -1,256 +0,0 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.symbol");
4
-
5
- require("core-js/modules/es.symbol.description");
6
-
7
- require("core-js/modules/es.symbol.iterator");
8
-
9
- require("core-js/modules/es.array.from");
10
-
11
- require("core-js/modules/es.array.iterator");
12
-
13
- require("core-js/modules/es.array.slice");
14
-
15
- require("core-js/modules/es.object.to-string");
16
-
17
- require("core-js/modules/es.promise");
18
-
19
- require("core-js/modules/es.regexp.to-string");
20
-
21
- require("core-js/modules/es.string.iterator");
22
-
23
- require("core-js/modules/web.dom-collections.iterator");
24
-
25
- require("regenerator-runtime/runtime");
26
-
27
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
28
-
29
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
30
-
31
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
32
-
33
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
34
-
35
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
36
-
37
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
38
-
39
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
40
-
41
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
42
-
43
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
44
-
45
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
46
-
47
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
48
-
49
- var ora = require('ora');
50
-
51
- var fs = require('fs');
52
-
53
- var path = require('path');
54
-
55
- var _require = require('util'),
56
- promisify = _require.promisify;
57
-
58
- var CloudflareAPI = /*#__PURE__*/function () {
59
- function CloudflareAPI(options) {
60
- _classCallCheck(this, CloudflareAPI);
61
-
62
- var args = options.args;
63
- var url = args.url,
64
- proxy = args.proxy,
65
- ipaddress = args.ipaddress,
66
- account = args.account;
67
- this.url = url;
68
- this.proxy = proxy;
69
- this.ipaddress = ipaddress;
70
- this.spinner = ora({
71
- text: 'Creating DNS record...',
72
- spinner: 'monkey'
73
- });
74
- this.account = account;
75
- }
76
-
77
- _createClass(CloudflareAPI, [{
78
- key: "decrypt",
79
- value: function () {
80
- var _decrypt = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
81
- var projectId,
82
- keyRingId,
83
- cryptoKeyId,
84
- ciphertextFileName,
85
- plaintextFileName,
86
- kms,
87
- client,
88
- locationId,
89
- readFile,
90
- contentsBuffer,
91
- name,
92
- ciphertext,
93
- _yield$client$decrypt,
94
- _yield$client$decrypt2,
95
- result,
96
- writeFile,
97
- _args = arguments;
98
-
99
- return regeneratorRuntime.wrap(function _callee$(_context) {
100
- while (1) {
101
- switch (_context.prev = _context.next) {
102
- case 0:
103
- projectId = _args.length > 0 && _args[0] !== undefined ? _args[0] : 'leverege-docker-images';
104
- keyRingId = _args.length > 1 && _args[1] !== undefined ? _args[1] : 'build-tools';
105
- cryptoKeyId = _args.length > 2 && _args[2] !== undefined ? _args[2] : 'circle-ci';
106
- ciphertextFileName = _args.length > 3 && _args[3] !== undefined ? _args[3] : './accounts.json.enc';
107
- plaintextFileName = _args.length > 4 && _args[4] !== undefined ? _args[4] : './accounts.json';
108
- // Import the library and create a client
109
- kms = require('@google-cloud/kms');
110
- client = new kms.KeyManagementServiceClient(); // The location of the crypto key's key ring, e.g. "global"
111
-
112
- locationId = 'us-east4'; // Reads the file to be decrypted
113
-
114
- readFile = promisify(fs.readFile);
115
- _context.next = 11;
116
- return readFile(path.resolve(__dirname, ciphertextFileName));
117
-
118
- case 11:
119
- contentsBuffer = _context.sent;
120
- name = client.cryptoKeyPath(projectId, locationId, keyRingId, cryptoKeyId);
121
- ciphertext = contentsBuffer.toString('base64'); // Decrypts the file using the specified crypto key
122
-
123
- _context.next = 16;
124
- return client.decrypt({
125
- name: name,
126
- ciphertext: ciphertext
127
- });
128
-
129
- case 16:
130
- _yield$client$decrypt = _context.sent;
131
- _yield$client$decrypt2 = _slicedToArray(_yield$client$decrypt, 1);
132
- result = _yield$client$decrypt2[0];
133
- // Writes the decrypted file to disk
134
- writeFile = promisify(fs.writeFile);
135
- _context.next = 22;
136
- return writeFile(path.resolve(__dirname, plaintextFileName), Buffer.from(result.plaintext, 'base64'));
137
-
138
- case 22:
139
- case "end":
140
- return _context.stop();
141
- }
142
- }
143
- }, _callee);
144
- }));
145
-
146
- function decrypt() {
147
- return _decrypt.apply(this, arguments);
148
- }
149
-
150
- return decrypt;
151
- }()
152
- }, {
153
- key: "setAccountValues",
154
- value: function setAccountValues() {
155
- var accountJson = require(path.resolve(__dirname, './accounts.json'));
156
-
157
- var accountInfo = accountJson[this.account];
158
- var email = accountInfo.email,
159
- key = accountInfo.key,
160
- zone = accountInfo.zone;
161
- this.cf = require('cloudflare')({
162
- email: email,
163
- key: key
164
- });
165
- this.zone = zone;
166
- }
167
- }, {
168
- key: "deleteSecrets",
169
- value: function () {
170
- var _deleteSecrets = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
171
- var deleteFile;
172
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
173
- while (1) {
174
- switch (_context2.prev = _context2.next) {
175
- case 0:
176
- deleteFile = promisify(fs.unlink);
177
- _context2.next = 3;
178
- return deleteFile(path.resolve(__dirname, './accounts.json'));
179
-
180
- case 3:
181
- case "end":
182
- return _context2.stop();
183
- }
184
- }
185
- }, _callee2);
186
- }));
187
-
188
- function deleteSecrets() {
189
- return _deleteSecrets.apply(this, arguments);
190
- }
191
-
192
- return deleteSecrets;
193
- }()
194
- }, {
195
- key: "createDNSRecord",
196
- value: function () {
197
- var _createDNSRecord = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
198
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
199
- while (1) {
200
- switch (_context3.prev = _context3.next) {
201
- case 0:
202
- _context3.prev = 0;
203
- this.spinner.start();
204
- this.spinner.text = 'Decrypting Cloudflare secrets...';
205
- _context3.next = 5;
206
- return this.decrypt();
207
-
208
- case 5:
209
- this.spinner.text = 'Initializing Cloudflare API...';
210
- this.setAccountValues();
211
- this.spinner.text = 'Adding A name record...';
212
- _context3.next = 10;
213
- return this.cf.dnsRecords.add(this.zone, {
214
- type: 'A',
215
- name: this.url,
216
- content: this.ipaddress,
217
- proxied: this.proxy
218
- });
219
-
220
- case 10:
221
- this.spinner.text = 'Removing secrets...';
222
- _context3.next = 13;
223
- return this.deleteSecrets();
224
-
225
- case 13:
226
- this.spinner.stop();
227
- _context3.next = 21;
228
- break;
229
-
230
- case 16:
231
- _context3.prev = 16;
232
- _context3.t0 = _context3["catch"](0);
233
- this.spinner.stop();
234
- console.log(_context3.t0);
235
- throw _context3.t0;
236
-
237
- case 21:
238
- case "end":
239
- return _context3.stop();
240
- }
241
- }
242
- }, _callee3, this, [[0, 16]]);
243
- }));
244
-
245
- function createDNSRecord() {
246
- return _createDNSRecord.apply(this, arguments);
247
- }
248
-
249
- return createDNSRecord;
250
- }()
251
- }]);
252
-
253
- return CloudflareAPI;
254
- }();
255
-
256
- module.exports = CloudflareAPI;
@@ -1,153 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- require("core-js/modules/es.symbol");
5
-
6
- require("core-js/modules/es.array.filter");
7
-
8
- require("core-js/modules/es.array.for-each");
9
-
10
- require("core-js/modules/es.object.get-own-property-descriptor");
11
-
12
- require("core-js/modules/es.object.get-own-property-descriptors");
13
-
14
- require("core-js/modules/es.object.keys");
15
-
16
- require("core-js/modules/es.object.to-string");
17
-
18
- require("core-js/modules/es.promise");
19
-
20
- require("core-js/modules/web.dom-collections.for-each");
21
-
22
- require("regenerator-runtime/runtime");
23
-
24
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
25
-
26
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
27
-
28
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
-
30
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
31
-
32
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
33
-
34
- var commandLineArgs = require('command-line-args');
35
-
36
- var commandLineUsage = require('command-line-usage');
37
-
38
- var Cloudflare = require('./CloudflareAPI');
39
-
40
- var defaultConfig = {
41
- account: 'leverege',
42
- proxy: true
43
- };
44
- var sections = [{
45
- content: 'Wraps Cloudflare to modify DNS configs for new UI/Servers'
46
- }, {
47
- header: 'Options',
48
- optionList: [{
49
- name: 'account',
50
- alias: 'a',
51
- description: 'Cloudflare account to use'
52
- }, {
53
- name: 'ipaddress',
54
- alias: 'i',
55
- description: 'IP address to point DNS account to (e.g. 35.178.29.10)'
56
- }, {
57
- name: 'url',
58
- alias: 'u',
59
- description: 'URL name (e.g. myserver)'
60
- }, {
61
- name: 'proxy',
62
- alias: 'p',
63
- description: 'Turn on Cloudflare proxy (optional)'
64
- }, {
65
- name: 'help',
66
- description: 'Print this usage guide.'
67
- }]
68
- }];
69
- var usage = commandLineUsage(sections);
70
- var optionDefinitions = [{
71
- name: 'account',
72
- alias: 'a',
73
- type: String,
74
- defaultValue: defaultConfig.account
75
- }, {
76
- name: 'ipaddress',
77
- alias: 'i',
78
- type: String
79
- }, {
80
- name: 'url',
81
- alias: 'u',
82
- type: String
83
- }, {
84
- name: 'proxy',
85
- alias: 'p',
86
- type: Boolean,
87
- defaultValue: defaultConfig.proxy
88
- }, {
89
- name: 'help',
90
- alias: 'h',
91
- type: Boolean
92
- }];
93
- var args = commandLineArgs(optionDefinitions);
94
-
95
- function main() {
96
- return _main.apply(this, arguments);
97
- }
98
-
99
- function _main() {
100
- _main = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
101
- var CF;
102
- return regeneratorRuntime.wrap(function _callee$(_context) {
103
- while (1) {
104
- switch (_context.prev = _context.next) {
105
- case 0:
106
- if (args.help) {
107
- console.log(usage);
108
- }
109
-
110
- if (!(!args.url || !args.ipaddress)) {
111
- _context.next = 10;
112
- break;
113
- }
114
-
115
- console.log('\n*******************************************');
116
- console.log('** **');
117
- console.log('** Need to specify URL and/or IP address **');
118
- console.log('** **');
119
- console.log('*******************************************');
120
- console.log(usage);
121
- _context.next = 21;
122
- break;
123
-
124
- case 10:
125
- CF = new Cloudflare(_objectSpread({}, defaultConfig, {
126
- args: args
127
- }));
128
- _context.prev = 11;
129
- _context.next = 14;
130
- return CF.createDNSRecord();
131
-
132
- case 14:
133
- console.log('Successfully created a new DNS record');
134
- console.log('It may take a few minutes for DNS to propagate');
135
- _context.next = 21;
136
- break;
137
-
138
- case 18:
139
- _context.prev = 18;
140
- _context.t0 = _context["catch"](11);
141
- console.error(_context.t0.message);
142
-
143
- case 21:
144
- case "end":
145
- return _context.stop();
146
- }
147
- }
148
- }, _callee, null, [[11, 18]]);
149
- }));
150
- return _main.apply(this, arguments);
151
- }
152
-
153
- main();