Skip to content

Commit

Permalink
add apiKeyManager service
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed Jul 26, 2017
1 parent 2e695de commit c5829ef
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
11 changes: 0 additions & 11 deletions api-keys-sample.js

This file was deleted.

28 changes: 28 additions & 0 deletions web/apiKeyManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs');
const _ = require('lodash')

const apiKeysFile = '../api-keys.js';

const prefix = `//DO NOT SHARE THIS FILE WITH ANYONE
module.exports = `;

// on init:
const noApiKeysFile = !fs.existsSync(apiKeysFile);

if(noApiKeysFile) {
let content = prefix + '{}';
fs.writeFileSync(apiKeysFile, content);
}

const apiKeys = require(apiKeysFile);

module.exports = {
get: () => _.keys(apiKeys),

// note: overwrites if exists
add: (exchange, props) => {
apiKeys[exchange] = props;
fs.writeFileSync(apiKeysFile, prefix + JSON.stringify(apiKeys));
}

}
15 changes: 15 additions & 0 deletions web/routes/apiKeys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const manager = require('../apiKeyManager');

module.exports = {
get: function *() {
this.body = manager.get();
},
add: function *() {
const content = this.request.body;

manager.add(content.exchange, content.values);

this.body = 'ok';
}
}

0 comments on commit c5829ef

Please sign in to comment.