navy 6.0.0 → 7.0.0-alpha.2

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.
Files changed (149) hide show
  1. package/lib/__tests__/config-provider.js +75 -0
  2. package/lib/__tests__/config.js +130 -0
  3. package/lib/__tests__/driver-logging.js +148 -0
  4. package/lib/__tests__/driver.js +19 -0
  5. package/lib/__tests__/errors.js +49 -0
  6. package/lib/__tests__/http-proxy.js +214 -0
  7. package/lib/__tests__/index.js +25 -0
  8. package/lib/__tests__/service.js +16 -0
  9. package/lib/cli/__tests__/develop.js +239 -0
  10. package/lib/cli/__tests__/external-ip.js +68 -0
  11. package/lib/cli/__tests__/health.js +257 -0
  12. package/lib/cli/__tests__/https.js +210 -0
  13. package/lib/cli/__tests__/import.js +110 -0
  14. package/lib/cli/__tests__/index.js +118 -0
  15. package/lib/cli/__tests__/lan-ip.js +90 -0
  16. package/lib/cli/__tests__/launch.js +179 -0
  17. package/lib/cli/__tests__/live.js +155 -0
  18. package/lib/cli/__tests__/local-ip.js +72 -0
  19. package/lib/cli/__tests__/logs.js +52 -0
  20. package/lib/cli/__tests__/open.js +65 -0
  21. package/lib/cli/__tests__/program.js +472 -0
  22. package/lib/cli/__tests__/ps.js +345 -0
  23. package/lib/cli/__tests__/refresh-config.js +95 -0
  24. package/lib/cli/__tests__/run.js +54 -0
  25. package/lib/cli/__tests__/status.js +204 -0
  26. package/lib/cli/__tests__/updates.js +243 -0
  27. package/lib/cli/__tests__/wait-for-healthy.js +134 -0
  28. package/lib/cli/config/__tests__/index.js +275 -0
  29. package/lib/cli/config/__tests__/wrapper.js +53 -0
  30. package/lib/cli/config/index.js +19 -37
  31. package/lib/cli/config/wrapper.js +0 -6
  32. package/lib/cli/develop.js +7 -21
  33. package/lib/cli/doctor/__tests__/clean-compose-files.js +78 -0
  34. package/lib/cli/doctor/__tests__/index.js +67 -0
  35. package/lib/cli/doctor/__tests__/invalid-compose-config.js +103 -0
  36. package/lib/cli/doctor/__tests__/invalid-state.js +83 -0
  37. package/lib/cli/doctor/__tests__/util.js +91 -0
  38. package/lib/cli/doctor/clean-compose-files.js +5 -13
  39. package/lib/cli/doctor/index.js +0 -12
  40. package/lib/cli/doctor/invalid-compose-config.js +0 -4
  41. package/lib/cli/doctor/invalid-state.js +0 -6
  42. package/lib/cli/doctor/util.js +0 -10
  43. package/lib/cli/external-ip.js +0 -4
  44. package/lib/cli/health.js +0 -12
  45. package/lib/cli/https.js +9 -25
  46. package/lib/cli/import.js +0 -12
  47. package/lib/cli/index.js +0 -9
  48. package/lib/cli/lan-ip.js +2 -8
  49. package/lib/cli/launch.js +0 -9
  50. package/lib/cli/live.js +6 -16
  51. package/lib/cli/local-ip.js +2 -7
  52. package/lib/cli/logs.js +0 -3
  53. package/lib/cli/open.js +2 -7
  54. package/lib/cli/program.js +73 -101
  55. package/lib/cli/ps.js +1 -21
  56. package/lib/cli/refresh-config.js +0 -7
  57. package/lib/cli/run.js +0 -3
  58. package/lib/cli/status.js +0 -11
  59. package/lib/cli/updates.js +0 -22
  60. package/lib/cli/util/__tests__/get-or-initialise-navy.js +66 -0
  61. package/lib/cli/util/__tests__/import.js +123 -0
  62. package/lib/cli/util/__tests__/index.js +17 -0
  63. package/lib/cli/util/__tests__/merge-action-options.js +47 -0
  64. package/lib/cli/util/__tests__/reconfigure.js +78 -0
  65. package/lib/cli/util/get-or-initialise-navy.js +0 -7
  66. package/lib/cli/util/import.js +0 -9
  67. package/lib/cli/util/index.js +0 -2
  68. package/lib/cli/util/merge-action-options.js +20 -0
  69. package/lib/cli/util/reconfigure.js +0 -4
  70. package/lib/cli/wait-for-healthy.js +0 -21
  71. package/lib/client/registry/__tests__/get-credentials.js +62 -0
  72. package/lib/client/registry/__tests__/get-endpoint.js +124 -0
  73. package/lib/client/registry/__tests__/get-fat-manifest.js +67 -0
  74. package/lib/client/registry/__tests__/get-token.js +66 -0
  75. package/lib/client/registry/__tests__/helpers.js +26 -0
  76. package/lib/client/registry/get-credentials.js +3 -9
  77. package/lib/client/registry/get-endpoint.js +29 -63
  78. package/lib/client/registry/get-fat-manifest.js +2 -9
  79. package/lib/client/registry/get-token.js +2 -13
  80. package/lib/client/registry/helpers.js +0 -4
  81. package/lib/config-provider.js +0 -12
  82. package/lib/config-providers/filesystem/__tests__/index.js +176 -0
  83. package/lib/config-providers/filesystem/index.js +5 -23
  84. package/lib/config-providers/npm/__tests__/index.js +226 -0
  85. package/lib/config-providers/npm/__tests__/util.js +1 -2
  86. package/lib/config-providers/npm/index.js +12 -35
  87. package/lib/config-providers/npm/util.js +0 -3
  88. package/lib/config.js +4 -19
  89. package/lib/domain/__tests__/container-image.js +81 -0
  90. package/lib/domain/__tests__/oci-api-specification.js +23 -0
  91. package/lib/domain/container-image.js +8 -21
  92. package/lib/domain/oci-api-specification.js +3 -5
  93. package/lib/driver-logging.js +0 -19
  94. package/lib/driver.js +0 -4
  95. package/lib/drivers/docker-compose/__tests__/client.js +249 -0
  96. package/lib/drivers/docker-compose/__tests__/index.js +430 -0
  97. package/lib/drivers/docker-compose/client.js +0 -16
  98. package/lib/drivers/docker-compose/index.js +7 -49
  99. package/lib/errors.js +0 -10
  100. package/lib/http-proxy.js +28 -23
  101. package/lib/index.js +1 -9
  102. package/lib/middleware/__tests__/add-service-proxy-config.js +258 -0
  103. package/lib/middleware/__tests__/develop.js +120 -0
  104. package/lib/middleware/__tests__/helpers.js +154 -0
  105. package/lib/middleware/__tests__/port-override.js +125 -0
  106. package/lib/middleware/__tests__/set-env-vars.js +94 -0
  107. package/lib/middleware/__tests__/set-image.js +76 -0
  108. package/lib/middleware/__tests__/set-logging-driver.js +94 -0
  109. package/lib/middleware/__tests__/tag-override.js +92 -0
  110. package/lib/middleware/add-service-proxy-config.js +8 -16
  111. package/lib/middleware/develop.js +2 -5
  112. package/lib/middleware/helpers.js +6 -12
  113. package/lib/middleware/port-override.js +5 -8
  114. package/lib/middleware/set-env-vars.js +6 -6
  115. package/lib/middleware/set-image.js +4 -5
  116. package/lib/middleware/set-logging-driver.js +6 -6
  117. package/lib/middleware/tag-override.js +4 -6
  118. package/lib/navy/__tests__/default-middleware.js +40 -0
  119. package/lib/navy/__tests__/index.js +1612 -0
  120. package/lib/navy/__tests__/middleware.js +71 -0
  121. package/lib/navy/__tests__/plugin-interface.js +121 -0
  122. package/lib/navy/__tests__/state.js +103 -0
  123. package/lib/navy/__tests__/util.js +24 -0
  124. package/lib/navy/default-middleware.js +0 -10
  125. package/lib/navy/index.js +83 -138
  126. package/lib/navy/middleware.js +0 -6
  127. package/lib/navy/plugin-interface.js +2 -10
  128. package/lib/navy/state.js +12 -24
  129. package/lib/navy/util.js +0 -1
  130. package/lib/service.js +2 -3
  131. package/lib/util/__tests__/exec-async.js +83 -0
  132. package/lib/util/__tests__/external-ip.js +97 -2
  133. package/lib/util/__tests__/get-lan-ip.js +46 -0
  134. package/lib/util/__tests__/has-update.js +136 -0
  135. package/lib/util/__tests__/https.js +301 -0
  136. package/lib/util/__tests__/navyrc.js +45 -0
  137. package/lib/util/__tests__/service-host.js +63 -5
  138. package/lib/util/__tests__/table.js +44 -0
  139. package/lib/util/docker-client.js +2 -10
  140. package/lib/util/exec-async.js +0 -4
  141. package/lib/util/external-ip.js +8 -12
  142. package/lib/util/fs.js +1 -6
  143. package/lib/util/get-lan-ip.js +0 -5
  144. package/lib/util/has-update.js +2 -14
  145. package/lib/util/https.js +11 -55
  146. package/lib/util/navyrc.js +0 -5
  147. package/lib/util/service-host.js +0 -17
  148. package/lib/util/table.js +0 -6
  149. package/package.json +14 -13
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _chai = require("chai");
5
+ var _sinon = _interopRequireDefault(require("sinon"));
6
+ var _proxyquire = _interopRequireDefault(require("proxyquire"));
7
+ var _ociApiSpecification = require("../../../domain/oci-api-specification");
8
+ /* eslint-env mocha */
9
+
10
+ function fakeResponse({
11
+ digest,
12
+ body
13
+ }) {
14
+ return {
15
+ headers: {
16
+ get: name => name === 'docker-content-digest' ? digest : null
17
+ },
18
+ json: async () => body
19
+ };
20
+ }
21
+ function loadModule(getEndpointStub) {
22
+ return _proxyquire.default.noCallThru()('../get-fat-manifest', {
23
+ './get-endpoint': getEndpointStub
24
+ });
25
+ }
26
+ describe('get-fat-manifest', function () {
27
+ it('should call getEndpoint with the manifest path and the FAT_MANIFEST accept header', async function () {
28
+ const getEndpoint = _sinon.default.stub().resolves(fakeResponse({
29
+ digest: 'sha256:abc',
30
+ body: {
31
+ manifests: []
32
+ }
33
+ }));
34
+ const getFatManifest = loadModule(getEndpoint);
35
+ const result = await getFatManifest({
36
+ repository: 'library/node',
37
+ registry: 'registry-1.docker.io',
38
+ tag: 'lts'
39
+ });
40
+ (0, _chai.expect)(result).to.eql({
41
+ tag: 'sha256:abc',
42
+ data: {
43
+ manifests: []
44
+ }
45
+ });
46
+ (0, _chai.expect)(getEndpoint.calledOnce).to.equal(true);
47
+ const args = getEndpoint.firstCall.args[0];
48
+ (0, _chai.expect)(args.endpoint).to.equal('library/node/manifests/lts');
49
+ (0, _chai.expect)(args.options.headers.Accept).to.equal(_ociApiSpecification.MEDIA_TYPES.FAT_MANIFEST);
50
+ (0, _chai.expect)(args.allowUnauthorizedRequest).to.equal(false);
51
+ (0, _chai.expect)(args.registry).to.equal('registry-1.docker.io');
52
+ });
53
+ it('should propagate allowUnauthorizedRequest=true', async function () {
54
+ const getEndpoint = _sinon.default.stub().resolves(fakeResponse({
55
+ digest: 'd',
56
+ body: {}
57
+ }));
58
+ const getFatManifest = loadModule(getEndpoint);
59
+ await getFatManifest({
60
+ allowUnauthorizedRequest: true,
61
+ repository: 'org/img',
62
+ registry: 'r',
63
+ tag: 't'
64
+ });
65
+ (0, _chai.expect)(getEndpoint.firstCall.args[0].allowUnauthorizedRequest).to.equal(true);
66
+ });
67
+ });
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _chai = require("chai");
5
+ var _nock = _interopRequireDefault(require("nock"));
6
+ var _getToken = _interopRequireDefault(require("../get-token"));
7
+ /* eslint-env mocha */
8
+
9
+ describe('get-token', function () {
10
+ afterEach(function () {
11
+ _nock.default.cleanAll();
12
+ });
13
+ it('should call the realm with service+scope and return the token from the JSON body', async function () {
14
+ const scope = (0, _nock.default)('https://auth.docker.io').get('/token').query({
15
+ service: 'registry.docker.io',
16
+ scope: 'repository:library/node:pull'
17
+ }).matchHeader('authorization', 'Basic dXNlcjpwYXNz').reply(200, {
18
+ token: 'abc123'
19
+ });
20
+ const token = await (0, _getToken.default)({
21
+ realm: 'https://auth.docker.io/token',
22
+ service: 'registry.docker.io',
23
+ scope: 'repository:library/node:pull'
24
+ }, {
25
+ headers: {
26
+ Authorization: 'Basic dXNlcjpwYXNz'
27
+ }
28
+ });
29
+ (0, _chai.expect)(token).to.equal('abc123');
30
+ scope.done();
31
+ });
32
+ it('should throw "Invalid authentication" when the realm responds 401', async function () {
33
+ (0, _nock.default)('https://auth.docker.io').get('/token').query(true).reply(401, {});
34
+ let caught;
35
+ try {
36
+ await (0, _getToken.default)({
37
+ realm: 'https://auth.docker.io/token',
38
+ service: 'reg',
39
+ scope: 'sc'
40
+ }, {
41
+ headers: {}
42
+ });
43
+ } catch (err) {
44
+ caught = err;
45
+ }
46
+ (0, _chai.expect)(caught).to.be.an('error');
47
+ (0, _chai.expect)(caught.message).to.equal('Invalid authentication');
48
+ });
49
+ it('should pick only the Authorization header from the supplied headers (no other headers leak)', async function () {
50
+ (0, _nock.default)('https://auth.example.com').get('/token').query(true).matchHeader('authorization', 'Basic xyz').reply(200, {
51
+ token: 't'
52
+ });
53
+ const token = await (0, _getToken.default)({
54
+ realm: 'https://auth.example.com/token',
55
+ service: 'svc',
56
+ scope: 'sc'
57
+ }, {
58
+ headers: {
59
+ Authorization: 'Basic xyz',
60
+ Cookie: 'should-not-be-sent',
61
+ 'X-Custom': 'should-not-be-sent'
62
+ }
63
+ });
64
+ (0, _chai.expect)(token).to.equal('t');
65
+ });
66
+ });
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var _chai = require("chai");
4
+ var _helpers = require("../helpers");
5
+ /* eslint-env mocha */
6
+
7
+ describe('registry helpers', function () {
8
+ describe('basicAuthentication', function () {
9
+ it('should return null for empty credentials', function () {
10
+ (0, _chai.expect)((0, _helpers.basicAuthentication)({})).to.equal(null);
11
+ });
12
+ it('should base64-encode user:password into a Basic header', function () {
13
+ const result = (0, _helpers.basicAuthentication)({
14
+ username: 'alice',
15
+ password: 's3cret'
16
+ });
17
+ (0, _chai.expect)(result).to.equal('Basic ' + Buffer.from('alice:s3cret').toString('base64'));
18
+ });
19
+ it('should still return a Basic header for non-empty objects with empty values', function () {
20
+ (0, _chai.expect)((0, _helpers.basicAuthentication)({
21
+ username: '',
22
+ password: ''
23
+ })).to.equal('Basic ' + Buffer.from(':').toString('base64'));
24
+ });
25
+ });
26
+ });
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _ramda = require("ramda");
9
-
10
8
  var _execAsync = require("../../util/exec-async");
11
-
12
9
  var _containerImage = require("../../domain/container-image");
13
-
14
10
  const getAuthenticationForRegistry = async registry => {
15
11
  try {
16
12
  const credentialStore = registry === _containerImage.DEFAULT_REGISTRY ? _containerImage.DEFAULT_REGISTRY_AUTH : registry;
@@ -20,8 +16,8 @@ const getAuthenticationForRegistry = async registry => {
20
16
  });
21
17
  const credentials = JSON.parse(stdout);
22
18
  return {
23
- username: credentials['Username'],
24
- password: credentials['Secret']
19
+ username: credentials.Username,
20
+ password: credentials.Secret
25
21
  };
26
22
  } catch (exception) {
27
23
  return {
@@ -30,7 +26,5 @@ const getAuthenticationForRegistry = async registry => {
30
26
  };
31
27
  }
32
28
  };
33
-
34
- var _default = getAuthenticationForRegistry;
35
- exports.default = _default;
29
+ var _default = exports.default = getAuthenticationForRegistry;
36
30
  module.exports = exports.default;
@@ -1,70 +1,47 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var R = _interopRequireWildcard(require("ramda"));
11
-
12
9
  var _https = _interopRequireDefault(require("https"));
13
-
14
10
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
15
-
16
11
  var _getToken = _interopRequireDefault(require("./get-token"));
17
-
18
12
  var _ociApiSpecification = require("../../domain/oci-api-specification");
19
-
20
13
  var _getCredentials = _interopRequireDefault(require("./get-credentials"));
21
-
22
14
  var _helpers = require("./helpers");
23
-
24
15
  var _parsers = _interopRequireDefault(require("www-authenticate/lib/parsers"));
25
-
26
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
16
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
30
17
  const handleUnauthorizedResponse = async ({
31
- response,
18
+ response: initialResponse,
32
19
  context,
33
20
  url
34
21
  }) => {
35
- const challenges = response.headers.get('WWW-Authenticate');
22
+ const challenges = initialResponse.headers.get('WWW-Authenticate');
36
23
  const {
37
24
  scheme,
38
25
  parms
39
26
  } = new _parsers.default.WWW_Authenticate(challenges);
40
-
41
27
  if (scheme === 'Basic') {
42
28
  throw new Error('Invalid authentication');
43
29
  }
44
-
45
30
  if (scheme !== 'Bearer') {
46
31
  throw new Error('Invalid authentication');
47
32
  }
48
-
49
- try {
50
- const token = await (0, _getToken.default)(parms, context);
51
- const options = R.mergeDeepRight(context, {
52
- headers: {
53
- 'Authorization': `Bearer ${token}`
54
- }
55
- });
56
- const response = await (0, _nodeFetch.default)(url, options);
57
-
58
- if (response.status === 401) {
59
- throw new Error('Access denied');
33
+ const token = await (0, _getToken.default)(parms, context);
34
+ const options = R.mergeDeepRight(context, {
35
+ headers: {
36
+ Authorization: `Bearer ${token}`
60
37
  }
61
-
62
- return response;
63
- } catch (exception) {
64
- throw exception;
38
+ });
39
+ const response = await (0, _nodeFetch.default)(url, options);
40
+ if (response.status === 401) {
41
+ throw new Error('Access denied');
65
42
  }
43
+ return response;
66
44
  };
67
-
68
45
  const get = async ({
69
46
  allowUnauthorizedRequest = false,
70
47
  endpoint,
@@ -72,42 +49,31 @@ const get = async ({
72
49
  options = {}
73
50
  }) => {
74
51
  const url = _ociApiSpecification.restSpecification.operation(registry, endpoint);
75
-
76
52
  const credentials = await (0, _getCredentials.default)(registry);
77
53
  const context = R.mergeDeepLeft(options, {
78
54
  headers: R.reject(R.isNil, {
79
- 'Authorization': (0, _helpers.basicAuthentication)(credentials)
55
+ Authorization: (0, _helpers.basicAuthentication)(credentials)
80
56
  }),
81
57
  agent: new _https.default.Agent({
82
58
  rejectUnauthorized: !allowUnauthorizedRequest
83
59
  })
84
60
  });
85
-
86
- try {
87
- const response = await (0, _nodeFetch.default)(url, context);
88
-
89
- switch (response.status) {
90
- case 401:
91
- return handleUnauthorizedResponse({
92
- response,
93
- context,
94
- url
95
- });
96
-
97
- case 404:
98
- throw new Error('Operation not found', {
99
- status: 404,
100
- body: await response.json()
101
- });
102
-
103
- default:
104
- return response;
105
- }
106
- } catch (exception) {
107
- throw exception;
61
+ const response = await (0, _nodeFetch.default)(url, context);
62
+ switch (response.status) {
63
+ case 401:
64
+ return handleUnauthorizedResponse({
65
+ response,
66
+ context,
67
+ url
68
+ });
69
+ case 404:
70
+ throw new Error('Operation not found', {
71
+ status: 404,
72
+ body: await response.json()
73
+ });
74
+ default:
75
+ return response;
108
76
  }
109
77
  };
110
-
111
- var _default = get;
112
- exports.default = _default;
78
+ var _default = exports.default = get;
113
79
  module.exports = exports.default;
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _getEndpoint = _interopRequireDefault(require("./get-endpoint"));
11
-
12
9
  var _ociApiSpecification = require("../../domain/oci-api-specification");
13
-
14
10
  const getFatManifest = async ({
15
11
  allowUnauthorizedRequest = false,
16
12
  repository,
@@ -18,10 +14,9 @@ const getFatManifest = async ({
18
14
  tag
19
15
  }) => {
20
16
  const endpoint = _ociApiSpecification.restSpecification.getManifest(repository, tag);
21
-
22
17
  const options = {
23
18
  headers: {
24
- 'Accept': _ociApiSpecification.MEDIA_TYPES.FAT_MANIFEST
19
+ Accept: _ociApiSpecification.MEDIA_TYPES.FAT_MANIFEST
25
20
  }
26
21
  };
27
22
  const response = await (0, _getEndpoint.default)({
@@ -35,7 +30,5 @@ const getFatManifest = async ({
35
30
  data: await response.json()
36
31
  };
37
32
  };
38
-
39
- var _default = getFatManifest;
40
- exports.default = _default;
33
+ var _default = exports.default = getFatManifest;
41
34
  module.exports = exports.default;
@@ -1,20 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _nodeFetch = _interopRequireDefault(require("node-fetch"));
11
-
12
9
  var R = _interopRequireWildcard(require("ramda"));
13
-
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
18
11
  const getToken = async ({
19
12
  realm,
20
13
  service,
@@ -29,17 +22,13 @@ const getToken = async ({
29
22
  agent
30
23
  };
31
24
  const response = await (0, _nodeFetch.default)(url, options);
32
-
33
25
  if (response.status === 401) {
34
26
  throw new Error('Invalid authentication');
35
27
  }
36
-
37
28
  const {
38
29
  token
39
30
  } = await response.json();
40
31
  return token;
41
32
  };
42
-
43
- var _default = getToken;
44
- exports.default = _default;
33
+ var _default = exports.default = getToken;
45
34
  module.exports = exports.default;
@@ -4,16 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.basicAuthentication = void 0;
7
-
8
7
  var _ramda = require("ramda");
9
-
10
8
  const basicAuthentication = credentials => {
11
9
  if ((0, _ramda.isEmpty)(credentials)) {
12
10
  return null;
13
11
  }
14
-
15
12
  const parameters = Buffer.from(`${credentials.username}:${credentials.password}`).toString('base64');
16
13
  return `Basic ${parameters}`;
17
14
  };
18
-
19
15
  exports.basicAuthentication = basicAuthentication;
@@ -1,46 +1,34 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.getImportCommandLineOptions = getImportCommandLineOptions;
9
8
  exports.getImportOptionsForCLI = getImportOptionsForCLI;
10
9
  exports.resolveConfigProviderFromName = resolveConfigProviderFromName;
11
-
12
10
  var _invariant = _interopRequireDefault(require("invariant"));
13
-
14
11
  var _filesystem = _interopRequireDefault(require("./config-providers/filesystem"));
15
-
16
12
  var _npm = _interopRequireDefault(require("./config-providers/npm"));
17
-
18
13
  const PROVIDERS = [_npm.default, _filesystem.default];
19
-
20
14
  function resolveConfigProviderFromName(providerName) {
21
15
  switch (providerName) {
22
16
  case 'filesystem':
23
17
  return _filesystem.default;
24
-
25
18
  case 'npm':
26
19
  return _npm.default;
27
20
  }
28
-
29
21
  return null;
30
22
  }
31
-
32
23
  function getImportCommandLineOptions() {
33
24
  return PROVIDERS.reduce((arr, provider) => [...arr, ...provider.importCliOptions], []);
34
25
  }
35
-
36
26
  async function getImportOptionsForCLI(opts) {
37
27
  for (const provider of PROVIDERS) {
38
28
  const optionsFromProvider = await provider.getImportOptionsForCLI(opts);
39
-
40
29
  if (optionsFromProvider) {
41
30
  return optionsFromProvider;
42
31
  }
43
32
  }
44
-
45
33
  (0, _invariant.default)(false, "CLI_IMPORT_RESOLVE_OPTIONS_ERR: Could not resolve import options from CLI arguments");
46
34
  }
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _chai = require("chai");
5
+ var _sinon = _interopRequireDefault(require("sinon"));
6
+ var _path = _interopRequireDefault(require("path"));
7
+ var _fs = _interopRequireDefault(require("../../../util/fs"));
8
+ var execAsyncModule = _interopRequireWildcard(require("../../../util/exec-async"));
9
+ var _index = _interopRequireDefault(require("../index"));
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
+ /* eslint-env mocha */
12
+
13
+ function makeNavy({
14
+ name = 'env',
15
+ state = null
16
+ } = {}) {
17
+ return {
18
+ name,
19
+ getState: _sinon.default.stub().resolves(state)
20
+ };
21
+ }
22
+ describe('filesystem config provider', function () {
23
+ let sandbox;
24
+ beforeEach(function () {
25
+ sandbox = _sinon.default.createSandbox();
26
+ sandbox.stub(process, 'cwd').returns('/work/dir');
27
+ });
28
+ afterEach(function () {
29
+ sandbox.restore();
30
+ });
31
+ describe('getNavyPath', function () {
32
+ it('should return the path from state when the path exists on disk', async function () {
33
+ const provider = (0, _index.default)(makeNavy({
34
+ state: {
35
+ path: '/some/path'
36
+ }
37
+ }));
38
+ sandbox.stub(_fs.default, 'statAsync').resolves({});
39
+ (0, _chai.expect)(await provider.getNavyPath()).to.equal('/some/path');
40
+ });
41
+ it('should throw STATE_NONEXISTANT when state is missing', async function () {
42
+ const provider = (0, _index.default)(makeNavy({
43
+ state: null
44
+ }));
45
+ let caught;
46
+ try {
47
+ await provider.getNavyPath();
48
+ } catch (e) {
49
+ caught = e;
50
+ }
51
+ (0, _chai.expect)(caught.message).to.match(/STATE_NONEXISTANT/);
52
+ });
53
+ it('should throw FILESYSTEM_PROVIDER_REQUIRES_PATH when state has no path', async function () {
54
+ const provider = (0, _index.default)(makeNavy({
55
+ state: {}
56
+ }));
57
+ let caught;
58
+ try {
59
+ await provider.getNavyPath();
60
+ } catch (e) {
61
+ caught = e;
62
+ }
63
+ (0, _chai.expect)(caught.message).to.match(/FILESYSTEM_PROVIDER_REQUIRES_PATH/);
64
+ });
65
+ it('should throw FILESYSTEM_PROVIDER_INVALID_PATH when stat of the path fails', async function () {
66
+ const provider = (0, _index.default)(makeNavy({
67
+ state: {
68
+ path: '/missing'
69
+ }
70
+ }));
71
+ sandbox.stub(_fs.default, 'statAsync').rejects(new Error('ENOENT'));
72
+ let caught;
73
+ try {
74
+ await provider.getNavyPath();
75
+ } catch (e) {
76
+ caught = e;
77
+ }
78
+ (0, _chai.expect)(caught.message).to.match(/FILESYSTEM_PROVIDER_INVALID_PATH/);
79
+ });
80
+ });
81
+ describe('getNavyFilePath', function () {
82
+ it('should return <navyPath>/Navyfile.js', async function () {
83
+ const provider = (0, _index.default)(makeNavy({
84
+ state: {
85
+ path: '/some/path'
86
+ }
87
+ }));
88
+ sandbox.stub(_fs.default, 'statAsync').resolves({});
89
+ (0, _chai.expect)(await provider.getNavyFilePath()).to.equal(_path.default.join('/some/path', 'Navyfile.js'));
90
+ });
91
+ });
92
+ describe('refreshConfig', function () {
93
+ it('should be a no-op that returns false', async function () {
94
+ const provider = (0, _index.default)(makeNavy());
95
+ (0, _chai.expect)(await provider.refreshConfig()).to.equal(false);
96
+ });
97
+ });
98
+ describe('getLocationDisplayName', function () {
99
+ it('should return the path from state', async function () {
100
+ const provider = (0, _index.default)(makeNavy({
101
+ state: {
102
+ path: '/x'
103
+ }
104
+ }));
105
+ (0, _chai.expect)(await provider.getLocationDisplayName()).to.equal('/x');
106
+ });
107
+ it('should throw STATE_NONEXISTANT when state is missing', async function () {
108
+ const provider = (0, _index.default)(makeNavy({
109
+ state: null
110
+ }));
111
+ let caught;
112
+ try {
113
+ await provider.getLocationDisplayName();
114
+ } catch (e) {
115
+ caught = e;
116
+ }
117
+ (0, _chai.expect)(caught.message).to.match(/STATE_NONEXISTANT/);
118
+ });
119
+ });
120
+ describe('isDangling', function () {
121
+ it('should return true when state is null', async function () {
122
+ const provider = (0, _index.default)(makeNavy({
123
+ state: null
124
+ }));
125
+ (0, _chai.expect)(await provider.isDangling()).to.equal(true);
126
+ });
127
+ it('should return true when state has no path', async function () {
128
+ const provider = (0, _index.default)(makeNavy({
129
+ state: {}
130
+ }));
131
+ (0, _chai.expect)(await provider.isDangling()).to.equal(true);
132
+ });
133
+ it('should return true when stat of the path fails', async function () {
134
+ const provider = (0, _index.default)(makeNavy({
135
+ state: {
136
+ path: '/x'
137
+ }
138
+ }));
139
+ sandbox.stub(_fs.default, 'statAsync').rejects(new Error('ENOENT'));
140
+ (0, _chai.expect)(await provider.isDangling()).to.equal(true);
141
+ });
142
+ it('should return false when state has a valid path', async function () {
143
+ const provider = (0, _index.default)(makeNavy({
144
+ state: {
145
+ path: '/x'
146
+ }
147
+ }));
148
+ sandbox.stub(_fs.default, 'statAsync').resolves({});
149
+ (0, _chai.expect)(await provider.isDangling()).to.equal(false);
150
+ });
151
+ });
152
+ describe('importCliOptions', function () {
153
+ it('should expose an empty CLI options array', function () {
154
+ (0, _chai.expect)(_index.default.importCliOptions).to.eql([]);
155
+ });
156
+ });
157
+ describe('getImportOptionsForCLI', function () {
158
+ it('should return { configProvider: "filesystem", path: cwd } when docker-compose config is valid', async function () {
159
+ sandbox.stub(execAsyncModule, 'execAsync').resolves('');
160
+ (0, _chai.expect)(await _index.default.getImportOptionsForCLI({})).to.eql({
161
+ configProvider: 'filesystem',
162
+ path: '/work/dir'
163
+ });
164
+ });
165
+ it('should throw NO_DOCKER_COMPOSE_FILE when docker-compose config fails', async function () {
166
+ sandbox.stub(execAsyncModule, 'execAsync').rejects(new Error('boom'));
167
+ let caught;
168
+ try {
169
+ await _index.default.getImportOptionsForCLI({});
170
+ } catch (e) {
171
+ caught = e;
172
+ }
173
+ (0, _chai.expect)(caught.message).to.match(/NO_DOCKER_COMPOSE_FILE/);
174
+ });
175
+ });
176
+ });