-
Notifications
You must be signed in to change notification settings - Fork 6
/
util.js
59 lines (53 loc) · 1.88 KB
/
util.js
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* -----------------------------------------------------------------------------
* @copyright (C) 2018, Alert Logic, Inc
* @doc
*
* Helpers for collectors.
*
* @end
* -----------------------------------------------------------------------------
*/
const path = require('path');
/**
* @function
* returns Azure token cache filename.
*
* @param {String} [resource] - Azure resource URI.
* @param {String} [clientId] - (optional) Azure client id. Default is process.env.CUSTOMCONNSTR_APP_CLIENT_ID
* @param {String} [tenantId] - (optional) Azure AD id. Default is process.env.APP_TENANT_ID
*
* @return {String} - Azure token cache filename
*/
const getADCacheFilename = function (resource, clientId, tenantId) {
var cId = clientId ? clientId : process.env.CUSTOMCONNSTR_APP_CLIENT_ID;
var tId = tenantId ? tenantId : process.env.APP_TENANT_ID;
return path.join(process.env.TMP,
encodeURIComponent(cId) + '-' +
encodeURIComponent(tId) + '-' +
encodeURIComponent(resource) + '-token.tmp');
}
/**
* @function
* checks if expected key/value properties are present in Object
*
* @param {Object} obj - target JSON object where to check expected properties.
* @param {Object} expectedProps - JSON object that contains expected property keys and values.
*
* @return false - all expected key:value pairs are present in the object.
* | {Object} - the first unexpected key-value. The actual value is returned from the object.
*/
const verifyObjProps = function (obj, expectedProps) {
var expectedKeys = Object.keys(expectedProps);
for (let k of expectedKeys) {
if (obj[k] !== expectedProps[k]) {
var retObj = {};
retObj[k] = obj[k];
return retObj;
}
}
return false;
}
module.exports = {
getADCacheFilename: getADCacheFilename,
verifyObjProps: verifyObjProps
};