New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

docker-cli-js

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docker-cli-js - npm Package Compare versions

Comparing version 2.9.0 to 2.10.0

73

dist/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Options = exports.Docker = exports.dockerCommand = void 0;
const child_process = __importStar(require("child_process"));
const child_process = require("child_process");
const cli_table_2_json_1 = require("cli-table-2-json");
const dockermachine_cli_js_1 = require("dockermachine-cli-js");
//import * as _ from 'lodash';
//import * as _ from "lodash";
const snakeCase = require("lodash.snakecase");
const nodeify_ts_1 = __importDefault(require("nodeify-ts"));
const nodeify_ts_1 = require("nodeify-ts");
const exec = child_process.exec;
const splitLines = function (input) {
return input.replace(/\r/g, '').split('\n');
return input.replace(/\r/g, "").split("\n");
};

@@ -51,5 +27,5 @@ const array2Oject = function (lines) {

}
const parts = line.split(':');
const parts = line.split(":");
let key = parts[0];
const value = parts.slice(1).join(':');
const value = parts.slice(1).join(":");
key = snakeCase(key);

@@ -95,3 +71,3 @@ object[key] = value.trim();

const lines = splitLines(resultp.raw);
resultp.containerList = (0, cli_table_2_json_1.cliTable2Json)(lines);
resultp.containerList = cli_table_2_json_1.cliTable2Json(lines);
return resultp;

@@ -106,3 +82,3 @@ },

//debug(lines);
resultp.images = (0, cli_table_2_json_1.cliTable2Json)(lines);
resultp.images = cli_table_2_json_1.cliTable2Json(lines);
return resultp;

@@ -117,3 +93,3 @@ },

//debug(lines);
resultp.network = (0, cli_table_2_json_1.cliTable2Json)(lines);
resultp.network = cli_table_2_json_1.cliTable2Json(lines);
return resultp;

@@ -142,3 +118,3 @@ },

const lines = splitLines(resultp.raw);
resultp.images = (0, cli_table_2_json_1.cliTable2Json)(lines);
resultp.images = cli_table_2_json_1.cliTable2Json(lines);
return resultp;

@@ -172,3 +148,3 @@ },

const str = result.command;
const m = re.exec(str + ' ');
const m = re.exec(str + " ");
if (m !== null) {

@@ -185,3 +161,3 @@ if (m.index === re.lastIndex) {

};
const dockerCommand = (command, options = {
exports.dockerCommand = (command, options = {
currentWorkingDirectory: undefined,

@@ -192,4 +168,4 @@ echo: true,

stdin: undefined,
}) => __awaiter(void 0, void 0, void 0, function* () {
let machineconfig = '';
}) => __awaiter(this, void 0, void 0, function* () {
let machineconfig = "";
if (options.machineName) {

@@ -203,10 +179,9 @@ machineconfig = yield new dockermachine_cli_js_1.DockerMachine()

cwd: options.currentWorkingDirectory,
env: Object.assign({ DEBUG: '', HOME: process.env.HOME, PATH: process.env.PATH }, options.env),
env: Object.assign({ DEBUG: "", HOME: process.env.HOME, PATH: process.env.PATH, USER: process.env.USER }, options.env),
maxBuffer: 200 * 1024 * 1024,
};
const raw = yield new Promise((resolve, reject) => {
var _a, _b, _c, _d;
const childProcess = exec(execCommand, execOptions, (error, stdout, stderr) => {
if (error) {
return reject(Object.assign(new Error(`Error: stdout ${stdout}, stderr ${stderr}`), Object.assign(Object.assign({}, error), { stdout, stderr, innerError: error })));
return reject(Object.assign(new Error(`Error: stdout ${stdout}, stderr ${stderr}`), Object.assign({}, error, { stdout, stderr, innerError: error })));
}

@@ -216,10 +191,10 @@ resolve(stdout);

if (options.stdin) {
(_a = childProcess.stdin) === null || _a === void 0 ? void 0 : _a.write(options.stdin);
(_b = childProcess.stdin) === null || _b === void 0 ? void 0 : _b.end();
childProcess.stdin.write(options.stdin);
childProcess.stdin.end();
}
if (options.echo) {
(_c = childProcess.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (chunk) => {
childProcess.stdout.on("data", (chunk) => {
process.stdout.write(chunk.toString());
});
(_d = childProcess.stderr) === null || _d === void 0 ? void 0 : _d.on('data', (chunk) => {
childProcess.stderr.on("data", (chunk) => {
process.stderr.write(chunk.toString());

@@ -234,9 +209,8 @@ });

});
exports.dockerCommand = dockerCommand;
class Docker {
constructor(options = {
machineName: undefined,
currentWorkingDirectory: undefined,
echo: true,
env: undefined,
machineName: undefined,
stdin: undefined,

@@ -247,3 +221,3 @@ }) {

command(command, callback) {
return (0, nodeify_ts_1.default)((0, exports.dockerCommand)(command, this.options), callback);
return nodeify_ts_1.default(exports.dockerCommand(command, this.options), callback);
}

@@ -262,2 +236,1 @@ }

exports.Options = Options;
//# sourceMappingURL=index.js.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = __importStar(require("path"));
/* tslint:disable:no-shadowed-variable */
/* tslint:disable:no-unused-variable */
const test = require("blue-tape");
const path = require("path");
const index_1 = require("./index");
const index_2 = require("./index");
describe('docker-cli-js dockerCommand', () => {
it('info', () => {
const result = true;
expect(result).toBeTruthy();
const { dockerCommand } = require("./index");
test("docker-cli-js dockerCommand", (t) => {
t.test("info", (t) => {
const options = {
currentWorkingDirectory: null,
echo: true,
macineName: null,
};
return dockerCommand("info", options).then(function (data) {
//console.log("data", data);
//console.log("data.object", data.object);
t.ok(data);
t.ok(data.object.server_version);
});
});
it('info', () => {
const options = new index_1.Options(undefined, undefined, true, undefined, undefined);
return (0, index_2.dockerCommand)('info', options).then(function (data) {
// console.log('data', data);
// console.log('data.object', data.object);
expect(data).toBeDefined();
});
test("docker-cli-js", (t) => {
t.test("info", (t) => {
const docker = new index_1.Docker();
return docker.command("info").then(function (data) {
console.log(data);
t.ok(data);
t.ok(data.object.server_version);
});
});
it('build', () => {
const options = new index_1.Options(undefined, path.join(__dirname, '..', 'test', 'nginx'), true, undefined, undefined);
t.test("build", (t) => {
const options = new index_1.Options(
/* machineName */ undefined,
/* currentWorkingDirectory */ path.join(__dirname, "..", "test", "nginx"));
const docker = new index_1.Docker(options);
return docker.command('build -t nginximg .').then(function (data) {
//console.log('data = ', data);
expect(data.success).toBeTruthy();
return docker.command("build -t nginximg .").then(function (data) {
console.log("data = ", data);
t.ok(data);
t.ok(data.success);
});
});
it('run', () => {
const options = new index_1.Options(undefined, undefined, false, undefined, undefined);
const docker = new index_1.Docker(options);
return docker.command('run -d nginximg').then(function (data) {
//console.log('data = ', data);
expect(data.containerId).toBeTruthy();
t.test("run", (t) => {
const docker = new index_1.Docker();
return docker.command("run --name nginxcont -d -p 80:80 nginximg").then(function (data) {
console.log("data = ", data);
t.ok(data.containerId);
});
});
// it('info', () => {
// const result = true;
// expect(result).toBeTruthy();
// });
// it('info', () => {
// const result = true;
// expect(result).toBeTruthy();
// });
// it('info', () => {
// const result = true;
// expect(result).toBeTruthy();
// });
// it('info', () => {
// const result = true;
// expect(result).toBeTruthy();
// });
// it('info', () => {
// const result = true;
// expect(result).toBeTruthy();
// });
// it('info', () => {
// const result = true;
// expect(result).toBeTruthy();
// });
t.test("ps", (t) => {
const docker = new index_1.Docker();
return docker.command("ps").then(function (data) {
console.log("data = ", data);
t.ok(data.containerList);
});
});
t.test("images", (t) => {
const docker = new index_1.Docker();
return docker.command("images").then(function (data) {
console.log("data = ", data);
t.ok(data.images);
});
});
t.test("network ls", (t) => {
const docker = new index_1.Docker();
return docker.command("network ls").then(function (data) {
console.log("data = ", data);
t.ok(data.network);
});
});
t.test("inspect", (t) => {
const docker = new index_1.Docker();
return docker.command("inspect nginxcont").then(function (data) {
console.log("data = ", data);
t.ok(data.object);
});
});
t.test("search", (t) => {
const docker = new index_1.Docker();
return docker.command("search nginxcont").then(function (data) {
console.log("data = ", data);
t.ok(data.images);
});
});
t.test("login success", (t) => {
const docker = new index_1.Docker();
// if this these credentials ever fail, they should be replaced with new valid ones.
return docker.command("login -u myusername -p mypassword").then(function (data) {
console.log("data = ", data);
// if login succeeds, these tests should pass
t.notOk(/error/.test(data));
t.ok(data.login);
}, function (data) {
console.log("data = ", data);
// if login is rejected, these tests should fail
t.notOk(/error/.test(data));
t.ok(data.login);
});
});
t.test("login fail", (t) => {
const docker = new index_1.Docker();
return docker.command("login -u fakeUsername -p fakePassword").then(function (data) {
console.log("data = ", data);
// if login succeeds, these tests should fail
t.ok(/error/.test(data));
t.notOk(data.login);
}, function (data) {
console.log("data = ", data);
// if login is rejected, these tests should pass
t.ok(/error/.test(data));
t.notOk(data.login);
});
});
t.test("pull latest", (t) => {
const docker = new index_1.Docker();
return docker.command("pull nginx").then(function (data) {
console.log("data = ", data);
t.ok(data.login);
});
});
t.test("pull specific tag", (t) => {
const docker = new index_1.Docker();
return docker.command("pull nginx:1.15.2").then(function (data) {
console.log("data = ", data);
t.ok(data.login);
});
});
t.test("pull intentionally failed, invalid image", (t) => {
const docker = new index_1.Docker();
return docker.command("pull nginx:999.999.999").then(function (data) {
console.log("data = ", data);
t.notOk(data.login);
}, function (rejected) {
console.log("rejected = ", rejected);
t.ok(/error/.test(rejected));
});
});
t.test("push intentionally failed, denied repo access", (t) => {
const docker = new index_1.Docker();
return docker.command("push nginx").then(function (data) {
console.log("data = ", data);
t.ok(data.login);
}, function (rejected) {
console.log("rejected = ", rejected);
t.ok(/error/.test(rejected));
});
});
t.test("push intentionally failed, local image does not exist", (t) => {
const docker = new index_1.Docker();
return docker.command("push dmarionertfulthestoncoag").then(function (data) {
console.log("data = ", data);
t.ok(data.login);
}, function (rejected) {
console.log("rejected = ", rejected);
t.ok(/error/.test(rejected));
});
});
});
// t.test('images', (t) => {
// const docker = new Docker();
// return docker.command('images').then(function(data) {
// console.log('data = ', data);
// t.ok(data.images);
// });
// });
// t.test('network ls', (t) => {
// const docker = new Docker();
// return docker.command('network ls').then(function(data) {
// console.log('data = ', data);
// t.ok(data.network);
// });
// });
// t.test('inspect', (t) => {
// const docker = new Docker();
// return docker.command('inspect nginxcont').then(function(data) {
// console.log('data = ', data);
// t.ok(data.object);
// });
// });
// t.test('search', (t) => {
// const docker = new Docker();
// return docker.command('search nginxcont').then(function(data) {
// console.log('data = ', data);
// t.ok(data.images);
// });
// });
// t.test('login success', (t) => {
// const docker = new Docker();
// // if this these credentials ever fail, they should be replaced with new valid ones.
// return docker.command('login -u myusername -p mypassword').then(function(data) {
// console.log('data = ', data);
// // if login succeeds, these tests should pass
// t.notOk(/error/.test(data));
// t.ok(data.login);
// }, function(data) {
// console.log('data = ', data);
// // if login is rejected, these tests should fail
// t.notOk(/error/.test(data));
// t.ok(data.login);
// });
// });
// t.test('login fail', (t) => {
// const docker = new Docker();
// return docker.command('login -u fakeUsername -p fakePassword').then(function(data) {
// console.log('data = ', data);
// // if login succeeds, these tests should fail
// t.ok(/error/.test(data));
// t.notOk(data.login);
// }, function(data) {
// console.log('data = ', data);
// // if login is rejected, these tests should pass
// t.ok(/error/.test(data));
// t.notOk(data.login);
// });
// });
// t.test('pull latest', (t) => {
// const docker = new Docker();
// return docker.command('pull nginx').then(function(data) {
// console.log('data = ', data);
// t.ok(data.login);
// });
// });
// t.test('pull specific tag', (t) => {
// const docker = new Docker();
// return docker.command('pull nginx:1.15.2').then(function(data) {
// console.log('data = ', data);
// t.ok(data.login);
// });
// });
// t.test('pull intentionally failed, invalid image', (t) => {
// const docker = new Docker();
// return docker.command('pull nginx:999.999.999').then(function(data) {
// console.log('data = ', data);
// t.notOk(data.login);
// }, function(rejected) {
// console.log('rejected = ', rejected);
// t.ok(/error/.test(rejected));
// });
// });
// t.test('push intentionally failed, denied repo access', (t) => {
// const docker = new Docker();
// return docker.command('push nginx').then(function(data) {
// console.log('data = ', data);
// t.ok(data.login);
// }, function(rejected) {
// console.log('rejected = ', rejected);
// t.ok(/error/.test(rejected));
// });
// });
// t.test('push intentionally failed, local image does not exist', (t) => {
// const docker = new Docker();
// return docker.command('push dmarionertfulthestoncoag').then(function(data) {
// console.log('data = ', data);
// t.ok(data.login);
// }, function(rejected) {
// console.log('rejected = ', rejected);
// t.ok(/error/.test(rejected));
// });
// });
//});
//# sourceMappingURL=index.spec.js.map
{
"name": "docker-cli-js",
"version": "2.9.0",
"version": "2.10.0",
"description": "A node.js wrapper for the docker command line interface CLI",

@@ -11,6 +11,7 @@ "main": "dist/index.js",

"scripts": {
"lint": "eslint . --fix --ext .ts",
"lint-fix": "eslint . --fix --ext .ts",
"build": "npx del-cli dist/ && tsc",
"test": "jest",
"lint": "tslint --project .",
"lintfix": "tslint --project . --fix",
"build": "rimraf dist/ && tsc",
"test-spec": "ts-node node_modules/blue-tape/bin/blue-tape.js \"src/**/*.spec.ts\" | tap-diff",
"test": "npm run lint && npm run build && npm run test-spec",
"prepublish": "npm run lint && npm run build && rimraf \"dist/**/*.spec.*\""

@@ -33,21 +34,10 @@ },

"devDependencies": {
"@types/jest": "^26.0.20",
"@types/lodash": "^4.14.168",
"@types/lodash.snakecase": "^4.1.6",
"@types/moment-duration-format": "^2.2.3",
"@types/node": "^14.14.25",
"@types/parse-json": "^4.0.0",
"@types/shelljs": "^0.8.9",
"@types/tape": "^4.13.2",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"del-cli": "^3.0.1",
"eslint": "^7.27.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.23.3",
"jest": "^26.6.3",
"promise-delay": "^2.1.0",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
"@types/node": "10.9.1",
"@types/blue-tape": "0.1.32",
"blue-tape": "1.0.0",
"rimraf": "2.6.2",
"tap-diff": "0.1.1",
"ts-node": "7.0.1",
"tslint": "5.11.0",
"typescript": "3.3.4000"
},

@@ -54,0 +44,0 @@ "dependencies": {

@@ -39,7 +39,5 @@ # docker-cli-js

const options = {
machineName: undefined, // uses local docker
currentWorkingDirectory: undefined, // uses current working directory
echo: true, // echo command output to stdout/stderr
env: undefined,
stdin: undefined,
machineName: null, // uses local docker
currentWorkingDirectory: null, // uses current working directory
echo: true, // echo command output to stdout/stderr
};

@@ -53,9 +51,7 @@

```js
const options = {
machineName: undefined, // uses local docker
currentWorkingDirectory: undefined, // uses current working directory
echo: true, // echo command output to stdout/stderr
env: undefined,
stdin: undefined,
};
var options = new DockerOptions(
/* machinename */ 'aws_machine01',
/* currentWorkingDirectory */ 'nginx',
/* echo */ true,
);

@@ -65,3 +61,3 @@ var docker = new Docker(options);

docker.command('build -t nginximg .').then(function (data) {
console.log('data = ', data);
console.log('data = ', data);
})

@@ -142,3 +138,3 @@

```js
var docker = new Docker();
var docker = new Docker();

@@ -157,9 +153,8 @@ docker.command('info', function (err, data) {

const options = new Options(undefined,
path.join(__dirname, '..', 'test', 'nginx'),
true,
undefined,
undefined);
const options = new Options(
/* machineName */ null,
/* currentWorkingDirectory */ path.join(__dirname, '..', 'test', 'nginx'),
/* echo*/ true,
);
let docker = new Docker(options);

@@ -166,0 +161,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc