-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathdruid-request-decorator.js
More file actions
35 lines (28 loc) · 1.25 KB
/
druid-request-decorator.js
File metadata and controls
35 lines (28 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
exports.version = 1;
// logger - is just a collection of functions that you should use instead of console to have your logs included with the Pivot logs
// params - is an object with the following keys:
// * options: the decoratorOptions part of the cluster object
// * cluster: Cluster - the cluster object
exports.druidRequestDecoratorFactory = function (logger, params) {
var options = params.options;
var myUsername = options.myUsername; // pretend we store the username and password
var myPassword = options.myPassword; // in the config
if (!myUsername) throw new Error('must have username');
if (!myPassword) throw new Error('must have password');
logger.log("Decorator init for username: " + myUsername);
var auth = "Basic " + Buffer(myUsername + ":" + myPassword).toString('base64');
// decoratorRequest: DecoratorRequest - is an object that has the following keys:
// * method: string - the method that is used (POST or GET)
// * url: string -
// * query: Druid.Query -
return function (decoratorRequest) {
var decoration = {
headers: {
"Authorization": auth,
"X-I-Like": "Koalas"
}
};
// This can also be async if instead of a value of a promise is returned.
return decoration;
};
};