You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP →
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keystok - npm Package Compare versions

Comparing version

to
1.0.1

@@ -13,2 +13,3 @@ /**

var path = require('path');
var fs = require('fs');
var decryptKeys = require('./decrypt');

@@ -18,4 +19,4 @@ var apiRequest = require('./api');

DEFAULT_API_HOST = 'https://api.keystok.com';
DEFAULT_AUTH_HOST = 'https://keystok.com';
var DEFAULT_API_HOST = 'https://api.keystok.com';
var DEFAULT_AUTH_HOST = 'https://keystok.com';

@@ -27,6 +28,6 @@ function keystok(accessTokenOrOptions) {

// Support either a simple access token or an options object.
if (typeof accessTokenOrOptions == 'string') {
if (typeof accessTokenOrOptions === 'string') {
options.accessToken = accessTokenOrOptions;
} else {
options = accessTokenOrOptions;
options = accessTokenOrOptions || {};
}

@@ -38,3 +39,3 @@

}
if (options.apiHost.slice(0, 4) != 'http') {
if (options.apiHost.slice(0, 4) !== 'http') {
options.apiHost = 'https://' + options.apiHost;

@@ -45,3 +46,3 @@ }

}
if (options.authHost.slice(0, 4) != 'http') {
if (options.authHost.slice(0, 4) !== 'http') {
options.authHost = 'https://' + options.authHost;

@@ -53,7 +54,7 @@ }

}
if (typeof options.cache == 'undefined') {
if (typeof options.cache === 'undefined') {
// Enable cache by default
options.cache = true;
}
if (typeof options.cacheDir == 'undefined') {
if (typeof options.cacheDir === 'undefined') {
// Put cache files in /tmp/keystok by default

@@ -63,2 +64,14 @@ options.cacheDir = path.join(os.tmpdir(), 'keystok');

// Try to read access token from ~/.keystok/access_token if not specified as an argument
if (!options.accessToken) {
try {
options.accessToken = fs.readFileSync(path.join(process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE, '.keystok', 'access_token'), {encoding:'utf8'}).trim();
} catch (err) {
// Ignore error
}
}
if (!options.accessToken) {
throw new Error('No Keystok access token specified');
}
if (options.cache) {

@@ -65,0 +78,0 @@ // Create the cache manager

{
"name": "keystok",
"version": "1.0.0",
"version": "1.0.1",
"description": "Keystok Client",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,3 +7,3 @@ # Keystok Node.js Client Library

npm install git+https://git@bitbucket.org/keystok/keystok-client-node.git
npm install keystok

@@ -10,0 +10,0 @@ ## Retrieving a single key

var assert = require('chai').assert;
var path = require('path');
var os = require('os');
var fs = require('fs');
var KEYSTOK_TOKEN = require('./token');

@@ -18,2 +21,30 @@ var server = require('./server');

it('should not instantiate without access token', function(done) {
var home = process.env.HOME;
process.env.HOME = path.join(os.tmpdir(), 'temp-keystok-home');
assert.throw(function() {
var keystok = require('../lib/keystok')();
assert.isNotNull(keystok);
}, Error);
process.env.HOME = home;
done();
});
it('should instantiate with file access token', function(done) {
var home = process.env.HOME;
process.env.HOME = path.join(os.tmpdir(), 'temp-keystok-home');
var tokendir = path.join(process.env.HOME, '.keystok');
var tokenfile = path.join(tokendir, 'access_token');
try { fs.mkdirSync(process.env.HOME); } catch (err) {}
try { fs.mkdirSync(tokendir); } catch (err) {}
fs.writeFileSync(tokenfile, KEYSTOK_TOKEN);
var keystok = require('../lib/keystok')();
assert.isNotNull(keystok);
fs.unlinkSync(tokenfile);
fs.rmdirSync(tokendir);
fs.rmdirSync(process.env.HOME);
process.env.HOME = home;
done();
});
it('should retrieve a single key', function(done) {

@@ -20,0 +51,0 @@ var keystok = require('../lib/keystok')(this.server.options);