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
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ linux-user
==========
Node module for Linux user and group control.

Use Node to manage Linux user easily. All APIs do what you think.
Use Node to manage Linux user easily. All APIs do what you think. Promise and
`async\await` out of the box. **Zero dependences!**

**The module must be running on Linux and as root user !**

Expand Down Expand Up @@ -81,12 +82,25 @@ linuxUser.getUsers(function (err, users) {

### Promises

This project works with promises right out of the box! Just grade the promise function
This project works with promises right out of the box! Just grab the promise
function.

```js
var linuxUser = require('linux-sys-user').promise;
var linuxUser = require('linux-sys-user').promise();
```

This will NodeJS's `util.promisify` by default. You can pass your own promisify
function like, like bluebird:

```js
var bluebird = require('bluebird');
var linuxUser = require('linux-sys-user').promise(bluebird.promisify);

```

** `bluebird` is NOT included with this package! ** If you are using a older
version of NodeJS( less then 8 ) you will need something like it.

This will work with `.then()`, `.catch()` and the `async`/`await` pattern.

```js
Expand Down Expand Up @@ -139,8 +153,8 @@ console.log(user);
missing.
```

* `expiredate` *String* The date on which the user account will be disabled.
The date is specified in the format `YYYY-MM-DD`..
* `expiredate` *String* The date on which the user account will be
disabled. The date is specified in the format `YYYY-MM-DD`..

```
If not specified, useradd will use the default expiry date
Expand Down Expand Up @@ -182,8 +196,8 @@ console.log(user);
* `selinux_user` *String* The SELinux user for the user's login.

```
The default is to leave this field blank, which causes the system to select
the default SELinux user.
The default is to leave this field blank, which causes the system to
select the default SELinux user.
```

* callback function(err, userInfo)
Expand Down
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict';

var bluebird= require('bluebird');
var lib = require('./lib/user');

lib.promise = (function(lib) {
var out = {};
// ensure process is running on linux
if(process.platform !== 'linux') {
throw new Error('linux-user must be running on Linux');
}

Object.keys(lib).forEach(function(key){
out[key] = bluebird.promisify(lib[key]);
});
// ensure process is running as root
if(!(process.getuid && process.getuid() === 0)) {
throw new Error('linux-user must be running as root user');
}

return out;
})(lib);
var lib = require('./lib/user');
lib.promises = require('./lib/promise')

module.exports = lib;
16 changes: 16 additions & 0 deletions lib/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

var promise = function(promise_fn) {
var lib = require('./user');

promise_fn = promise_fn || util.promisify;

var out = {};

Object.keys(lib).forEach(function(key){
out[key] = promise_fn(lib[key]);
});

return out;
}

module.exports = promise;
15 changes: 4 additions & 11 deletions lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@ var exec = require('child_process').exec;
var spawn = require('child_process').spawn;
var fs = require('fs');

if(process.platform !== 'linux') {
throw new Error('linux-user must be running on Linux');
}

// ensure process is running as root
if(!(process.getuid && process.getuid() === 0)) {
throw new Error('linux-user must be running as root user');
}

var validUsernameRegex = /^([a-z_][a-z0-9_-]{0,30})$/;

function validate (username) {
return validUsernameRegex.test(username);
return validUsernameRegex.test(username);
}

exports.validateUsername = validate;

var user_arg_map = {
shell: function(SHELL){
Expand Down Expand Up @@ -296,3 +286,6 @@ exports.addSSHtoUser = function (user, key, callback){
});
});
};


exports.validateUsername = validate;
7 changes: 1 addition & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linux-sys-user",
"version": "0.6.3",
"version": "1.0.0",
"description": "Node module for Linux user and group control.",
"author": [
{
Expand Down Expand Up @@ -43,7 +43,5 @@
"type": "git",
"url": "https://github.com/wmantly/linux-user.git"
},
"dependencies": {
"bluebird": "^3.5.5"
}
"dependencies": {}
}