├── .eslintrc ├── .github ├── FUNDING.yml └── workflows │ └── main.yml ├── .gitignore ├── .travis.yml ├── .vscode └── launch.json ├── LICENSE ├── README.md ├── lib ├── http.js ├── http_duplex.js ├── modem.js ├── ssh.js └── utils.js ├── package-lock.json ├── package.json └── test └── modem_test.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "mocha": true, 4 | "node": true 5 | }, 6 | "rules": { 7 | /* Possible Errors */ 8 | "no-extra-parens": 2, 9 | "valid-jsdoc": 2, 10 | /* Best Practices */ 11 | "block-scoped-var": 2, 12 | "complexity": [1, 3], 13 | "default-case": 2, 14 | "dot-notation": [2], 15 | "guard-for-in": 2, 16 | "no-div-regex": 2, 17 | "no-else-return": 2, 18 | "no-eq-null": 2, 19 | "no-floating-decimal": 2, 20 | "no-process-env": 2, 21 | "no-self-compare": 2, 22 | "no-void": 2, 23 | "no-warning-comments": 2, 24 | "radix": 2, 25 | "vars-on-top": 2, 26 | "wrap-iife": 2, 27 | /* Variables */ 28 | "no-catch-shadow": 2, 29 | /* Node.JS */ 30 | "no-sync": 2, 31 | /* Stylistic Issues */ 32 | "no-mixed-spaces-and-tabs": 2, 33 | "no-underscore-dangle": 2, 34 | "quotes": [1, "single", "avoid-escape"] 35 | }} 36 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: apocas 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | 8 | jobs: 9 | build_nodejs: 10 | runs-on: ubuntu-latest 11 | 12 | strategy: 13 | matrix: 14 | node-version: [14.x, 16.x, 18.x, 20.x, 22.x] 15 | 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - name: Use Node.js ${{ matrix.node-version }} 20 | uses: actions/setup-node@v3 21 | with: 22 | node-version: ${{ matrix.node-version }} 23 | 24 | - name: Provisioning 25 | run: | 26 | docker --version 27 | node -v 28 | docker pull ubuntu 29 | pwd 30 | cd ../ 31 | git clone --depth=50 --branch=master https://github.com/apocas/dockerode.git 32 | cd dockerode 33 | npm install 34 | cd ../docker-modem 35 | 36 | - name: NPM install 37 | run: npm install 38 | 39 | - name: NPM test 40 | run: npm test 41 | 42 | - name: Dockerode test suite 43 | run: | 44 | cd ../dockerode 45 | rm -rf ./node_modules/docker-modem 46 | pwd 47 | ls ../ 48 | cp -R ../docker-modem ./node_modules/docker-modem 49 | npm test 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | 3 | git: 4 | quiet: true 5 | 6 | language: node_js 7 | 8 | node_js: 9 | - "8" 10 | 11 | before_script: 12 | - docker pull ubuntu 13 | 14 | services: 15 | - docker 16 | 17 | before_install: 18 | - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 19 | - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" 20 | - sudo apt-get update 21 | - sudo apt-get -y install docker-ce 22 | - cd .. 23 | - git clone --depth=50 --branch=master https://github.com/apocas/dockerode.git 24 | - cd dockerode 25 | - npm install 26 | - cd ../docker-modem 27 | 28 | install: 29 | - npm install 30 | 31 | script: 32 | - npm test 33 | - cd ../dockerode 34 | - rm -rf ./node_modules/docker-modem 35 | - npm install git://github.com/apocas/docker-modem 36 | - npm test 37 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "args": [ 6 | "--colors", 7 | "${workspaceFolder}/test", 8 | "-R", 9 | "spec", 10 | "--exit" 11 | ], 12 | "internalConsoleOptions": "openOnSessionStart", 13 | "name": "Mocha Tests", 14 | "program": "./node_modules/mocha/bin/mocha.js", 15 | "request": "launch", 16 | "skipFiles": [ 17 | "/**" 18 | ], 19 | "type": "node" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-modem 2 | 3 | [Docker](https://www.docker.com/)'s Remote API network layer module. 4 | 5 | `docker-modem` will help you interacting with `Docker`, since it already implements all the network strategies needed to support all `Docker`'s Remote API endpoints. 6 | 7 | It is the module powering (network wise) [dockerode](https://github.com/apocas/dockerode) and other modules. 8 | 9 | ## Usage 10 | 11 | ### Getting started 12 | 13 | ``` js 14 | var Modem = require('docker-modem'); 15 | var modem1 = new Modem({socketPath: '/var/run/docker.sock'}); 16 | var modem2 = new Modem(); //defaults to above if env variables are not used 17 | var modem3 = new Modem({host: 'http://192.168.1.10', port: 3000}); 18 | var modem4 = new Modem({protocol:'http', host: '127.0.0.1', port: 3000}); 19 | var modem5 = new Modem({host: '127.0.0.1', port: 3000}); //defaults to http 20 | ``` 21 | 22 | ### SSH 23 | 24 | You can connect to the Docker daemon via SSH in two ways: 25 | 26 | * Using the built-in SSH agent. 27 | * Implement your own custom agent. 28 | 29 | ``` js 30 | //built-in SSH agent 31 | var modem1 = new Modem({ 32 | protocol: 'ssh', 33 | host: 'ssh://127.0.0.1', 34 | port: 22 35 | }); 36 | 37 | //custom agent 38 | var customAgent = myOwnSSHAgent({host: 'ssh://127.0.0.1', port: 22}); 39 | var modem2 = new Modem({ 40 | agent: customAgent, 41 | }); 42 | ``` 43 | 44 | ## Tests 45 | 46 | * Tests are implemented using `mocha` and `chai`. Run them with `npm test`. 47 | * Check [dockerode](https://github.com/apocas/dockerode) tests, which is indirectly co-testing `docker-modem`. 48 | 49 | ## Sponsors 50 | 51 | Amazing entities that [sponsor](https://github.com/sponsors/apocas) my open-source work. Check them out! 52 | 53 | [![HTTP Toolkit](https://avatars.githubusercontent.com/u/39777515?s=100)](https://github.com/httptoolkit) 54 | 55 | ## License 56 | 57 | Pedro Dias - [@pedromdias](https://twitter.com/pedromdias) 58 | 59 | Licensed under the Apache license, version 2.0 (the "license"); You may not use this file except in compliance with the license. You may obtain a copy of the license at: 60 | 61 | http://www.apache.org/licenses/LICENSE-2.0.html 62 | 63 | Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "as is" basis, without warranties or conditions of any kind, either express or implied. See the license for the specific language governing permissions and limitations under the license. 64 | -------------------------------------------------------------------------------- /lib/http.js: -------------------------------------------------------------------------------- 1 | //Based on follow-redirects v0.0.x 2 | 3 | var nativeHttps = require('https'), 4 | nativeHttp = require('http'), 5 | url = require('url'), 6 | utils = require('./utils'); 7 | 8 | var maxRedirects = module.exports.maxRedirects = 5; 9 | 10 | var protocols = { 11 | https: nativeHttps, 12 | http: nativeHttp 13 | }; 14 | 15 | for (var protocol in protocols) { 16 | var h = function() {}; 17 | h.prototype = protocols[protocol]; 18 | h = new h(); 19 | 20 | h.request = function(h) { 21 | return function(options, callback, redirectOptions) { 22 | 23 | redirectOptions = redirectOptions || {}; 24 | 25 | var max = (typeof options === 'object' && 'maxRedirects' in options) ? options.maxRedirects : exports.maxRedirects; 26 | 27 | var redirect = utils.extend({ 28 | count: 0, 29 | max: max, 30 | clientRequest: null, 31 | userCallback: callback 32 | }, redirectOptions); 33 | 34 | if (redirect.count > redirect.max) { 35 | var err = new Error('Max redirects exceeded. To allow more redirects, pass options.maxRedirects property.'); 36 | redirect.clientRequest.emit('error', err); 37 | return redirect.clientRequest; 38 | } 39 | 40 | redirect.count++; 41 | 42 | var reqUrl; 43 | if (typeof options === 'string') { 44 | reqUrl = options; 45 | } else { 46 | reqUrl = url.format(utils.extend({ 47 | protocol: protocol 48 | }, options)); 49 | } 50 | 51 | var clientRequest = Object.getPrototypeOf(h).request(options, redirectCallback(reqUrl, redirect)); 52 | 53 | if (!redirect.clientRequest) redirect.clientRequest = clientRequest; 54 | 55 | function redirectCallback(reqUrl, redirect) { 56 | return function(res) { 57 | if (res.statusCode < 300 || res.statusCode > 399) { 58 | return redirect.userCallback(res); 59 | } 60 | 61 | if (!('location' in res.headers)) { 62 | return redirect.userCallback(res); 63 | } 64 | 65 | var redirectUrl = url.resolve(reqUrl, res.headers.location); 66 | 67 | var proto = url.parse(redirectUrl).protocol; 68 | proto = proto.substr(0, proto.length - 1); 69 | return module.exports[proto].get(redirectUrl, redirectCallback(reqUrl, redirect), redirect); 70 | }; 71 | } 72 | 73 | return clientRequest; 74 | }; 75 | }(h); 76 | 77 | // see https://github.com/joyent/node/blob/master/lib/http.js#L1623 78 | h.get = function(h) { 79 | return function(options, cb, redirectOptions) { 80 | var req = h.request(options, cb, redirectOptions); 81 | req.end(); 82 | return req; 83 | }; 84 | }(h); 85 | 86 | module.exports[protocol] = h; 87 | } 88 | -------------------------------------------------------------------------------- /lib/http_duplex.js: -------------------------------------------------------------------------------- 1 | module.exports = HttpDuplex; 2 | 3 | var util = require('util'), 4 | stream = require('readable-stream'); 5 | 6 | util.inherits(HttpDuplex, stream.Duplex); 7 | 8 | function HttpDuplex(req, res, options) { 9 | var self = this; 10 | 11 | if (!(self instanceof HttpDuplex)) return new HttpDuplex(req, res, options); 12 | 13 | stream.Duplex.call(self, options); 14 | self._output = null; 15 | 16 | self.connect(req, res); 17 | } 18 | 19 | HttpDuplex.prototype.connect = function(req, res) { 20 | var self = this; 21 | self.req = req; 22 | self._output = res; 23 | self.emit('response', res); 24 | 25 | res.on('data', function(c) { 26 | if (!self.push(c)) self._output.pause(); 27 | }); 28 | res.on('end', function() { 29 | self.push(null); 30 | }); 31 | }; 32 | 33 | HttpDuplex.prototype._read = function(n) { 34 | if (this._output) this._output.resume(); 35 | }; 36 | 37 | HttpDuplex.prototype._write = function(chunk, encoding, cb) { 38 | this.req.write(chunk, encoding); 39 | cb(); 40 | }; 41 | 42 | HttpDuplex.prototype.end = function(chunk, encoding, cb) { 43 | this._output.socket.destroySoon(); 44 | return this.req.end(chunk, encoding, cb); 45 | }; 46 | 47 | HttpDuplex.prototype.destroy = function() { 48 | this.req.destroy(); 49 | this._output.socket.destroy(); 50 | }; 51 | 52 | HttpDuplex.prototype.destroySoon = function() { 53 | this.req.destroy(); 54 | this._output.socket.destroy(); 55 | }; 56 | -------------------------------------------------------------------------------- /lib/modem.js: -------------------------------------------------------------------------------- 1 | var querystring = require('querystring'), 2 | http = require('./http'), 3 | fs = require('fs'), 4 | path = require('path'), 5 | url = require('url'), 6 | ssh = require('./ssh'), 7 | HttpDuplex = require('./http_duplex'), 8 | debug = require('debug')('modem'), 9 | utils = require('./utils'), 10 | util = require('util'), 11 | splitca = require('split-ca'), 12 | os = require('os'), 13 | isWin = os.type() === 'Windows_NT', 14 | stream = require('stream'); 15 | 16 | var defaultOpts = function () { 17 | var host; 18 | var opts = {}; 19 | 20 | if (!process.env.DOCKER_HOST) { 21 | // Windows socket path: //./pipe/docker_engine ( Windows 10 ) 22 | // Linux & Darwin socket path is /var/run/docker.sock when running system-wide, 23 | // or $HOME/.docker/run/docker.sock in new Docker Desktop installs. 24 | opts.socketPath = isWin ? '//./pipe/docker_engine' : findDefaultUnixSocket; 25 | } else if (process.env.DOCKER_HOST.indexOf('unix://') === 0) { 26 | // Strip off unix://, fall back to default if unix:// was passed without a path 27 | opts.socketPath = process.env.DOCKER_HOST.substring(7) || findDefaultUnixSocket; 28 | } else if (process.env.DOCKER_HOST.indexOf('npipe://') === 0) { 29 | // Strip off npipe://, fall back to default of //./pipe/docker_engine if 30 | // npipe:// was passed without a path 31 | opts.socketPath = process.env.DOCKER_HOST.substring(8) || '//./pipe/docker_engine'; 32 | } else { 33 | var hostStr = process.env.DOCKER_HOST; 34 | if (hostStr.indexOf('\/\/') < 0) { 35 | hostStr = 'tcp://' + hostStr; 36 | } 37 | try { 38 | host = new url.URL(hostStr); 39 | } catch (err) { 40 | throw new Error('DOCKER_HOST env variable should be something like tcp://localhost:1234'); 41 | } 42 | 43 | opts.port = host.port; 44 | 45 | if (process.env.DOCKER_TLS_VERIFY === '1' || opts.port === '2376') { 46 | opts.protocol = 'https'; 47 | } else if (host.protocol === 'ssh:') { 48 | opts.protocol = 'ssh'; 49 | opts.username = host.username; 50 | opts.sshOptions = { 51 | agent: process.env.SSH_AUTH_SOCK, 52 | } 53 | } else { 54 | opts.protocol = 'http'; 55 | } 56 | 57 | if (process.env.DOCKER_PATH_PREFIX) { 58 | opts.pathPrefix = process.env.DOCKER_PATH_PREFIX; 59 | } 60 | else { 61 | opts.pathPrefix = '/'; 62 | } 63 | 64 | opts.host = host.hostname; 65 | 66 | if (process.env.DOCKER_CERT_PATH) { 67 | opts.ca = splitca(path.join(process.env.DOCKER_CERT_PATH, 'ca.pem')); 68 | opts.cert = fs.readFileSync(path.join(process.env.DOCKER_CERT_PATH, 'cert.pem')); 69 | opts.key = fs.readFileSync(path.join(process.env.DOCKER_CERT_PATH, 'key.pem')); 70 | } 71 | 72 | if (process.env.DOCKER_CLIENT_TIMEOUT) { 73 | opts.timeout = parseInt(process.env.DOCKER_CLIENT_TIMEOUT, 10); 74 | } 75 | } 76 | 77 | return opts; 78 | }; 79 | 80 | var findDefaultUnixSocket = function () { 81 | return new Promise(function (resolve) { 82 | var userDockerSocket = path.join(os.homedir(), '.docker', 'run', 'docker.sock'); 83 | fs.access(userDockerSocket, function (err) { 84 | if (err) resolve('/var/run/docker.sock'); 85 | else resolve(userDockerSocket); 86 | }) 87 | }); 88 | } 89 | 90 | 91 | var Modem = function (options) { 92 | var optDefaults = defaultOpts(); 93 | var opts = Object.assign({}, optDefaults, options); 94 | 95 | this.host = opts.host; 96 | 97 | if (!this.host) { 98 | this.socketPath = opts.socketPath; 99 | } 100 | 101 | this.port = opts.port; 102 | this.pathPrefix = opts.pathPrefix; 103 | this.username = opts.username; 104 | this.password = opts.password; 105 | this.version = opts.version; 106 | this.key = opts.key; 107 | this.cert = opts.cert; 108 | this.ca = opts.ca; 109 | this.timeout = opts.timeout; 110 | this.connectionTimeout = opts.connectionTimeout; 111 | this.checkServerIdentity = opts.checkServerIdentity; 112 | this.agent = opts.agent; 113 | this.headers = opts.headers || {}; 114 | this.sshOptions = Object.assign({}, options ? options.sshOptions : {}, optDefaults.sshOptions); 115 | //retrocompabitlity 116 | if (this.sshOptions.agentForward === undefined) { 117 | this.sshOptions.agentForward = opts.agentForward; 118 | } 119 | 120 | if (this.key && this.cert && this.ca) { 121 | this.protocol = 'https'; 122 | } 123 | this.protocol = opts.protocol || this.protocol || 'http'; 124 | }; 125 | 126 | Modem.prototype.dial = function (options, callback) { 127 | var opts, address, data; 128 | 129 | if (options.options) { 130 | opts = options.options; 131 | } 132 | 133 | // Prevent credentials from showing up in URL 134 | if (opts && opts.authconfig) { 135 | delete opts.authconfig; 136 | } 137 | 138 | // Prevent abortsignal from showing up in the URL 139 | if (opts && opts.abortSignal) { 140 | delete opts.abortSignal; 141 | } 142 | 143 | if (this.version) { 144 | options.path = '/' + this.version + options.path; 145 | } 146 | 147 | if (this.host) { 148 | var parsed = url.parse(this.host); 149 | address = url.format({ 150 | protocol: parsed.protocol || this.protocol, 151 | hostname: parsed.hostname || this.host, 152 | port: this.port, 153 | pathname: parsed.pathname || this.pathPrefix, 154 | }); 155 | address = url.resolve(address, options.path); 156 | } else { 157 | address = options.path; 158 | } 159 | 160 | if (options.path.indexOf('?') !== -1) { 161 | if (opts && Object.keys(opts).length > 0) { 162 | address += this.buildQuerystring(opts._query || opts); 163 | } else { 164 | address = address.substring(0, address.length - 1); 165 | } 166 | } 167 | 168 | var optionsf = { 169 | path: address, 170 | method: options.method, 171 | headers: options.headers || Object.assign({}, this.headers), 172 | key: this.key, 173 | cert: this.cert, 174 | ca: this.ca 175 | }; 176 | 177 | 178 | if (this.checkServerIdentity) { 179 | optionsf.checkServerIdentity = this.checkServerIdentity; 180 | } 181 | 182 | if (this.agent) { 183 | optionsf.agent = this.agent; 184 | } 185 | 186 | if (options.authconfig) { 187 | optionsf.headers['X-Registry-Auth'] = options.authconfig.key || options.authconfig.base64 || 188 | Buffer.from(JSON.stringify(options.authconfig)).toString('base64').replace(/\+/g, "-").replace(/\//g, "_"); 189 | } 190 | 191 | if (options.registryconfig) { 192 | optionsf.headers['X-Registry-Config'] = options.registryconfig.base64 || 193 | Buffer.from(JSON.stringify(options.registryconfig)).toString('base64'); 194 | } 195 | 196 | if (options.abortSignal) { 197 | optionsf.signal = options.abortSignal; 198 | } 199 | 200 | if (options.file) { 201 | if (typeof options.file === 'string') { 202 | data = fs.createReadStream(path.resolve(options.file)); 203 | } else { 204 | data = options.file; 205 | } 206 | optionsf.headers['Content-Type'] = 'application/tar'; 207 | } else if (opts && options.method === 'POST') { 208 | data = JSON.stringify(opts._body || opts); 209 | if (options.allowEmpty) { 210 | optionsf.headers['Content-Type'] = 'application/json'; 211 | } else { 212 | if (data !== '{}' && data !== '""') { 213 | optionsf.headers['Content-Type'] = 'application/json'; 214 | } else { 215 | data = undefined; 216 | } 217 | } 218 | } 219 | 220 | if (typeof data === 'string') { 221 | optionsf.headers['Content-Length'] = Buffer.byteLength(data); 222 | } else if (Buffer.isBuffer(data) === true) { 223 | optionsf.headers['Content-Length'] = data.length; 224 | } else if (optionsf.method === 'PUT' || options.hijack || options.openStdin) { 225 | optionsf.headers['Transfer-Encoding'] = 'chunked'; 226 | } 227 | 228 | if (options.hijack) { 229 | optionsf.headers.Connection = 'Upgrade'; 230 | optionsf.headers.Upgrade = optionsf.headers.Upgrade ?? 'tcp'; 231 | } 232 | 233 | if (this.socketPath) { 234 | // SocketPath may be a function that can return a promise: 235 | this.getSocketPath().then((socketPath) => { 236 | optionsf.socketPath = socketPath; 237 | this.buildRequest(optionsf, options, data, callback); 238 | }); 239 | } else { 240 | var urlp = url.parse(address); 241 | optionsf.hostname = urlp.hostname; 242 | optionsf.port = urlp.port; 243 | optionsf.path = urlp.path; 244 | 245 | this.buildRequest(optionsf, options, data, callback); 246 | } 247 | }; 248 | 249 | Modem.prototype.getSocketPath = function () { 250 | if (!this.socketPath) return; 251 | if (this.socketPathCache) return Promise.resolve(this.socketPathCache); 252 | 253 | var socketPathValue = typeof this.socketPath === 'function' 254 | ? this.socketPath() : this.socketPath; 255 | 256 | this.socketPathCache = socketPathValue; 257 | 258 | return Promise.resolve(socketPathValue); 259 | } 260 | 261 | Modem.prototype.buildRequest = function (options, context, data, callback) { 262 | var self = this; 263 | var connectionTimeoutTimer; 264 | var finished = false; 265 | 266 | var opts = self.protocol === 'ssh' ? Object.assign(options, { 267 | agent: ssh(Object.assign({}, self.sshOptions, { 268 | 'host': self.host, 269 | 'port': self.port, 270 | 'username': self.username, 271 | 'password': self.password, 272 | })), 273 | protocol: 'http:', 274 | }) : options; 275 | 276 | var req = http[self.protocol === 'ssh' ? 'http' : self.protocol].request(opts, function () { }); 277 | 278 | debug('Sending: %s', util.inspect(options, { 279 | showHidden: true, 280 | depth: null 281 | })); 282 | 283 | if (self.connectionTimeout) { 284 | connectionTimeoutTimer = setTimeout(function () { 285 | debug('Connection Timeout of %s ms exceeded', self.connectionTimeout); 286 | req.destroy(); 287 | }, self.connectionTimeout); 288 | } 289 | 290 | if (self.timeout) { 291 | req.setTimeout(self.timeout); 292 | req.on('timeout', function () { 293 | debug('Timeout of %s ms exceeded', self.timeout); 294 | req.destroy(); 295 | }); 296 | } 297 | 298 | if (context.hijack === true) { 299 | clearTimeout(connectionTimeoutTimer); 300 | req.on('upgrade', function (res, sock, head) { 301 | if (finished === false) { 302 | finished = true; 303 | if (head.length > 0) { 304 | sock.unshift(head); 305 | } 306 | return callback(null, sock); 307 | } 308 | }); 309 | } 310 | 311 | req.on('connect', function () { 312 | clearTimeout(connectionTimeoutTimer); 313 | }); 314 | 315 | req.on('disconnect', function () { 316 | clearTimeout(connectionTimeoutTimer); 317 | }); 318 | 319 | req.on('response', function (res) { 320 | clearTimeout(connectionTimeoutTimer); 321 | if (context.isStream === true) { 322 | if (finished === false) { 323 | finished = true; 324 | self.buildPayload(null, context.isStream, context.statusCodes, context.openStdin, req, res, null, callback); 325 | } 326 | } else { 327 | // The native 'request' method only handles aborting during the request lifecycle not the response lifecycle. 328 | // We need to make the response stream abortable so that it's destroyed with an error on abort and then 329 | // it triggers the request 'error' event 330 | if (options.signal != null) { 331 | stream.addAbortSignal(options.signal, res) 332 | } 333 | var chunks = []; 334 | res.on('data', function (chunk) { 335 | chunks.push(chunk); 336 | }); 337 | 338 | res.on('end', function () { 339 | var buffer = Buffer.concat(chunks); 340 | var result = buffer.toString(); 341 | 342 | debug('Received: %s', result); 343 | 344 | var json = utils.parseJSON(result) || buffer; 345 | if (finished === false) { 346 | finished = true; 347 | self.buildPayload(null, context.isStream, context.statusCodes, false, req, res, json, callback); 348 | } 349 | }); 350 | } 351 | }); 352 | 353 | req.on('error', function (error) { 354 | clearTimeout(connectionTimeoutTimer); 355 | if (finished === false) { 356 | finished = true; 357 | self.buildPayload(error, context.isStream, context.statusCodes, false, {}, {}, null, callback); 358 | } 359 | }); 360 | 361 | if (typeof data === 'string' || Buffer.isBuffer(data)) { 362 | req.write(data); 363 | } else if (data) { 364 | data.on('error', function (error) { 365 | req.destroy(error); 366 | }); 367 | data.pipe(req); 368 | } 369 | 370 | if (!context.openStdin && (typeof data === 'string' || data === undefined || Buffer.isBuffer(data))) { 371 | req.end(); 372 | } 373 | }; 374 | 375 | Modem.prototype.buildPayload = function (err, isStream, statusCodes, openStdin, req, res, json, cb) { 376 | if (err) return cb(err, null); 377 | 378 | if (statusCodes[res.statusCode] !== true) { 379 | getCause(isStream, res, json, function (err, cause) { 380 | if (err) { 381 | return cb(err, null); 382 | } 383 | var msg = new Error( 384 | '(HTTP code ' + res.statusCode + ') ' + 385 | (statusCodes[res.statusCode] || 'unexpected') + ' - ' + 386 | (cause.message || cause.error || cause) + ' ' 387 | ); 388 | msg.reason = statusCodes[res.statusCode]; 389 | msg.statusCode = res.statusCode; 390 | msg.json = json; 391 | cb(msg, null); 392 | }); 393 | } else { 394 | if (openStdin) { 395 | cb(null, new HttpDuplex(req, res)); 396 | } else if (isStream) { 397 | cb(null, res); 398 | } else { 399 | cb(null, json); 400 | } 401 | } 402 | 403 | function getCause(isStream, res, json, callback) { 404 | var chunks = ''; 405 | var done = false; 406 | 407 | if (isStream) { 408 | res.on('data', function (chunk) { 409 | chunks += chunk; 410 | }); 411 | res.on('error', function (err) { 412 | handler(err, null); 413 | }); 414 | res.on('end', function () { 415 | handler(null, utils.parseJSON(chunks) || chunks) 416 | }); 417 | } else { 418 | callback(null, json); 419 | } 420 | 421 | function handler(err, data) { 422 | if (done === false) { 423 | if (err) { 424 | callback(err); 425 | } else { 426 | callback(null, data); 427 | } 428 | } 429 | done = true; 430 | } 431 | } 432 | }; 433 | 434 | Modem.prototype.demuxStream = function (streama, stdout, stderr) { 435 | var nextDataType = null; 436 | var nextDataLength = null; 437 | var buffer = Buffer.from(''); 438 | function processData(data) { 439 | if (data) { 440 | buffer = Buffer.concat([buffer, data]); 441 | } 442 | if (!nextDataType) { 443 | if (buffer.length >= 8) { 444 | var header = bufferSlice(8); 445 | nextDataType = header.readUInt8(0); 446 | nextDataLength = header.readUInt32BE(4); 447 | // It's possible we got a "data" that contains multiple messages 448 | // Process the next one 449 | processData(); 450 | } 451 | } else { 452 | if (buffer.length >= nextDataLength) { 453 | var content = bufferSlice(nextDataLength); 454 | if (nextDataType === 1) { 455 | stdout.write(content); 456 | } else { 457 | stderr.write(content); 458 | } 459 | nextDataType = null; 460 | // It's possible we got a "data" that contains multiple messages 461 | // Process the next one 462 | processData(); 463 | } 464 | } 465 | } 466 | 467 | function bufferSlice(end) { 468 | var out = buffer.subarray(0, end); 469 | buffer = Buffer.from(buffer.subarray(end, buffer.length)); 470 | return out; 471 | } 472 | 473 | streama.on('data', processData); 474 | }; 475 | 476 | Modem.prototype.followProgress = function (streama, onFinished, onProgress) { 477 | var buf = ''; 478 | var output = []; 479 | var finished = false; 480 | 481 | streama.on('data', onStreamEvent); 482 | streama.on('error', onStreamError); 483 | streama.on('end', onStreamEnd); 484 | streama.on('close', onStreamEnd); 485 | 486 | function onStreamEvent(data) { 487 | buf += data.toString(); 488 | pump(); 489 | 490 | function pump() { 491 | var pos; 492 | while ((pos = buf.indexOf('\n')) >= 0) { 493 | if (pos == 0) { 494 | buf = buf.slice(1); 495 | continue; 496 | } 497 | processLine(buf.slice(0, pos)); 498 | buf = buf.slice(pos + 1); 499 | } 500 | } 501 | 502 | function processLine(line) { 503 | if (line[line.length - 1] == '\r') line = line.substr(0, line.length - 1); 504 | if (line.length > 0) { 505 | var obj = JSON.parse(line); 506 | output.push(obj); 507 | if (onProgress) { 508 | onProgress(obj); 509 | } 510 | } 511 | } 512 | }; 513 | 514 | function onStreamError(err) { 515 | finished = true; 516 | streama.removeListener('data', onStreamEvent); 517 | streama.removeListener('error', onStreamError); 518 | streama.removeListener('end', onStreamEnd); 519 | streama.removeListener('close', onStreamEnd); 520 | onFinished(err, output); 521 | } 522 | 523 | function onStreamEnd() { 524 | if (!finished) onFinished(null, output); 525 | finished = true; 526 | } 527 | }; 528 | 529 | Modem.prototype.buildQuerystring = function (opts) { 530 | var clone = {}; 531 | 532 | Object.keys(opts).map(function (key, i) { 533 | if ( 534 | opts[key] && 535 | typeof opts[key] === 'object' && 536 | !Array.isArray(opts[key]) 537 | ) { 538 | clone[key] = JSON.stringify(opts[key]); 539 | } else { 540 | clone[key] = opts[key]; 541 | } 542 | }); 543 | 544 | return querystring.stringify(clone); 545 | }; 546 | 547 | module.exports = Modem; 548 | -------------------------------------------------------------------------------- /lib/ssh.js: -------------------------------------------------------------------------------- 1 | var Client = require('ssh2').Client, 2 | http = require('http'); 3 | 4 | module.exports = function (opt) { 5 | var conn = new Client(); 6 | var agent = new http.Agent(); 7 | 8 | agent.createConnection = function (options, fn) { 9 | try { 10 | conn.once('ready', function () { 11 | conn.exec('docker system dial-stdio', function (err, stream) { 12 | if (err) { 13 | handleError(err , fn); 14 | } 15 | 16 | fn(null, stream); 17 | 18 | stream.addListener('error', (err) => { 19 | handleError(err, fn); 20 | }); 21 | stream.once('close', () => { 22 | conn.end(); 23 | agent.destroy(); 24 | }); 25 | }); 26 | }).on('error', (err) => { 27 | handleError(err, fn); 28 | }) 29 | .connect(opt); 30 | conn.once('end', () => agent.destroy()); 31 | 32 | } catch (err) { 33 | handleError(err); 34 | } 35 | }; 36 | 37 | function handleError(err, cb) { 38 | conn.end(); 39 | agent.destroy(); 40 | if (cb) { 41 | cb(err); 42 | } else { 43 | throw err; 44 | } 45 | } 46 | 47 | return agent; 48 | }; 49 | -------------------------------------------------------------------------------- /lib/utils.js: -------------------------------------------------------------------------------- 1 | // https://github.com/HenrikJoreteg/extend-object/blob/v0.1.0/extend-object.js 2 | 3 | var arr = []; 4 | var each = arr.forEach; 5 | var slice = arr.slice; 6 | 7 | module.exports.extend = function(obj) { 8 | each.call(slice.call(arguments, 1), function(source) { 9 | if (source) { 10 | for (var prop in source) { 11 | obj[prop] = source[prop]; 12 | } 13 | } 14 | }); 15 | return obj; 16 | }; 17 | 18 | module.exports.parseJSON = function(s) { 19 | try { 20 | return JSON.parse(s); 21 | } catch (e) { 22 | return null; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker-modem", 3 | "version": "5.0.6", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "docker-modem", 9 | "version": "5.0.6", 10 | "license": "Apache-2.0", 11 | "dependencies": { 12 | "debug": "^4.1.1", 13 | "readable-stream": "^3.5.0", 14 | "split-ca": "^1.0.1", 15 | "ssh2": "^1.15.0" 16 | }, 17 | "devDependencies": { 18 | "chai": "~4.2.0", 19 | "mocha": "^10.2.0" 20 | }, 21 | "engines": { 22 | "node": ">= 8.0" 23 | } 24 | }, 25 | "node_modules/ansi-colors": { 26 | "version": "4.1.3", 27 | "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", 28 | "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", 29 | "dev": true, 30 | "license": "MIT", 31 | "engines": { 32 | "node": ">=6" 33 | } 34 | }, 35 | "node_modules/ansi-regex": { 36 | "version": "5.0.1", 37 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", 38 | "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", 39 | "dev": true, 40 | "engines": { 41 | "node": ">=8" 42 | } 43 | }, 44 | "node_modules/ansi-styles": { 45 | "version": "4.3.0", 46 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", 47 | "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", 48 | "dev": true, 49 | "dependencies": { 50 | "color-convert": "^2.0.1" 51 | }, 52 | "engines": { 53 | "node": ">=8" 54 | }, 55 | "funding": { 56 | "url": "https://github.com/chalk/ansi-styles?sponsor=1" 57 | } 58 | }, 59 | "node_modules/anymatch": { 60 | "version": "3.1.2", 61 | "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", 62 | "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", 63 | "dev": true, 64 | "dependencies": { 65 | "normalize-path": "^3.0.0", 66 | "picomatch": "^2.0.4" 67 | }, 68 | "engines": { 69 | "node": ">= 8" 70 | } 71 | }, 72 | "node_modules/argparse": { 73 | "version": "2.0.1", 74 | "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", 75 | "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", 76 | "dev": true 77 | }, 78 | "node_modules/asn1": { 79 | "version": "0.2.6", 80 | "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", 81 | "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", 82 | "dependencies": { 83 | "safer-buffer": "~2.1.0" 84 | } 85 | }, 86 | "node_modules/assertion-error": { 87 | "version": "1.1.0", 88 | "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", 89 | "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", 90 | "dev": true, 91 | "engines": { 92 | "node": "*" 93 | } 94 | }, 95 | "node_modules/balanced-match": { 96 | "version": "1.0.2", 97 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", 98 | "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", 99 | "dev": true, 100 | "license": "MIT" 101 | }, 102 | "node_modules/bcrypt-pbkdf": { 103 | "version": "1.0.2", 104 | "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", 105 | "integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==", 106 | "dependencies": { 107 | "tweetnacl": "^0.14.3" 108 | } 109 | }, 110 | "node_modules/binary-extensions": { 111 | "version": "2.2.0", 112 | "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", 113 | "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", 114 | "dev": true, 115 | "engines": { 116 | "node": ">=8" 117 | } 118 | }, 119 | "node_modules/brace-expansion": { 120 | "version": "2.0.1", 121 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", 122 | "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", 123 | "dev": true, 124 | "license": "MIT", 125 | "dependencies": { 126 | "balanced-match": "^1.0.0" 127 | } 128 | }, 129 | "node_modules/braces": { 130 | "version": "3.0.3", 131 | "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", 132 | "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", 133 | "dev": true, 134 | "dependencies": { 135 | "fill-range": "^7.1.1" 136 | }, 137 | "engines": { 138 | "node": ">=8" 139 | } 140 | }, 141 | "node_modules/browser-stdout": { 142 | "version": "1.3.1", 143 | "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", 144 | "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", 145 | "dev": true 146 | }, 147 | "node_modules/camelcase": { 148 | "version": "6.3.0", 149 | "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", 150 | "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", 151 | "dev": true, 152 | "engines": { 153 | "node": ">=10" 154 | }, 155 | "funding": { 156 | "url": "https://github.com/sponsors/sindresorhus" 157 | } 158 | }, 159 | "node_modules/chai": { 160 | "version": "4.2.0", 161 | "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", 162 | "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", 163 | "dev": true, 164 | "dependencies": { 165 | "assertion-error": "^1.1.0", 166 | "check-error": "^1.0.2", 167 | "deep-eql": "^3.0.1", 168 | "get-func-name": "^2.0.0", 169 | "pathval": "^1.1.0", 170 | "type-detect": "^4.0.5" 171 | }, 172 | "engines": { 173 | "node": ">=4" 174 | } 175 | }, 176 | "node_modules/chalk": { 177 | "version": "4.1.2", 178 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", 179 | "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", 180 | "dev": true, 181 | "dependencies": { 182 | "ansi-styles": "^4.1.0", 183 | "supports-color": "^7.1.0" 184 | }, 185 | "engines": { 186 | "node": ">=10" 187 | }, 188 | "funding": { 189 | "url": "https://github.com/chalk/chalk?sponsor=1" 190 | } 191 | }, 192 | "node_modules/chalk/node_modules/supports-color": { 193 | "version": "7.2.0", 194 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", 195 | "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", 196 | "dev": true, 197 | "dependencies": { 198 | "has-flag": "^4.0.0" 199 | }, 200 | "engines": { 201 | "node": ">=8" 202 | } 203 | }, 204 | "node_modules/check-error": { 205 | "version": "1.0.2", 206 | "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", 207 | "integrity": "sha512-BrgHpW9NURQgzoNyjfq0Wu6VFO6D7IZEmJNdtgNqpzGG8RuNFHt2jQxWlAs4HMe119chBnv+34syEZtc6IhLtA==", 208 | "dev": true, 209 | "engines": { 210 | "node": "*" 211 | } 212 | }, 213 | "node_modules/chokidar": { 214 | "version": "3.5.3", 215 | "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", 216 | "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", 217 | "dev": true, 218 | "funding": [ 219 | { 220 | "type": "individual", 221 | "url": "https://paulmillr.com/funding/" 222 | } 223 | ], 224 | "dependencies": { 225 | "anymatch": "~3.1.2", 226 | "braces": "~3.0.2", 227 | "glob-parent": "~5.1.2", 228 | "is-binary-path": "~2.1.0", 229 | "is-glob": "~4.0.1", 230 | "normalize-path": "~3.0.0", 231 | "readdirp": "~3.6.0" 232 | }, 233 | "engines": { 234 | "node": ">= 8.10.0" 235 | }, 236 | "optionalDependencies": { 237 | "fsevents": "~2.3.2" 238 | } 239 | }, 240 | "node_modules/cliui": { 241 | "version": "7.0.4", 242 | "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", 243 | "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", 244 | "dev": true, 245 | "dependencies": { 246 | "string-width": "^4.2.0", 247 | "strip-ansi": "^6.0.0", 248 | "wrap-ansi": "^7.0.0" 249 | } 250 | }, 251 | "node_modules/color-convert": { 252 | "version": "2.0.1", 253 | "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", 254 | "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", 255 | "dev": true, 256 | "dependencies": { 257 | "color-name": "~1.1.4" 258 | }, 259 | "engines": { 260 | "node": ">=7.0.0" 261 | } 262 | }, 263 | "node_modules/color-name": { 264 | "version": "1.1.4", 265 | "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", 266 | "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", 267 | "dev": true 268 | }, 269 | "node_modules/debug": { 270 | "version": "4.4.0", 271 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", 272 | "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", 273 | "license": "MIT", 274 | "dependencies": { 275 | "ms": "^2.1.3" 276 | }, 277 | "engines": { 278 | "node": ">=6.0" 279 | }, 280 | "peerDependenciesMeta": { 281 | "supports-color": { 282 | "optional": true 283 | } 284 | } 285 | }, 286 | "node_modules/decamelize": { 287 | "version": "4.0.0", 288 | "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", 289 | "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", 290 | "dev": true, 291 | "engines": { 292 | "node": ">=10" 293 | }, 294 | "funding": { 295 | "url": "https://github.com/sponsors/sindresorhus" 296 | } 297 | }, 298 | "node_modules/deep-eql": { 299 | "version": "3.0.1", 300 | "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", 301 | "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", 302 | "dev": true, 303 | "dependencies": { 304 | "type-detect": "^4.0.0" 305 | }, 306 | "engines": { 307 | "node": ">=0.12" 308 | } 309 | }, 310 | "node_modules/diff": { 311 | "version": "5.2.0", 312 | "resolved": "https://registry.npmjs.org/diff/-/diff-5.2.0.tgz", 313 | "integrity": "sha512-uIFDxqpRZGZ6ThOk84hEfqWoHx2devRFvpTZcTHur85vImfaxUbTW9Ryh4CpCuDnToOP1CEtXKIgytHBPVff5A==", 314 | "dev": true, 315 | "license": "BSD-3-Clause", 316 | "engines": { 317 | "node": ">=0.3.1" 318 | } 319 | }, 320 | "node_modules/emoji-regex": { 321 | "version": "8.0.0", 322 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", 323 | "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", 324 | "dev": true 325 | }, 326 | "node_modules/escalade": { 327 | "version": "3.1.1", 328 | "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", 329 | "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", 330 | "dev": true, 331 | "engines": { 332 | "node": ">=6" 333 | } 334 | }, 335 | "node_modules/escape-string-regexp": { 336 | "version": "4.0.0", 337 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", 338 | "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", 339 | "dev": true, 340 | "engines": { 341 | "node": ">=10" 342 | }, 343 | "funding": { 344 | "url": "https://github.com/sponsors/sindresorhus" 345 | } 346 | }, 347 | "node_modules/fill-range": { 348 | "version": "7.1.1", 349 | "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", 350 | "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", 351 | "dev": true, 352 | "dependencies": { 353 | "to-regex-range": "^5.0.1" 354 | }, 355 | "engines": { 356 | "node": ">=8" 357 | } 358 | }, 359 | "node_modules/find-up": { 360 | "version": "5.0.0", 361 | "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", 362 | "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", 363 | "dev": true, 364 | "dependencies": { 365 | "locate-path": "^6.0.0", 366 | "path-exists": "^4.0.0" 367 | }, 368 | "engines": { 369 | "node": ">=10" 370 | }, 371 | "funding": { 372 | "url": "https://github.com/sponsors/sindresorhus" 373 | } 374 | }, 375 | "node_modules/flat": { 376 | "version": "5.0.2", 377 | "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", 378 | "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", 379 | "dev": true, 380 | "bin": { 381 | "flat": "cli.js" 382 | } 383 | }, 384 | "node_modules/fs.realpath": { 385 | "version": "1.0.0", 386 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 387 | "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", 388 | "dev": true, 389 | "license": "ISC" 390 | }, 391 | "node_modules/fsevents": { 392 | "version": "2.3.2", 393 | "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", 394 | "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", 395 | "dev": true, 396 | "hasInstallScript": true, 397 | "optional": true, 398 | "os": [ 399 | "darwin" 400 | ], 401 | "engines": { 402 | "node": "^8.16.0 || ^10.6.0 || >=11.0.0" 403 | } 404 | }, 405 | "node_modules/get-caller-file": { 406 | "version": "2.0.5", 407 | "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", 408 | "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", 409 | "dev": true, 410 | "engines": { 411 | "node": "6.* || 8.* || >= 10.*" 412 | } 413 | }, 414 | "node_modules/get-func-name": { 415 | "version": "2.0.2", 416 | "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", 417 | "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", 418 | "dev": true, 419 | "engines": { 420 | "node": "*" 421 | } 422 | }, 423 | "node_modules/glob": { 424 | "version": "8.1.0", 425 | "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", 426 | "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", 427 | "deprecated": "Glob versions prior to v9 are no longer supported", 428 | "dev": true, 429 | "license": "ISC", 430 | "dependencies": { 431 | "fs.realpath": "^1.0.0", 432 | "inflight": "^1.0.4", 433 | "inherits": "2", 434 | "minimatch": "^5.0.1", 435 | "once": "^1.3.0" 436 | }, 437 | "engines": { 438 | "node": ">=12" 439 | }, 440 | "funding": { 441 | "url": "https://github.com/sponsors/isaacs" 442 | } 443 | }, 444 | "node_modules/glob-parent": { 445 | "version": "5.1.2", 446 | "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", 447 | "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", 448 | "dev": true, 449 | "dependencies": { 450 | "is-glob": "^4.0.1" 451 | }, 452 | "engines": { 453 | "node": ">= 6" 454 | } 455 | }, 456 | "node_modules/has-flag": { 457 | "version": "4.0.0", 458 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", 459 | "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", 460 | "dev": true, 461 | "engines": { 462 | "node": ">=8" 463 | } 464 | }, 465 | "node_modules/he": { 466 | "version": "1.2.0", 467 | "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", 468 | "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", 469 | "dev": true, 470 | "bin": { 471 | "he": "bin/he" 472 | } 473 | }, 474 | "node_modules/inflight": { 475 | "version": "1.0.6", 476 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 477 | "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", 478 | "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", 479 | "dev": true, 480 | "license": "ISC", 481 | "dependencies": { 482 | "once": "^1.3.0", 483 | "wrappy": "1" 484 | } 485 | }, 486 | "node_modules/inherits": { 487 | "version": "2.0.4", 488 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 489 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 490 | }, 491 | "node_modules/is-binary-path": { 492 | "version": "2.1.0", 493 | "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", 494 | "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", 495 | "dev": true, 496 | "dependencies": { 497 | "binary-extensions": "^2.0.0" 498 | }, 499 | "engines": { 500 | "node": ">=8" 501 | } 502 | }, 503 | "node_modules/is-extglob": { 504 | "version": "2.1.1", 505 | "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", 506 | "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", 507 | "dev": true, 508 | "engines": { 509 | "node": ">=0.10.0" 510 | } 511 | }, 512 | "node_modules/is-fullwidth-code-point": { 513 | "version": "3.0.0", 514 | "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", 515 | "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", 516 | "dev": true, 517 | "engines": { 518 | "node": ">=8" 519 | } 520 | }, 521 | "node_modules/is-glob": { 522 | "version": "4.0.3", 523 | "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", 524 | "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", 525 | "dev": true, 526 | "dependencies": { 527 | "is-extglob": "^2.1.1" 528 | }, 529 | "engines": { 530 | "node": ">=0.10.0" 531 | } 532 | }, 533 | "node_modules/is-number": { 534 | "version": "7.0.0", 535 | "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", 536 | "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", 537 | "dev": true, 538 | "engines": { 539 | "node": ">=0.12.0" 540 | } 541 | }, 542 | "node_modules/is-plain-obj": { 543 | "version": "2.1.0", 544 | "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", 545 | "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", 546 | "dev": true, 547 | "engines": { 548 | "node": ">=8" 549 | } 550 | }, 551 | "node_modules/is-unicode-supported": { 552 | "version": "0.1.0", 553 | "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", 554 | "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", 555 | "dev": true, 556 | "engines": { 557 | "node": ">=10" 558 | }, 559 | "funding": { 560 | "url": "https://github.com/sponsors/sindresorhus" 561 | } 562 | }, 563 | "node_modules/js-yaml": { 564 | "version": "4.1.0", 565 | "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", 566 | "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", 567 | "dev": true, 568 | "dependencies": { 569 | "argparse": "^2.0.1" 570 | }, 571 | "bin": { 572 | "js-yaml": "bin/js-yaml.js" 573 | } 574 | }, 575 | "node_modules/locate-path": { 576 | "version": "6.0.0", 577 | "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", 578 | "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", 579 | "dev": true, 580 | "dependencies": { 581 | "p-locate": "^5.0.0" 582 | }, 583 | "engines": { 584 | "node": ">=10" 585 | }, 586 | "funding": { 587 | "url": "https://github.com/sponsors/sindresorhus" 588 | } 589 | }, 590 | "node_modules/log-symbols": { 591 | "version": "4.1.0", 592 | "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", 593 | "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", 594 | "dev": true, 595 | "dependencies": { 596 | "chalk": "^4.1.0", 597 | "is-unicode-supported": "^0.1.0" 598 | }, 599 | "engines": { 600 | "node": ">=10" 601 | }, 602 | "funding": { 603 | "url": "https://github.com/sponsors/sindresorhus" 604 | } 605 | }, 606 | "node_modules/minimatch": { 607 | "version": "5.1.6", 608 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", 609 | "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", 610 | "dev": true, 611 | "license": "ISC", 612 | "dependencies": { 613 | "brace-expansion": "^2.0.1" 614 | }, 615 | "engines": { 616 | "node": ">=10" 617 | } 618 | }, 619 | "node_modules/mocha": { 620 | "version": "10.8.2", 621 | "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.8.2.tgz", 622 | "integrity": "sha512-VZlYo/WE8t1tstuRmqgeyBgCbJc/lEdopaa+axcKzTBJ+UIdlAB9XnmvTCAH4pwR4ElNInaedhEBmZD8iCSVEg==", 623 | "dev": true, 624 | "license": "MIT", 625 | "dependencies": { 626 | "ansi-colors": "^4.1.3", 627 | "browser-stdout": "^1.3.1", 628 | "chokidar": "^3.5.3", 629 | "debug": "^4.3.5", 630 | "diff": "^5.2.0", 631 | "escape-string-regexp": "^4.0.0", 632 | "find-up": "^5.0.0", 633 | "glob": "^8.1.0", 634 | "he": "^1.2.0", 635 | "js-yaml": "^4.1.0", 636 | "log-symbols": "^4.1.0", 637 | "minimatch": "^5.1.6", 638 | "ms": "^2.1.3", 639 | "serialize-javascript": "^6.0.2", 640 | "strip-json-comments": "^3.1.1", 641 | "supports-color": "^8.1.1", 642 | "workerpool": "^6.5.1", 643 | "yargs": "^16.2.0", 644 | "yargs-parser": "^20.2.9", 645 | "yargs-unparser": "^2.0.0" 646 | }, 647 | "bin": { 648 | "_mocha": "bin/_mocha", 649 | "mocha": "bin/mocha.js" 650 | }, 651 | "engines": { 652 | "node": ">= 14.0.0" 653 | } 654 | }, 655 | "node_modules/ms": { 656 | "version": "2.1.3", 657 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", 658 | "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", 659 | "license": "MIT" 660 | }, 661 | "node_modules/normalize-path": { 662 | "version": "3.0.0", 663 | "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", 664 | "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", 665 | "dev": true, 666 | "engines": { 667 | "node": ">=0.10.0" 668 | } 669 | }, 670 | "node_modules/once": { 671 | "version": "1.4.0", 672 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 673 | "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", 674 | "dev": true, 675 | "license": "ISC", 676 | "dependencies": { 677 | "wrappy": "1" 678 | } 679 | }, 680 | "node_modules/p-limit": { 681 | "version": "3.1.0", 682 | "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", 683 | "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", 684 | "dev": true, 685 | "dependencies": { 686 | "yocto-queue": "^0.1.0" 687 | }, 688 | "engines": { 689 | "node": ">=10" 690 | }, 691 | "funding": { 692 | "url": "https://github.com/sponsors/sindresorhus" 693 | } 694 | }, 695 | "node_modules/p-locate": { 696 | "version": "5.0.0", 697 | "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", 698 | "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", 699 | "dev": true, 700 | "dependencies": { 701 | "p-limit": "^3.0.2" 702 | }, 703 | "engines": { 704 | "node": ">=10" 705 | }, 706 | "funding": { 707 | "url": "https://github.com/sponsors/sindresorhus" 708 | } 709 | }, 710 | "node_modules/path-exists": { 711 | "version": "4.0.0", 712 | "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", 713 | "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", 714 | "dev": true, 715 | "engines": { 716 | "node": ">=8" 717 | } 718 | }, 719 | "node_modules/pathval": { 720 | "version": "1.1.1", 721 | "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", 722 | "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", 723 | "dev": true, 724 | "engines": { 725 | "node": "*" 726 | } 727 | }, 728 | "node_modules/picomatch": { 729 | "version": "2.3.1", 730 | "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", 731 | "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", 732 | "dev": true, 733 | "engines": { 734 | "node": ">=8.6" 735 | }, 736 | "funding": { 737 | "url": "https://github.com/sponsors/jonschlinkert" 738 | } 739 | }, 740 | "node_modules/randombytes": { 741 | "version": "2.1.0", 742 | "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", 743 | "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", 744 | "dev": true, 745 | "license": "MIT", 746 | "dependencies": { 747 | "safe-buffer": "^5.1.0" 748 | } 749 | }, 750 | "node_modules/readable-stream": { 751 | "version": "3.6.0", 752 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", 753 | "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", 754 | "dependencies": { 755 | "inherits": "^2.0.3", 756 | "string_decoder": "^1.1.1", 757 | "util-deprecate": "^1.0.1" 758 | }, 759 | "engines": { 760 | "node": ">= 6" 761 | } 762 | }, 763 | "node_modules/readdirp": { 764 | "version": "3.6.0", 765 | "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", 766 | "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", 767 | "dev": true, 768 | "dependencies": { 769 | "picomatch": "^2.2.1" 770 | }, 771 | "engines": { 772 | "node": ">=8.10.0" 773 | } 774 | }, 775 | "node_modules/require-directory": { 776 | "version": "2.1.1", 777 | "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", 778 | "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", 779 | "dev": true, 780 | "engines": { 781 | "node": ">=0.10.0" 782 | } 783 | }, 784 | "node_modules/safe-buffer": { 785 | "version": "5.2.1", 786 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 787 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", 788 | "funding": [ 789 | { 790 | "type": "github", 791 | "url": "https://github.com/sponsors/feross" 792 | }, 793 | { 794 | "type": "patreon", 795 | "url": "https://www.patreon.com/feross" 796 | }, 797 | { 798 | "type": "consulting", 799 | "url": "https://feross.org/support" 800 | } 801 | ] 802 | }, 803 | "node_modules/safer-buffer": { 804 | "version": "2.1.2", 805 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", 806 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" 807 | }, 808 | "node_modules/serialize-javascript": { 809 | "version": "6.0.2", 810 | "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", 811 | "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", 812 | "dev": true, 813 | "license": "BSD-3-Clause", 814 | "dependencies": { 815 | "randombytes": "^2.1.0" 816 | } 817 | }, 818 | "node_modules/split-ca": { 819 | "version": "1.0.1", 820 | "resolved": "https://registry.npmjs.org/split-ca/-/split-ca-1.0.1.tgz", 821 | "integrity": "sha1-bIOv82kvphJW4M0ZfgXp3hV2kaY=" 822 | }, 823 | "node_modules/ssh2": { 824 | "version": "1.15.0", 825 | "resolved": "https://registry.npmjs.org/ssh2/-/ssh2-1.15.0.tgz", 826 | "integrity": "sha512-C0PHgX4h6lBxYx7hcXwu3QWdh4tg6tZZsTfXcdvc5caW/EMxaB4H9dWsl7qk+F7LAW762hp8VbXOX7x4xUYvEw==", 827 | "hasInstallScript": true, 828 | "dependencies": { 829 | "asn1": "^0.2.6", 830 | "bcrypt-pbkdf": "^1.0.2" 831 | }, 832 | "engines": { 833 | "node": ">=10.16.0" 834 | }, 835 | "optionalDependencies": { 836 | "cpu-features": "~0.0.9", 837 | "nan": "^2.18.0" 838 | } 839 | }, 840 | "node_modules/string_decoder": { 841 | "version": "1.3.0", 842 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", 843 | "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", 844 | "dependencies": { 845 | "safe-buffer": "~5.2.0" 846 | } 847 | }, 848 | "node_modules/string-width": { 849 | "version": "4.2.3", 850 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", 851 | "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", 852 | "dev": true, 853 | "dependencies": { 854 | "emoji-regex": "^8.0.0", 855 | "is-fullwidth-code-point": "^3.0.0", 856 | "strip-ansi": "^6.0.1" 857 | }, 858 | "engines": { 859 | "node": ">=8" 860 | } 861 | }, 862 | "node_modules/strip-ansi": { 863 | "version": "6.0.1", 864 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", 865 | "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", 866 | "dev": true, 867 | "dependencies": { 868 | "ansi-regex": "^5.0.1" 869 | }, 870 | "engines": { 871 | "node": ">=8" 872 | } 873 | }, 874 | "node_modules/strip-json-comments": { 875 | "version": "3.1.1", 876 | "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", 877 | "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", 878 | "dev": true, 879 | "engines": { 880 | "node": ">=8" 881 | }, 882 | "funding": { 883 | "url": "https://github.com/sponsors/sindresorhus" 884 | } 885 | }, 886 | "node_modules/supports-color": { 887 | "version": "8.1.1", 888 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", 889 | "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", 890 | "dev": true, 891 | "dependencies": { 892 | "has-flag": "^4.0.0" 893 | }, 894 | "engines": { 895 | "node": ">=10" 896 | }, 897 | "funding": { 898 | "url": "https://github.com/chalk/supports-color?sponsor=1" 899 | } 900 | }, 901 | "node_modules/to-regex-range": { 902 | "version": "5.0.1", 903 | "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", 904 | "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", 905 | "dev": true, 906 | "dependencies": { 907 | "is-number": "^7.0.0" 908 | }, 909 | "engines": { 910 | "node": ">=8.0" 911 | } 912 | }, 913 | "node_modules/tweetnacl": { 914 | "version": "0.14.5", 915 | "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", 916 | "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" 917 | }, 918 | "node_modules/type-detect": { 919 | "version": "4.0.8", 920 | "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", 921 | "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", 922 | "dev": true, 923 | "engines": { 924 | "node": ">=4" 925 | } 926 | }, 927 | "node_modules/util-deprecate": { 928 | "version": "1.0.2", 929 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 930 | "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" 931 | }, 932 | "node_modules/workerpool": { 933 | "version": "6.5.1", 934 | "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.5.1.tgz", 935 | "integrity": "sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==", 936 | "dev": true, 937 | "license": "Apache-2.0" 938 | }, 939 | "node_modules/wrap-ansi": { 940 | "version": "7.0.0", 941 | "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", 942 | "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", 943 | "dev": true, 944 | "dependencies": { 945 | "ansi-styles": "^4.0.0", 946 | "string-width": "^4.1.0", 947 | "strip-ansi": "^6.0.0" 948 | }, 949 | "engines": { 950 | "node": ">=10" 951 | }, 952 | "funding": { 953 | "url": "https://github.com/chalk/wrap-ansi?sponsor=1" 954 | } 955 | }, 956 | "node_modules/wrappy": { 957 | "version": "1.0.2", 958 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 959 | "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", 960 | "dev": true, 961 | "license": "ISC" 962 | }, 963 | "node_modules/y18n": { 964 | "version": "5.0.8", 965 | "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", 966 | "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", 967 | "dev": true, 968 | "engines": { 969 | "node": ">=10" 970 | } 971 | }, 972 | "node_modules/yargs": { 973 | "version": "16.2.0", 974 | "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", 975 | "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", 976 | "dev": true, 977 | "dependencies": { 978 | "cliui": "^7.0.2", 979 | "escalade": "^3.1.1", 980 | "get-caller-file": "^2.0.5", 981 | "require-directory": "^2.1.1", 982 | "string-width": "^4.2.0", 983 | "y18n": "^5.0.5", 984 | "yargs-parser": "^20.2.2" 985 | }, 986 | "engines": { 987 | "node": ">=10" 988 | } 989 | }, 990 | "node_modules/yargs-parser": { 991 | "version": "20.2.9", 992 | "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz", 993 | "integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==", 994 | "dev": true, 995 | "license": "ISC", 996 | "engines": { 997 | "node": ">=10" 998 | } 999 | }, 1000 | "node_modules/yargs-unparser": { 1001 | "version": "2.0.0", 1002 | "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", 1003 | "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", 1004 | "dev": true, 1005 | "dependencies": { 1006 | "camelcase": "^6.0.0", 1007 | "decamelize": "^4.0.0", 1008 | "flat": "^5.0.2", 1009 | "is-plain-obj": "^2.1.0" 1010 | }, 1011 | "engines": { 1012 | "node": ">=10" 1013 | } 1014 | }, 1015 | "node_modules/yocto-queue": { 1016 | "version": "0.1.0", 1017 | "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", 1018 | "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", 1019 | "dev": true, 1020 | "engines": { 1021 | "node": ">=10" 1022 | }, 1023 | "funding": { 1024 | "url": "https://github.com/sponsors/sindresorhus" 1025 | } 1026 | } 1027 | } 1028 | } 1029 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docker-modem", 3 | "description": "Docker remote API network layer module.", 4 | "version": "5.0.6", 5 | "author": "Pedro Dias ", 6 | "maintainers": [ 7 | "apocas " 8 | ], 9 | "license": "Apache-2.0", 10 | "repository": { 11 | "type": "git", 12 | "url": "http://github.com/apocas/docker-modem.git" 13 | }, 14 | "keywords": [ 15 | "containers", 16 | "api", 17 | "docker" 18 | ], 19 | "dependencies": { 20 | "debug": "^4.1.1", 21 | "readable-stream": "^3.5.0", 22 | "split-ca": "^1.0.1", 23 | "ssh2": "^1.15.0" 24 | }, 25 | "devDependencies": { 26 | "chai": "~4.2.0", 27 | "mocha": "^10.2.0" 28 | }, 29 | "main": "./lib/modem", 30 | "scripts": { 31 | "test": "./node_modules/mocha/bin/mocha.js -R spec --exit" 32 | }, 33 | "engines": { 34 | "node": ">= 8.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/modem_test.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | var path = require('path'); 3 | var os = require('os'); 4 | var http = require('http'); 5 | var Modem = require('../lib/modem'); 6 | 7 | var unixDefaultSocketPaths = ['/var/run/docker.sock', path.join(os.homedir(), '.docker/run/docker.sock')] 8 | var defaultSocketPaths = os.type() === 'Windows_NT' ? ['//./pipe/docker_engine'] : unixDefaultSocketPaths; 9 | 10 | describe('Modem', function () { 11 | beforeEach(function () { 12 | delete process.env.DOCKER_HOST; 13 | }); 14 | 15 | it('should default to default socket path', function () { 16 | var modem = new Modem(); 17 | 18 | return modem.getSocketPath().then((socketPath) => { 19 | assert.ok(socketPath); 20 | assert.ok(defaultSocketPaths.includes(socketPath)); 21 | }); 22 | }); 23 | 24 | it('should use specific cert, key and ca', function () { 25 | var ca = 'caaaaa'; 26 | var cert = 'certtttt'; 27 | var key = 'keyyyyy'; 28 | var modem = new Modem({ 29 | version: 'v1.39', 30 | host: '127.0.0.1', 31 | port: 2376, 32 | ca, 33 | cert, 34 | key 35 | }); 36 | 37 | assert.strictEqual(ca, modem.ca); 38 | assert.strictEqual(cert, modem.cert); 39 | assert.strictEqual(key, modem.key); 40 | }); 41 | 42 | it('shouldn\'t default to default socket path', function () { 43 | var modem = new Modem({ 44 | protocol: 'http', 45 | host: '127.0.0.1', 46 | port: 2375 47 | }); 48 | assert.ok(modem.host); 49 | assert.strictEqual(modem.socketPath, undefined); 50 | }); 51 | 52 | it('should use default value if argument not defined in constructor parameter object', function () { 53 | var customHeaders = { 54 | host: 'my-custom-host' 55 | }; 56 | var modem = new Modem({ 57 | headers: customHeaders 58 | }); 59 | assert.ok(modem.headers); 60 | assert.strictEqual(modem.headers, customHeaders); 61 | 62 | return modem.getSocketPath().then((socketPath) => { 63 | assert.ok(socketPath); 64 | assert.ok(defaultSocketPaths.includes(socketPath)); 65 | }); 66 | }); 67 | 68 | it('should allow DOCKER_HOST=unix:///path/to/docker.sock', function () { 69 | process.env.DOCKER_HOST = 'unix:///tmp/docker.sock'; 70 | 71 | var modem = new Modem(); 72 | assert.ok(modem.socketPath); 73 | assert.strictEqual(modem.host, undefined); 74 | assert.strictEqual(modem.socketPath, '/tmp/docker.sock'); 75 | }); 76 | 77 | it('should interpret DOCKER_HOST=unix:// as /var/run/docker.sock', function () { 78 | process.env.DOCKER_HOST = 'unix://'; 79 | 80 | var modem = new Modem(); 81 | return modem.getSocketPath().then((socketPath) => { 82 | assert.ok(socketPath); 83 | assert.ok(unixDefaultSocketPaths.includes(socketPath)); 84 | }); 85 | }); 86 | 87 | it('should use custom socketPath function once', function () { 88 | var count = 0; 89 | var modem = new Modem(); 90 | modem.socketPath = function() { 91 | assert(++count === 1); 92 | return 'testpath'; 93 | } 94 | modem.getSocketPath().then((socketPath) => { 95 | assert.ok(socketPath); 96 | assert.ok('testpath'); 97 | }); 98 | return modem.getSocketPath().then((socketPath) => { 99 | assert.ok(socketPath); 100 | assert.ok('testpath'); 101 | }); 102 | }); 103 | 104 | it('should interpret DOCKER_HOST=tcp://N.N.N.N:2376 as https', function () { 105 | process.env.DOCKER_HOST = 'tcp://192.168.59.103:2376'; 106 | 107 | var modem = new Modem(); 108 | assert.ok(modem.host); 109 | assert.ok(modem.port); 110 | assert.ok(modem.protocol); 111 | assert.strictEqual(modem.host, '192.168.59.103'); 112 | assert.strictEqual(modem.port, '2376'); 113 | assert.strictEqual(modem.protocol, 'https'); 114 | }); 115 | 116 | it('should interpret DOCKER_HOST=tcp://[::1]:12345', function () { 117 | process.env.DOCKER_HOST = 'tcp://[::1]:12345'; 118 | 119 | var modem = new Modem(); 120 | assert.ok(modem.host); 121 | assert.ok(modem.port); 122 | assert.ok(modem.protocol); 123 | assert.strictEqual(modem.host, '[::1]'); 124 | assert.strictEqual(modem.port, '12345'); 125 | assert.strictEqual(modem.protocol, 'http'); 126 | }); 127 | 128 | it('should interpret DOCKER_HOST=tcp://N.N.N.N:5555 as http', function () { 129 | delete process.env.DOCKER_TLS_VERIFY; 130 | process.env.DOCKER_HOST = 'tcp://192.168.59.105:5555'; 131 | 132 | var modem = new Modem(); 133 | assert.ok(modem.host); 134 | assert.ok(modem.port); 135 | assert.ok(modem.protocol); 136 | assert.strictEqual(modem.host, '192.168.59.105'); 137 | assert.strictEqual(modem.port, '5555'); 138 | assert.strictEqual(modem.protocol, 'http'); 139 | }); 140 | 141 | it('should interpret DOCKER_HOST=tcp://N.N.N.N:5555 as http', function () { 142 | process.env.DOCKER_TLS_VERIFY = '1'; 143 | process.env.DOCKER_HOST = 'tcp://192.168.59.105:5555'; 144 | 145 | var modem = new Modem(); 146 | assert.ok(modem.host); 147 | assert.ok(modem.port); 148 | assert.ok(modem.protocol); 149 | assert.strictEqual(modem.host, '192.168.59.105'); 150 | assert.strictEqual(modem.port, '5555'); 151 | assert.strictEqual(modem.protocol, 'https'); 152 | }); 153 | 154 | it('should accept DOCKER_HOST=N.N.N.N:5555 as http', function () { 155 | delete process.env.DOCKER_TLS_VERIFY; 156 | process.env.DOCKER_HOST = '192.168.59.105:5555'; 157 | 158 | var modem = new Modem(); 159 | assert.ok(modem.host); 160 | assert.ok(modem.port); 161 | assert.ok(modem.protocol); 162 | assert.strictEqual(modem.host, '192.168.59.105'); 163 | assert.strictEqual(modem.port, '5555'); 164 | assert.strictEqual(modem.protocol, 'http'); 165 | }); 166 | 167 | it('should auto encode querystring option maps as JSON', function () { 168 | var modem = new Modem(); 169 | 170 | var opts = { 171 | "limit": 12, 172 | "filters": { 173 | "label": [ 174 | "staging", 175 | "env=green", 176 | ], 177 | }, 178 | "t": [ 179 | "repo:latest", 180 | "repo:1.0.0", 181 | ], 182 | /* From /create/image */ 183 | changes: [ 184 | 'WORKDIR /app', 185 | 'EXPOSE 80', 186 | 'ENTRYPOINT ["node"]', 187 | 'CMD ["app.js"]', 188 | 'USER root', 189 | 'ENV NODE_ENV=production', 190 | 'ENV SOME_PASSWORD=dockerpassword', 191 | ] 192 | }; 193 | var control = 'limit=12&filters={"label"%3A["staging"%2C"env%3Dgreen"]}&t=repo%3Alatest&t=repo%3A1.0.0&changes=WORKDIR %2Fapp&changes=EXPOSE 80&changes=ENTRYPOINT ["node"]&changes=CMD ["app.js"]&changes=USER root&changes=ENV NODE_ENV%3Dproduction&changes=ENV SOME_PASSWORD%3Ddockerpassword'; 194 | var qs = modem.buildQuerystring(opts); 195 | assert.strictEqual(decodeURI(qs), control); 196 | 197 | }); 198 | 199 | it('should parse DOCKER_CLIENT_TIMEOUT from environment', function () { 200 | process.env.DOCKER_HOST = '192.168.59.105:5555'; 201 | process.env.DOCKER_CLIENT_TIMEOUT = 3000; 202 | 203 | var modem = new Modem(); 204 | assert.strictEqual(modem.timeout, 3000); 205 | }); 206 | 207 | it('should use default http agent when no agent is specified', function () { 208 | var modem = new Modem(); 209 | assert.strictEqual(typeof modem.agent, 'undefined'); 210 | }); 211 | 212 | it('should use custom http agent', function () { 213 | var httpAgent = new http.Agent({ 214 | keepAlive: true 215 | }); 216 | var modem = new Modem({ 217 | agent: httpAgent 218 | }); 219 | assert.ok(modem.agent instanceof http.Agent); 220 | assert.strictEqual(modem.agent, httpAgent); 221 | }); 222 | 223 | it('should set default ssh agent options from DOCKER_HOST', function() { 224 | process.env.DOCKER_HOST = 'ssh://user@192.168.59.105:5555'; 225 | process.env.SSH_AUTH_SOCK = '/var/lib/sock'; 226 | 227 | var modem = new Modem(); 228 | assert.strictEqual(modem.protocol, 'ssh'); 229 | assert.strictEqual(modem.username, 'user'); 230 | assert.ok(modem.sshOptions); 231 | assert.strictEqual(modem.sshOptions.agent, '/var/lib/sock'); 232 | }); 233 | 234 | it('should combine custom ssh agent options', function() { 235 | process.env.DOCKER_HOST = 'ssh://user@192.168.59.105:5555'; 236 | process.env.SSH_AUTH_SOCK = '/var/lib/sock'; 237 | 238 | var modem = new Modem({ 239 | sshOptions: { 240 | foo: 'bar', // options are arbitrary, whatever ssh2 supports 241 | }, 242 | }); 243 | assert.ok(modem.sshOptions); 244 | assert.strictEqual(modem.sshOptions.agent, '/var/lib/sock'); 245 | assert.strictEqual(modem.sshOptions.foo, 'bar'); 246 | }); 247 | }); 248 | --------------------------------------------------------------------------------