Skip to content

Commit

Permalink
uses process.env.ES_INDEX for ES index. #129 & #64
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Apr 13, 2015
1 parent 4dcfcea commit b9e598b
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Run the following command to set up your local machine:
```sh
export ES_HOST="127.0.0.1"
export ES_PORT=9200
export ES_INDEX=dwyl
export JWT_SECRET="NeverShareYourSecret"

```
See [**.travis.yml**](https://github.com/ideaq/time/blob/master/.travis.yml)
for [Continuous integration](http://en.wikipedia.org/wiki/Continuous_integration) settings.
Expand Down
2 changes: 1 addition & 1 deletion api/handlers/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var ES = require('esta');

module.exports = function logout(req, reply) {
var session = {
index : "time",
index : process.env.ES_INDEX,
type : "session",
id : req.auth.credentials.jti,
ended : new Date().toISOString()
Expand Down
2 changes: 1 addition & 1 deletion api/handlers/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var transfer = require('../lib/transfer_anon_to_registered.js');
module.exports = function handler(req, reply) {
var personid = aguid(req.payload.email)
var person = {
index: "people",
index: process.env.ES_INDEX,
type: "person",
id: personid,
email: req.payload.email
Expand Down
2 changes: 1 addition & 1 deletion api/handlers/timer_find.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var file = dir + __filename.replace(__dirname, '') + " -> ";

module.exports = function(req, reply) {
var record = {
index: "time",
index: process.env.ES_INDEX,
type: "timer",
id: req.params.id
}
Expand Down
2 changes: 1 addition & 1 deletion api/handlers/timer_find_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function timer_find_all(req, reply, statusCode) {
statusCode = 404;
}
var query = {
"index": "time",
"index": process.env.ES_INDEX,
"type": "timer",
"field": "person",
"text": req.auth.credentials.person.toString() // using issuer as the person
Expand Down
2 changes: 1 addition & 1 deletion api/handlers/timer_start.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Hoek = require('hoek');
module.exports = function(req, reply) {
var decoded = req.auth.credentials; //JWT.verify(req.headers.authorization, process.env.JWT_SECRET);
var timer = {
index: "time",
index: process.env.ES_INDEX,
type: "timer",
person: decoded.person,
session: decoded.jti, // session id from JWT
Expand Down
2 changes: 1 addition & 1 deletion api/handlers/timer_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var Hoek = require('hoek');
module.exports = function(req, reply) {
var decoded = req.auth.credentials;
var timer = {
index: "time",
index: process.env.ES_INDEX,
type: "timer",
id: req.payload.id
}
Expand Down
2 changes: 1 addition & 1 deletion api/lib/auth_basic_validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var aguid = require('aguid'); // https://github.com/ideaq/aguid
module.exports = function validate (email, password, callback) {

var person = {
index: "people",
index: process.env.ES_INDEX,
type: "person",
id: aguid(email)
}
Expand Down
2 changes: 1 addition & 1 deletion api/lib/auth_jwt_sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function sign(request, callback) {
var token = JWT.sign(payload, process.env.JWT_SECRET); // http://git.io/xPBn

var session = { // set up session record for inserting into ES
index: "time",
index: process.env.ES_INDEX,
type: "session",
id : payload.jti,
person: payload.person,
Expand Down
2 changes: 1 addition & 1 deletion api/lib/auth_jwt_validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var ES = require('esta');
var validateFunc = function (decoded, request, callback) {

var session = {
index : "time",
index : process.env.ES_INDEX,
type : "session",
id : decoded.jti // use SESSION ID as key for sessions
} // jti? >> http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html#jtiDef
Expand Down
8 changes: 4 additions & 4 deletions api/lib/transfer_anon_to_registered.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ module.exports = function(req, reply) {
Hoek.assert(!err, 'Missing JWT!'); // JWT fails

var session = {
index : "time",
index : process.env.ES_INDEX,
type : "session",
id : decoded.jti,
person: personid
}
var session_copy = {
index : "time",
index : process.env.ES_INDEX,
type : "session",
id : decoded.jti,
person: personid
Expand All @@ -46,7 +46,7 @@ module.exports = function(req, reply) {
ES.READ(session, function(ses) {
// console.log("Anon SESSION :",ses);
var session = ses._source;
session.index = "time";
session.index = process.env.ES_INDEX;
session.type = "session";
session.person = personid;
session.id = decoded.jti;
Expand All @@ -57,7 +57,7 @@ module.exports = function(req, reply) {
// lookup all the records that were created with the anon session
// before the person decided to login...
var query = {
"index": "time",
"index": process.env.ES_INDEX,
"type": "timer",
"field": "session",
"text": decoded.jti
Expand Down
6 changes: 3 additions & 3 deletions api/test/_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var ES = require('esta');
var test = require('tape');

var record = {
index: "time",
index: process.env.ES_INDEX,
type: "timer",
id: Math.floor(Math.random() * (1000000)),
start: new Date().toISOString()
Expand Down Expand Up @@ -37,7 +37,7 @@ test("CREATE & READ a record", function(t) {

test("UPDATE a record", function(t) {
var record = {
index: "time",
index: process.env.ES_INDEX,
type: "timer",
id: Math.floor(Math.random() * (1000000)),
start: new Date().getTime()
Expand All @@ -63,7 +63,7 @@ test("UPDATE a record", function(t) {
var aguid = require('aguid');

var session = {
index: "time",
index: process.env.ES_INDEX,
type: "session",
id: aguid(),
start: new Date().toISOString(),
Expand Down
Empty file removed api/test/debug.js
Empty file.

0 comments on commit b9e598b

Please sign in to comment.