Skip to content
Open
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
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,30 @@ Example app.config.json (see also the included app.config.json file):
}
```

#### .netrc Auth Example

This example shows how to use the .netrc file for credentials.

Example app.config.json:

```javascript
{
"roots": {
"/Users/joe.developer/instance/records": {
"host": "some-instance.service-now.com"
}
},
"useNetrcAuth": true
}
```

Example ~/.netrc file:

```
machine some-instance.service-now.com
login admin
password hgdf723jdt72u28
```

## Advanced settings

Expand Down Expand Up @@ -278,6 +301,7 @@ preLoad | Bool: true / false | false | Creates local files that can be specified
ignoreList | Array of matches | `/[\/\\]\./` | Define what files are **not** tracked for changes. Defaults to ignore hidden files on any directory level (eg `.sync_data`). Usage details can be found on the [chokidar readme](https://github.com/paulmillr/chokidar#path-filtering).
ensureUniqueNames | Bool: true / false | false | If set to true then files will be post-fixed with the record sys_id to ensure all saved files have unique names. This supports records that have the same name on the same table. By default this is false to encourage more useful record names on the instance.
proxy | Object | not set | Required if stuck behind a proxy. <br />Eg. `"proxy": { `<br />`"host": "host.com",`<br />`"port": "3860"`<br />` }`
useNetrcAuth | Bool: true / false | false | If set to true, authentication information information will be retrieved from your ~/.netrc file. This provides a simple mechanism to keep credentials separate from your project configuration.<br />The .netrc file is a standard mechanism used by many command line utilites (e.g. curl, ftp, httpie, etc.) to store credentials in a controlled way.


#### Root specific options
Expand Down
24 changes: 22 additions & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require('colors');
var fs = require('fs');
var path = require('path');
var util = require('util');
var netrcConfig = require('./netrc_credentials');

// non documented function. Worry about that some other day. It won't go away soon because nodejs relies on it!
var extend = require('util')._extend;
Expand Down Expand Up @@ -76,6 +77,9 @@ function getConfig() {
var config = require(config_file);
config.debug = config.debug || false;

// Allow using the netrc auth instead of hard coded credentials (https://www.gnu.org/software/inetutils/manual/html_node/The-_002enetrc-file.html)
config.useNetrcAuth = config.useNetrcAuth || false;

assert.object(config.roots, 'roots');

var roots = Object.keys(config.roots);
Expand All @@ -89,9 +93,25 @@ function getConfig() {
validateRootFolder(root);
var host = config.roots[root];
assert.ok(host.host, 'Invalid root config. host missing.');
if (!host.auth) {

if (config.useNetrcAuth) {
assert.ok(netrcConfig.hasCredentials(host.host), 'Host is missing the .netrc credentials');

// Fetch the credentials from the .netrc file
var creds = netrcConfig.getCredentials(host.host);
host.user = creds.user;
host.pass = creds.pass;

// Encode the credentials the same way we always do, but don't persist them
config.roots[root] = encodeCredentials(host);
save = true;

// We don't want to save, because the config will dynamically come from the .netrc file
save = false;
} else {
if (!host.auth) {
config.roots[root] = encodeCredentials(host);
save = true;
}
}
});

Expand Down
21 changes: 21 additions & 0 deletions lib/netrc_credentials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var netrc = require('netrc');
var netrcConfig = netrc();

function getCredentials(hostname) {
var settings = netrcConfig[hostname] || {};

return {
user: settings['login'],
pass: settings['password']
};
}

function hasCredentials(hostname) {
var credentials = getCredentials(hostname);
return credentials.user != null && credentials.pass != null;
}

module.exports = {
getCredentials: getCredentials,
hasCredentials: hasCredentials
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"glob": "^6.0.0",
"minimist": "^1.1.1",
"moment": "^2.10.2",
"netrc": "^0.1.4",
"node-notifier": "^4.3.1",
"osx-notifier": "^0.2.1",
"@mishguru/restler": "https://github.com/mishguruorg/restler/tarball/master",
Expand Down