ganomede-helpers
Helper modules shared by ganomede microservices
Last updated 3 years ago by jchoelt .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ganomede-helpers 
SYNC missed versions from official npm registry.

Ganomede Helpers

Install

Install with npm install --save ganomede-helpers

Usage

var helpers = require("ganomede-helpers");

helpers.restify.middlewares.authdb

Simplifies the integration of restify servers with authdb. Will check req.params.authToken agains passed in authdb client and fill out req.params.user with result. Replies with HTTP 400 in case of missing token; or 401 in case of error or missing account.

create: function(options)

Options:

  • authdbClient [required]: a authdb client as created using the authdb library
  • secret: allows "spoofing" req.params.user in case authToken matches ${secret}.${username} pattern. Will skip validating token and run following instead:
 req.params.user = {
   _secret: true
   username: spoofUsername // second part of token
 }
  • log: a bunyan style logger object

Returns a restify middleware function. This function requires authToken as a request parameter and fills the virtual user query parameter with the full user account details.

example

authMW = helpers.restify.middlewares.create({
  authdbClient: myClient
});
app.get "/auth/:authToken/games", authMW, getGames

helpers.links.ServiceEnv

Conveniant access to service links environment variables, compatible with docker links.

exists: function(name, port) : boolean

  • name: Name of the service to link
  • port: Default port of the service

Returns true if both the _PORT and _ADDR environemnt variables are set.

host: function(name, port) : string

  • name: Name of the service to link
  • port: Default port of the service

Returns the _ADDR environemnt variable, or 127.0.0.1

port: function(name, port) : int

  • name: Name of the service to link
  • port: Default port of the service

Returns the _PORT environemnt variable (casted to int), or the port parameter.

url: function(name, port) : string

generates and http:// URL using host and port.

example

var couch = myLib.connect(helpers.links.ServiceEnv.url('COUCH_GAMES', 5984))

helpers.Notification

Helper class allowing easier sending of notifications from ganomede services.

example

// Create notificaiton.
var notification = new helpers.Notification(
  // Fill in required fields:
  from: 'ganomede-service',
  to: 'username',
  type: 'sample-notification',
  // Fill in optional fields as neccessary:
  data: {sample: 'data'},
  secret: 'api-secret' // defaults to process.env.API_SECRET
);

// send() function bound to NOTIFICATION service address
// (set as ENV variable retrieved by ServiceEnv class).
var sendNotification = helpers.Notification.sendFn();

// Send notification.
sendNotification(notification, function (err, response) {
  // When notification is sent, it will have `id` and `timestamp`
  // set by notification service. For more details, see:
  // https://github.com/j3k0/ganomede-notifications#send-a-message-post.
});

Current Tags

  • 1.0.0-beta2                                ...           beta (4 years ago)
  • 1.0.6                                ...           latest (3 years ago)

22 Versions

  • 1.0.6                                ...           3 years ago
  • 1.0.5                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0-beta2                                ...           4 years ago
  • 0.6.0                                ...           4 years ago
  • 0.5.2                                ...           4 years ago
  • 0.5.1                                ...           4 years ago
  • 0.5.0                                ...           4 years ago
  • 0.4.2                                ...           5 years ago
  • 0.4.1                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.3                                ...           5 years ago
  • 0.3.2                                ...           5 years ago
  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (9)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |