Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,29 @@ docker.command('search nginxcont').then(function (data) {
// }
```

* docker login

```js
docker.command('login -u myusername -p mypassword').then(function (data) {
console.log('data = ', data);
// Successful login
}, function (rejected) {
console.log('rejected = ', rejected);
// Failed login
});

// data = { command: 'docker login -u myusername -p mypassword ',
// raw: 'Login Succeeded\n',
// login: 'Login Succeeded' }

// rejected = error: 'Error: Command failed: docker login -u fakeUsername -p fakePassword
// WARNING! Using --password via the CLI is insecure. Use --password-stdin.
// Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password
// ' stdout = '' stderr = 'WARNING! Using --password via the CLI is insecure. Use --password-stdin.
// Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password
```


## License

MIT
Expand Down
39 changes: 39 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,43 @@ test('docker-cli-js', t => {
});
});

t.test('login success', t => {

let 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 => {

let 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);
});
});

});
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ const extractResult = function (result: any) {

resultp.images = cliTable2Json(lines);

return resultp;
},
},
{
re: / login /,
run: function (resultp: any) {
resultp.login = resultp.raw.trim();

return resultp;
},
},
Expand Down