navy 4.1.2-rc.2 → 5.0.0
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.
- package/lib/cli/config/index.js +57 -241
- package/lib/cli/config/wrapper.js +12 -36
- package/lib/cli/develop.js +63 -167
- package/lib/cli/doctor/clean-compose-files.js +19 -73
- package/lib/cli/doctor/index.js +34 -154
- package/lib/cli/doctor/invalid-compose-config.js +20 -110
- package/lib/cli/doctor/invalid-state.js +22 -115
- package/lib/cli/doctor/util.js +26 -93
- package/lib/cli/external-ip.js +9 -39
- package/lib/cli/health.js +18 -67
- package/lib/cli/https.js +92 -0
- package/lib/cli/import.js +22 -59
- package/lib/cli/index.js +11 -17
- package/lib/cli/lan-ip.js +18 -60
- package/lib/cli/launch.js +46 -127
- package/lib/cli/live.js +37 -111
- package/lib/cli/local-ip.js +16 -53
- package/lib/cli/logs.js +7 -35
- package/lib/cli/open.js +11 -45
- package/lib/cli/program.js +145 -167
- package/lib/cli/ps.js +36 -105
- package/lib/cli/refresh-config.js +18 -62
- package/lib/cli/run.js +8 -39
- package/lib/cli/status.js +41 -201
- package/lib/cli/updates.js +68 -160
- package/lib/cli/util/get-or-initialise-navy.js +14 -57
- package/lib/cli/util/import.js +33 -83
- package/lib/cli/util/index.js +10 -12
- package/lib/cli/util/reconfigure.js +12 -102
- package/lib/cli/wait-for-healthy.js +53 -100
- package/lib/config-provider.js +25 -127
- package/lib/config-providers/filesystem/index.js +58 -235
- package/lib/config-providers/npm/__tests__/util.js +3 -6
- package/lib/config-providers/npm/index.js +60 -231
- package/lib/config-providers/npm/util.js +6 -9
- package/lib/config.js +39 -76
- package/lib/driver-logging.js +23 -28
- package/lib/driver.js +5 -7
- package/lib/drivers/docker-compose/client.js +64 -172
- package/lib/drivers/docker-compose/index.js +153 -464
- package/lib/errors.js +27 -61
- package/lib/http-proxy.js +72 -158
- package/lib/index.js +26 -29
- package/lib/middleware/add-service-proxy-config.js +76 -0
- package/lib/middleware/develop.js +9 -23
- package/lib/middleware/helpers.js +20 -25
- package/lib/middleware/port-override.js +15 -37
- package/lib/middleware/set-env-vars.js +14 -18
- package/lib/middleware/set-image.js +12 -18
- package/lib/middleware/set-logging-driver.js +14 -18
- package/lib/middleware/tag-override.js +11 -19
- package/lib/navy/default-middleware.js +13 -27
- package/lib/navy/index.js +438 -1761
- package/lib/navy/middleware.js +15 -100
- package/lib/navy/plugin-interface.js +28 -108
- package/lib/navy/state.js +58 -147
- package/lib/navy/util.js +2 -1
- package/lib/service.js +5 -3
- package/lib/util/__tests__/external-ip.js +20 -96
- package/lib/util/__tests__/registry-client.js +11 -24
- package/lib/util/__tests__/service-host.js +19 -116
- package/lib/util/docker-client.js +10 -13
- package/lib/util/exec-async.js +9 -27
- package/lib/util/external-ip.js +48 -126
- package/lib/util/fs.js +7 -6
- package/lib/util/get-lan-ip.js +15 -52
- package/lib/util/has-update.js +23 -73
- package/lib/util/https.js +213 -0
- package/lib/util/navyrc.js +12 -50
- package/lib/util/registry-client.js +41 -112
- package/lib/util/service-host.js +40 -129
- package/lib/util/table.js +11 -21
- package/package.json +14 -14
- package/LICENSE +0 -21
- package/lib/middleware/add-virtual-hosts.js +0 -147
package/lib/util/has-update.js
CHANGED
|
@@ -1,87 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
2
4
|
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
8
|
+
exports.default = hasUpdate;
|
|
6
9
|
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
10
|
-
|
|
11
|
-
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
|
12
|
-
|
|
13
|
-
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
|
14
|
-
|
|
15
|
-
var _simpleDockerRegistryClient = require('simple-docker-registry-client');
|
|
16
|
-
|
|
17
|
-
var _registryClient = require('./registry-client');
|
|
18
|
-
|
|
19
|
-
var _dockerClient = require('./docker-client');
|
|
20
|
-
|
|
21
|
-
var _dockerClient2 = _interopRequireDefault(_dockerClient);
|
|
22
|
-
|
|
23
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
-
|
|
25
|
-
exports.default = function () {
|
|
26
|
-
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(imageWithTag, currentImageId, navyFile) {
|
|
27
|
-
var imageConfig, currentImageContainerId, image, client, manifest, lastLayer;
|
|
28
|
-
return _regenerator2.default.wrap(function _callee$(_context) {
|
|
29
|
-
while (1) {
|
|
30
|
-
switch (_context.prev = _context.next) {
|
|
31
|
-
case 0:
|
|
32
|
-
_context.next = 2;
|
|
33
|
-
return _dockerClient2.default.getImage(currentImageId).inspect();
|
|
34
|
-
|
|
35
|
-
case 2:
|
|
36
|
-
imageConfig = _context.sent;
|
|
37
|
-
currentImageContainerId = imageConfig.ContainerConfig.Image;
|
|
38
|
-
image = (0, _simpleDockerRegistryClient.imageFromImageWithTag)(imageWithTag);
|
|
39
|
-
_context.next = 7;
|
|
40
|
-
return (0, _registryClient.getRegistryClient)(image, navyFile);
|
|
41
|
-
|
|
42
|
-
case 7:
|
|
43
|
-
client = _context.sent;
|
|
44
|
-
manifest = void 0;
|
|
45
|
-
_context.prev = 9;
|
|
46
|
-
_context.next = 12;
|
|
47
|
-
return client.request((0, _simpleDockerRegistryClient.localImageFromImage)(image) + '/manifests/' + (0, _simpleDockerRegistryClient.tagFromImageWithTag)(imageWithTag));
|
|
48
|
-
|
|
49
|
-
case 12:
|
|
50
|
-
manifest = _context.sent;
|
|
51
|
-
_context.next = 20;
|
|
52
|
-
break;
|
|
53
|
-
|
|
54
|
-
case 15:
|
|
55
|
-
_context.prev = 15;
|
|
56
|
-
_context.t0 = _context['catch'](9);
|
|
57
|
-
|
|
58
|
-
if (!(_context.t0.body && _context.t0.body.errors[0].code === 'MANIFEST_UNKNOWN')) {
|
|
59
|
-
_context.next = 19;
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
10
|
+
var _simpleDockerRegistryClient = require("simple-docker-registry-client");
|
|
62
11
|
|
|
63
|
-
|
|
12
|
+
var _registryClient = require("./registry-client");
|
|
64
13
|
|
|
65
|
-
|
|
66
|
-
return _context.abrupt('return', 'UNKNOWN_ERROR');
|
|
14
|
+
var _dockerClient = _interopRequireDefault(require("./docker-client"));
|
|
67
15
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
16
|
+
async function hasUpdate(imageWithTag, currentImageId, navyFile) {
|
|
17
|
+
const imageConfig = await _dockerClient.default.getImage(currentImageId).inspect();
|
|
18
|
+
const currentImageContainerId = imageConfig.ContainerConfig.Image;
|
|
19
|
+
const image = (0, _simpleDockerRegistryClient.imageFromImageWithTag)(imageWithTag);
|
|
20
|
+
const client = await (0, _registryClient.getRegistryClient)(image, navyFile);
|
|
21
|
+
let manifest;
|
|
71
22
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
}));
|
|
23
|
+
try {
|
|
24
|
+
manifest = await client.request((0, _simpleDockerRegistryClient.localImageFromImage)(image) + '/manifests/' + (0, _simpleDockerRegistryClient.tagFromImageWithTag)(imageWithTag));
|
|
25
|
+
} catch (ex) {
|
|
26
|
+
if (ex.body && ex.body.errors[0].code === 'MANIFEST_UNKNOWN') {
|
|
27
|
+
return 'UNKNOWN_REMOTE';
|
|
28
|
+
}
|
|
79
29
|
|
|
80
|
-
|
|
81
|
-
return _ref.apply(this, arguments);
|
|
30
|
+
return 'UNKNOWN_ERROR';
|
|
82
31
|
}
|
|
83
32
|
|
|
84
|
-
|
|
85
|
-
|
|
33
|
+
const lastLayer = JSON.parse(manifest.history[0].v1Compatibility);
|
|
34
|
+
return lastLayer.container_config.Image !== currentImageContainerId;
|
|
35
|
+
}
|
|
86
36
|
|
|
87
37
|
module.exports = exports.default;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createCert = createCert;
|
|
9
|
+
exports.generateRootCa = generateRootCa;
|
|
10
|
+
exports.getCertsPath = getCertsPath;
|
|
11
|
+
exports.removeCert = removeCert;
|
|
12
|
+
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
|
|
15
|
+
var _config = require("../config");
|
|
16
|
+
|
|
17
|
+
var _errors = require("../errors");
|
|
18
|
+
|
|
19
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
20
|
+
|
|
21
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
22
|
+
|
|
23
|
+
var _nodeForge = require("node-forge");
|
|
24
|
+
|
|
25
|
+
var _navy = require("../navy");
|
|
26
|
+
|
|
27
|
+
const debug = require('debug')('navy:https');
|
|
28
|
+
|
|
29
|
+
function getCertsPath(create = false) {
|
|
30
|
+
const certsPath = _path.default.join((0, _config.getConfigDir)(), 'tls-certs');
|
|
31
|
+
|
|
32
|
+
if (!_fs.default.existsSync(certsPath)) {
|
|
33
|
+
if (create) {
|
|
34
|
+
debug(`Create ${certsPath} dir`); // $FlowIgnore
|
|
35
|
+
|
|
36
|
+
_fs.default.mkdirSync(certsPath, {
|
|
37
|
+
recursive: true
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
return '';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return certsPath;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function removeCert(opts) {
|
|
48
|
+
const certsPath = getCertsPath();
|
|
49
|
+
const navy = await (0, _navy.getNavy)(opts.navy);
|
|
50
|
+
const serviceUrl = await navy.url(opts.disable);
|
|
51
|
+
const baseName = serviceUrl.split('//')[1];
|
|
52
|
+
const extensions = ['crt', 'key'];
|
|
53
|
+
|
|
54
|
+
for (const ext of extensions) {
|
|
55
|
+
const file = `${certsPath}/${baseName}.${ext}`;
|
|
56
|
+
|
|
57
|
+
if (_fs.default.existsSync(file)) {
|
|
58
|
+
try {
|
|
59
|
+
await _fs.default.unlinkSync(file);
|
|
60
|
+
debug(`File ${file} removed.`);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
throw new _errors.NavyError(err);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function generateRootCa() {
|
|
69
|
+
const tlsRootCaDir = (0, _config.getConfig)().tlsRootCaDir || _config.DEFAULT_TLS_ROOT_CA_DIR;
|
|
70
|
+
|
|
71
|
+
if (!_fs.default.existsSync(tlsRootCaDir)) {
|
|
72
|
+
debug(`Creating ${tlsRootCaDir} Root CA dir`);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
// $FlowIgnore
|
|
76
|
+
_fs.default.mkdirSync(tlsRootCaDir, {
|
|
77
|
+
recursive: true
|
|
78
|
+
});
|
|
79
|
+
} catch (err) {
|
|
80
|
+
throw new _errors.NavyError(err);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (_fs.default.existsSync(`${tlsRootCaDir}/ca.crt`) && _fs.default.existsSync(`${tlsRootCaDir}/ca.key`)) {
|
|
85
|
+
debug(`Root CA already exists, skipping generation`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
debug('Generating Root CA');
|
|
90
|
+
debug('Generating 2048-bit key-pair...');
|
|
91
|
+
|
|
92
|
+
const keys = _nodeForge.pki.rsa.generateKeyPair(2048);
|
|
93
|
+
|
|
94
|
+
debug('Creating self-signed certificate...');
|
|
95
|
+
|
|
96
|
+
const cert = _nodeForge.pki.createCertificate();
|
|
97
|
+
|
|
98
|
+
cert.publicKey = keys.publicKey;
|
|
99
|
+
cert.serialNumber = '01';
|
|
100
|
+
cert.validity.notBefore = new Date();
|
|
101
|
+
cert.validity.notAfter = new Date();
|
|
102
|
+
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 5);
|
|
103
|
+
const attrs = [{
|
|
104
|
+
name: 'commonName',
|
|
105
|
+
value: 'navy-dev-ca.local'
|
|
106
|
+
}, {
|
|
107
|
+
name: 'organizationName',
|
|
108
|
+
value: 'navy-dev'
|
|
109
|
+
}];
|
|
110
|
+
cert.setSubject(attrs);
|
|
111
|
+
cert.setIssuer(attrs);
|
|
112
|
+
cert.setExtensions([{
|
|
113
|
+
name: 'basicConstraints',
|
|
114
|
+
cA: true
|
|
115
|
+
}, {
|
|
116
|
+
name: 'subjectKeyIdentifier'
|
|
117
|
+
}, {
|
|
118
|
+
name: 'authorityKeyIdentifier'
|
|
119
|
+
}]);
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
// self-sign certificate
|
|
123
|
+
cert.sign(keys.privateKey, _nodeForge.md.sha256.create()); // PEM-format keys and cert
|
|
124
|
+
|
|
125
|
+
const pem = {
|
|
126
|
+
privateKey: _nodeForge.pki.privateKeyToPem(keys.privateKey),
|
|
127
|
+
publicKey: _nodeForge.pki.publicKeyToPem(keys.publicKey),
|
|
128
|
+
certificate: _nodeForge.pki.certificateToPem(cert)
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
_fs.default.writeFileSync(tlsRootCaDir + '/ca.key', pem.privateKey, {
|
|
132
|
+
mode: 0o400
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
_fs.default.writeFileSync(tlsRootCaDir + '/ca.pub.key', pem.publicKey, {
|
|
136
|
+
mode: 0o640
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
_fs.default.writeFileSync(tlsRootCaDir + '/ca.crt', pem.certificate, {
|
|
140
|
+
mode: 0o640
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
console.log(_chalk.default.green(`✅ CA Certificate created at ${tlsRootCaDir}/ca.crt`));
|
|
144
|
+
console.log(_chalk.default.yellow(`⚠️ Importing a self-signed CA into a browser/truststore/keychain is not advisable ⚠️`));
|
|
145
|
+
} catch (e) {
|
|
146
|
+
throw new _errors.NavyError(e);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async function createCert(opts) {
|
|
151
|
+
const tlsRootCaDir = (0, _config.getConfig)().tlsRootCaDir || _config.DEFAULT_TLS_ROOT_CA_DIR;
|
|
152
|
+
|
|
153
|
+
const certName = opts.hostName || opts.serviceUrl.split('//')[1];
|
|
154
|
+
const certsPath = getCertsPath(true);
|
|
155
|
+
|
|
156
|
+
if (_fs.default.existsSync(`${certsPath}/${certName}.crt`)) {
|
|
157
|
+
debug(`Certificate for ${certName} already exists, skipping generation`);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
await generateRootCa();
|
|
162
|
+
|
|
163
|
+
const caCertString = _fs.default.readFileSync(`${tlsRootCaDir}/ca.crt`, 'utf8');
|
|
164
|
+
|
|
165
|
+
const caKeyString = _fs.default.readFileSync(`${tlsRootCaDir}/ca.key`, 'utf8');
|
|
166
|
+
|
|
167
|
+
debug(`Generating cert for ${certName} in ${certsPath}`);
|
|
168
|
+
|
|
169
|
+
const privateCAKey = _nodeForge.pki.privateKeyFromPem(caKeyString);
|
|
170
|
+
|
|
171
|
+
const keys = _nodeForge.pki.rsa.generateKeyPair(2048);
|
|
172
|
+
|
|
173
|
+
const cert = _nodeForge.pki.createCertificate();
|
|
174
|
+
|
|
175
|
+
const caCert = _nodeForge.pki.certificateFromPem(caCertString);
|
|
176
|
+
|
|
177
|
+
cert.publicKey = keys.publicKey;
|
|
178
|
+
cert.serialNumber = Math.floor(Math.random() * (99 - 2) + 2).toString();
|
|
179
|
+
cert.validity.notBefore = new Date();
|
|
180
|
+
cert.validity.notBefore.setDate(cert.validity.notBefore.getDate() - 1);
|
|
181
|
+
cert.validity.notAfter = new Date();
|
|
182
|
+
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 2);
|
|
183
|
+
const attrs = [{
|
|
184
|
+
name: 'commonName',
|
|
185
|
+
value: certName
|
|
186
|
+
}, {
|
|
187
|
+
name: 'organizationName',
|
|
188
|
+
value: 'navy-dev'
|
|
189
|
+
}];
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
cert.setSubject(attrs);
|
|
193
|
+
cert.setIssuer(caCert.subject.attributes);
|
|
194
|
+
cert.setExtensions([{
|
|
195
|
+
name: 'extKeyUsage',
|
|
196
|
+
serverAuth: true
|
|
197
|
+
}]);
|
|
198
|
+
cert.sign(privateCAKey, _nodeForge.md.sha256.create()); // PEM-format keys and cert
|
|
199
|
+
|
|
200
|
+
const pem = {
|
|
201
|
+
privateKey: _nodeForge.pki.privateKeyToPem(keys.privateKey),
|
|
202
|
+
certificate: _nodeForge.pki.certificateToPem(cert) // publicKey: pki.publicKeyToPem(keys.publicKey),
|
|
203
|
+
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
_fs.default.writeFileSync(`${certsPath}/${certName}.key`, pem.privateKey);
|
|
207
|
+
|
|
208
|
+
_fs.default.writeFileSync(`${certsPath}/${certName}.crt`, pem.certificate); // fs.writeFileSync(`${certsPath}/${certName}.pub.key`, pem.publicKey)
|
|
209
|
+
|
|
210
|
+
} catch (e) {
|
|
211
|
+
throw new _errors.NavyError(e);
|
|
212
|
+
}
|
|
213
|
+
}
|
package/lib/util/navyrc.js
CHANGED
|
@@ -1,60 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
2
4
|
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
8
|
+
exports.default = getNavyRc;
|
|
6
9
|
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
10
|
-
|
|
11
|
-
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
|
12
|
-
|
|
13
|
-
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
|
14
|
-
|
|
15
|
-
var _path = require('path');
|
|
16
|
-
|
|
17
|
-
var _path2 = _interopRequireDefault(_path);
|
|
18
|
-
|
|
19
|
-
var _fs = require('./fs');
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
20
11
|
|
|
21
|
-
var
|
|
12
|
+
var _fs = _interopRequireDefault(require("./fs"));
|
|
22
13
|
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
while (1) {
|
|
29
|
-
switch (_context.prev = _context.next) {
|
|
30
|
-
case 0:
|
|
31
|
-
_context.prev = 0;
|
|
32
|
-
_context.t0 = JSON;
|
|
33
|
-
_context.next = 4;
|
|
34
|
-
return _fs2.default.readFileAsync(_path2.default.join(dir, '.navyrc'));
|
|
35
|
-
|
|
36
|
-
case 4:
|
|
37
|
-
_context.t1 = _context.sent;
|
|
38
|
-
return _context.abrupt('return', _context.t0.parse.call(_context.t0, _context.t1));
|
|
39
|
-
|
|
40
|
-
case 8:
|
|
41
|
-
_context.prev = 8;
|
|
42
|
-
_context.t2 = _context['catch'](0);
|
|
43
|
-
return _context.abrupt('return', null);
|
|
44
|
-
|
|
45
|
-
case 11:
|
|
46
|
-
case 'end':
|
|
47
|
-
return _context.stop();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, _callee, this, [[0, 8]]);
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
function getNavyRc(_x) {
|
|
54
|
-
return _ref.apply(this, arguments);
|
|
14
|
+
async function getNavyRc(dir) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(await _fs.default.readFileAsync(_path.default.join(dir, '.navyrc')));
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
return null;
|
|
55
19
|
}
|
|
56
|
-
|
|
57
|
-
return getNavyRc;
|
|
58
|
-
}();
|
|
20
|
+
}
|
|
59
21
|
|
|
60
22
|
module.exports = exports.default;
|
|
@@ -1,122 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
2
4
|
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
var _regenerator = require('babel-runtime/regenerator');
|
|
9
|
-
|
|
10
|
-
var _regenerator2 = _interopRequireDefault(_regenerator);
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
|
|
13
|
-
|
|
14
|
-
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
|
|
15
|
-
|
|
16
|
-
// the url which docker stores in .docker/config.json for auth
|
|
17
|
-
|
|
18
|
-
var getDockerUserConfig = function () {
|
|
19
|
-
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
|
|
20
|
-
var rawConfig, config;
|
|
21
|
-
return _regenerator2.default.wrap(function _callee$(_context) {
|
|
22
|
-
while (1) {
|
|
23
|
-
switch (_context.prev = _context.next) {
|
|
24
|
-
case 0:
|
|
25
|
-
(0, _invariant2.default)(process.env.HOME, 'NO_HOME_DIRECTORY: No home directory available');
|
|
26
|
-
|
|
27
|
-
_context.prev = 1;
|
|
28
|
-
_context.next = 4;
|
|
29
|
-
return _fs2.default.readFileAsync(_path2.default.join(process.env.HOME, '.docker', 'config.json'));
|
|
30
|
-
|
|
31
|
-
case 4:
|
|
32
|
-
rawConfig = _context.sent;
|
|
33
|
-
config = JSON.parse(rawConfig);
|
|
34
|
-
return _context.abrupt('return', config);
|
|
35
|
-
|
|
36
|
-
case 9:
|
|
37
|
-
_context.prev = 9;
|
|
38
|
-
_context.t0 = _context['catch'](1);
|
|
39
|
-
return _context.abrupt('return', null);
|
|
40
|
-
|
|
41
|
-
case 12:
|
|
42
|
-
case 'end':
|
|
43
|
-
return _context.stop();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}, _callee, this, [[1, 9]]);
|
|
47
|
-
}));
|
|
48
|
-
|
|
49
|
-
return function getDockerUserConfig() {
|
|
50
|
-
return _ref.apply(this, arguments);
|
|
51
|
-
};
|
|
52
|
-
}();
|
|
53
|
-
|
|
54
|
-
var getRegistryClient = exports.getRegistryClient = function () {
|
|
55
|
-
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(image, navyFile) {
|
|
56
|
-
var registry, opts, auth;
|
|
57
|
-
return _regenerator2.default.wrap(function _callee2$(_context2) {
|
|
58
|
-
while (1) {
|
|
59
|
-
switch (_context2.prev = _context2.next) {
|
|
60
|
-
case 0:
|
|
61
|
-
registry = registryFromImage(image);
|
|
62
|
-
opts = {
|
|
63
|
-
registry: 'https://' + registry,
|
|
64
|
-
allowUnauthorized: navyFile && navyFile.ignoreUnauthorizedRequestsForRegistries && navyFile.ignoreUnauthorizedRequestsForRegistries.indexOf(registry) !== -1
|
|
65
|
-
|
|
66
|
-
// try and work out auth
|
|
67
|
-
};
|
|
68
|
-
_context2.t0 = getAuthForRegistry;
|
|
69
|
-
_context2.t1 = registry;
|
|
70
|
-
_context2.next = 6;
|
|
71
|
-
return getDockerUserConfig();
|
|
72
|
-
|
|
73
|
-
case 6:
|
|
74
|
-
_context2.t2 = _context2.sent;
|
|
75
|
-
auth = (0, _context2.t0)(_context2.t1, _context2.t2);
|
|
76
|
-
|
|
77
|
-
opts.credentials = credentialsFromAuth(auth);
|
|
78
|
-
|
|
79
|
-
return _context2.abrupt('return', {
|
|
80
|
-
request: function request(url) {
|
|
81
|
-
return (0, _simpleDockerRegistryClient.registryRequest)(url, opts);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
case 10:
|
|
86
|
-
case 'end':
|
|
87
|
-
return _context2.stop();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}, _callee2, this);
|
|
91
|
-
}));
|
|
92
|
-
|
|
93
|
-
return function getRegistryClient(_x, _x2) {
|
|
94
|
-
return _ref2.apply(this, arguments);
|
|
95
|
-
};
|
|
96
|
-
}();
|
|
97
|
-
|
|
8
|
+
exports.credentialsFromAuth = credentialsFromAuth;
|
|
98
9
|
exports.getAuthForRegistry = getAuthForRegistry;
|
|
10
|
+
exports.getRegistryClient = getRegistryClient;
|
|
99
11
|
exports.registryFromImage = registryFromImage;
|
|
100
|
-
exports.credentialsFromAuth = credentialsFromAuth;
|
|
101
12
|
|
|
102
|
-
var _path = require(
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
103
14
|
|
|
104
|
-
var
|
|
15
|
+
var _invariant = _interopRequireDefault(require("invariant"));
|
|
105
16
|
|
|
106
|
-
var
|
|
17
|
+
var _simpleDockerRegistryClient = require("simple-docker-registry-client");
|
|
107
18
|
|
|
108
|
-
var
|
|
19
|
+
var _fs = _interopRequireDefault(require("./fs"));
|
|
109
20
|
|
|
110
|
-
|
|
21
|
+
const DEFAULT_REGISTRY = 'registry-1.docker.io'; // docker v2 registry URL
|
|
111
22
|
|
|
112
|
-
|
|
23
|
+
const DEFAULT_REGISTRY_AUTH = 'https://index.docker.io/v1/'; // the url which docker stores in .docker/config.json for auth
|
|
113
24
|
|
|
114
|
-
|
|
25
|
+
async function getDockerUserConfig() {
|
|
26
|
+
(0, _invariant.default)(process.env.HOME, "NO_HOME_DIRECTORY: No home directory available");
|
|
115
27
|
|
|
116
|
-
|
|
28
|
+
try {
|
|
29
|
+
const rawConfig = await _fs.default.readFileAsync(_path.default.join(process.env.HOME, '.docker', 'config.json'));
|
|
30
|
+
const config = JSON.parse(rawConfig);
|
|
31
|
+
return config;
|
|
32
|
+
} catch (ex) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
117
36
|
|
|
118
|
-
|
|
119
|
-
var DEFAULT_REGISTRY_AUTH = 'https://index.docker.io/v1/';function getAuthForRegistry(registry, dockerUserConfig) {
|
|
37
|
+
function getAuthForRegistry(registry, dockerUserConfig) {
|
|
120
38
|
if (registry === DEFAULT_REGISTRY) {
|
|
121
39
|
registry = DEFAULT_REGISTRY_AUTH;
|
|
122
40
|
}
|
|
@@ -129,19 +47,16 @@ var DEFAULT_REGISTRY_AUTH = 'https://index.docker.io/v1/';function getAuthForReg
|
|
|
129
47
|
}
|
|
130
48
|
|
|
131
49
|
function registryFromImage(image) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
50
|
+
const parsedRegistry = image.match(/([a-zA-Z0-9-.:]+)\/[a-zA-Z0-9-]+\/[a-zA-Z0-9-]+/);
|
|
51
|
+
const registry = parsedRegistry != null && parsedRegistry.length > 1 ? parsedRegistry[1] : DEFAULT_REGISTRY;
|
|
135
52
|
return registry;
|
|
136
53
|
}
|
|
137
54
|
|
|
138
55
|
function credentialsFromAuth(auth) {
|
|
139
56
|
if (auth && auth.auth) {
|
|
140
|
-
(0,
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
var parts = decoded.split(':');
|
|
144
|
-
|
|
57
|
+
(0, _invariant.default)(auth.auth.match(/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/) != null, "DOCKER_CONFIG_INVALID_AUTH_BASE64: Invalid base64 string in docker/config.json for registry authentication");
|
|
58
|
+
const decoded = Buffer.from(auth.auth, 'base64').toString();
|
|
59
|
+
const parts = decoded.split(':');
|
|
145
60
|
return {
|
|
146
61
|
username: parts[0],
|
|
147
62
|
password: parts[1]
|
|
@@ -149,4 +64,18 @@ function credentialsFromAuth(auth) {
|
|
|
149
64
|
}
|
|
150
65
|
|
|
151
66
|
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function getRegistryClient(image, navyFile) {
|
|
70
|
+
const registry = registryFromImage(image);
|
|
71
|
+
const opts = {
|
|
72
|
+
registry: `https://${registry}`,
|
|
73
|
+
allowUnauthorized: navyFile && navyFile.ignoreUnauthorizedRequestsForRegistries && navyFile.ignoreUnauthorizedRequestsForRegistries.indexOf(registry) !== -1
|
|
74
|
+
}; // try and work out auth
|
|
75
|
+
|
|
76
|
+
const auth = getAuthForRegistry(registry, await getDockerUserConfig());
|
|
77
|
+
opts.credentials = credentialsFromAuth(auth);
|
|
78
|
+
return {
|
|
79
|
+
request: url => (0, _simpleDockerRegistryClient.registryRequest)(url, opts)
|
|
80
|
+
};
|
|
152
81
|
}
|