@alertlogic/al-collector-js 3.0.7 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Makefile CHANGED
@@ -20,6 +20,7 @@ clean:
20
20
  rm -rf node_modules
21
21
  rm -f package-lock.json
22
22
  rm -f test/report.xml
23
+ rm -f *.report.xml
23
24
  rm -rf ./coverage/
24
25
 
25
26
  publish:
package/al_log.js CHANGED
@@ -185,7 +185,7 @@ function buildHostmeta({hostId, hostmetaElems}, callback) {
185
185
  let meta = {
186
186
  hostUuid : hostId,
187
187
  data : hostmetaData,
188
- dataChecksum : new Buffer('')
188
+ dataChecksum : Buffer.from('')
189
189
  };
190
190
  let sha = crypto.createHash('sha1');
191
191
  let hashPayload = hostmetaType.encode(meta).finish();
package/al_servicec.js CHANGED
@@ -34,7 +34,7 @@ class AimsC extends m_alUtil.RestServiceClient {
34
34
  super(apiEndpoint, retryOptions);
35
35
  this._cid = cid;
36
36
  this._aimsAuth = {
37
- user: aimsCreds.access_key_id,
37
+ username: aimsCreds.access_key_id,
38
38
  password: aimsCreds.secret_key
39
39
  };
40
40
  var cache = cacheDir ? cacheDir : DEFAULT_CACHE_DIR;
package/al_util.js CHANGED
@@ -7,15 +7,15 @@
7
7
  * @end
8
8
  * -----------------------------------------------------------------------------
9
9
  */
10
-
11
- const rp = require('request-promise-native');
10
+ const axios = require('axios');
12
11
  const retry = require('retry');
12
+ const http = require('http');
13
+ const https = require('https');
13
14
 
14
15
  let MAX_CONNS_PER_SERVICE = 128;
15
16
 
16
17
  /**
17
18
  * @default Refer to https://www.npmjs.com/package/retry
18
- * set maxRetryTime to 180seconds(3min) to avoid lambda timeout.
19
19
  */
20
20
  let DEFAULT_RETRY = {
21
21
  // Default values
@@ -24,18 +24,25 @@ let DEFAULT_RETRY = {
24
24
  minTimeout: 300,
25
25
  retries: 2,
26
26
  maxTimeout: 10000,
27
- maxRetryTime: 180000 // Maximum time to spend retrying in milliseconds.
27
+ maxRetryTime: 180000
28
+ };
29
+
30
+ /**
31
+ * @default Refer to httpAgent and httpAgents axios
32
+ */
33
+ let DEFAULT_HTTP_HTTPS_AGENT_CONFIG = {
34
+ keepAlive: true,
35
+ maxSockets: MAX_CONNS_PER_SERVICE, // Maximum number of sockets to open
28
36
  };
29
37
 
38
+
30
39
  /**
31
- * @function Default retry callback.
32
- * It doesn't retry 2XX, 3XX and 4XX.
40
+ * @function Default retry callback.
41
+ * It doesn't retry 2XX, 3XX, and 4XX.
33
42
  * Keeps retrying 5XX HTTP responses and any system level errors
34
43
  **/
35
- var defaultRetryCb = function(err){
36
- if (err &&
37
- (err.statusCode >= 500 ||
38
- (err.error && err.error.errno))) {
44
+ var defaultRetryCb = function (err) {
45
+ if (err && (err.status >= 500) || (err.response && err.response.status >= 500) || (err.errno)) {
39
46
  return true;
40
47
  } else {
41
48
  return false;
@@ -47,8 +54,7 @@ var defaultRetryCb = function(err){
47
54
  * Rest client.
48
55
  *
49
56
  * @constructor
50
- * @param {string} endpoint - hostname/address to sent HTTPS
51
- * requests to.
57
+ * @param {string} endpoint - hostname/address to sent HTTPS requests to.
52
58
  *
53
59
  */
54
60
  class RestServiceClient {
@@ -56,9 +62,6 @@ class RestServiceClient {
56
62
  'use strict';
57
63
  this._host = endpoint;
58
64
  this._url = 'https://' + endpoint;
59
- this._pool = {
60
- maxSockets: MAX_CONNS_PER_SERVICE
61
- };
62
65
  if (retryOptions) {
63
66
  this._retryCb = retryOptions.retryCb ? retryOptions.retryCb : defaultRetryCb;
64
67
  delete retryOptions.retryCb;
@@ -74,40 +77,44 @@ class RestServiceClient {
74
77
  const defaultOptions = {
75
78
  method: method,
76
79
  url: this._url + path,
77
- json: true,
78
80
  headers: {},
79
- pool: this._pool
81
+ json: true,
82
+ httpAgent: new http.Agent(DEFAULT_HTTP_HTTPS_AGENT_CONFIG),
83
+ httpsAgent: new https.Agent(DEFAULT_HTTP_HTTPS_AGENT_CONFIG)
80
84
  };
81
85
  const options = Object.assign({}, defaultOptions, extra);
82
86
  const defaultHeaders = {
83
87
  'Accept': 'application/json'
84
88
  };
85
- Object.assign(options.headers,
86
- defaultHeaders,
87
- extra.headers ? extra.headers : {});
89
+ if (!options.data || options.body) {
90
+ options.data = options.body;
91
+ options.body = undefined;
92
+ }
93
+ Object.assign(options.headers, defaultHeaders, extra.headers ? extra.headers : {});
88
94
  return options;
89
95
  }
96
+
90
97
  request(method, path, extraOptions) {
91
98
  'use strict';
92
99
  const options = this._initRequestOptions(method, path, extraOptions);
93
100
  const retryOptions = this._retryOptions;
94
101
  var retryCb = this._retryCb;
95
-
102
+
96
103
  var operation = retry.operation(retryOptions);
97
-
98
- return new Promise(function(resolve, reject) {
99
- operation.attempt(function(currentAttempt) {
100
- rp(options)
101
- .then( resp => {
102
- // We need opertaion.retry here as we want to check if
104
+
105
+ return new Promise(function (resolve, reject) {
106
+ operation.attempt(function (currentAttempt) {
107
+ axios(options)
108
+ .then(resp => {
109
+ // We need operation.retry here as we want to check if
103
110
  // the maximum amount of retries has been reached
104
111
  if (retryCb(resp) && operation.retry('retry')) {
105
112
  return;
106
113
  } else {
107
- return resolve(resp);
114
+ return resolve(resp.data);
108
115
  }
109
116
  })
110
- .catch( err =>{
117
+ .catch(err => {
111
118
  if (retryCb(err) && operation.retry(err)) {
112
119
  return;
113
120
  } else {
@@ -117,21 +124,27 @@ class RestServiceClient {
117
124
  });
118
125
  });
119
126
  }
127
+
120
128
  post(path, extraOptions) {
121
129
  return this.request('POST', path, extraOptions);
122
130
  }
131
+
123
132
  get(path, extraOptions) {
124
133
  return this.request('GET', path, extraOptions);
125
134
  }
135
+
126
136
  deleteRequest(path, extraOptions) {
127
137
  return this.request('DELETE', path, extraOptions);
128
138
  }
139
+
129
140
  put(path, extraOptions) {
130
141
  return this.request('PUT', path, extraOptions);
131
142
  }
143
+
132
144
  get host() {
133
145
  return this._host;
134
146
  }
147
+
135
148
  get url() {
136
149
  return this._url;
137
150
  }
@@ -140,4 +153,3 @@ class RestServiceClient {
140
153
  module.exports = {
141
154
  RestServiceClient: RestServiceClient
142
155
  };
143
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alertlogic/al-collector-js",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
4
  "license": "MIT",
5
5
  "description": "Alert Logic Collector Common Library",
6
6
  "repository": {
@@ -20,26 +20,25 @@
20
20
  }
21
21
  ],
22
22
  "devDependencies": {
23
- "jshint": "^2.9.5",
23
+ "jshint": "^2.13.6",
24
24
  "mocha": "^10.2.0",
25
- "mocha-jenkins-reporter": "^0.4.2",
26
- "nock": "^13.2.9",
25
+ "mocha-jenkins-reporter": "^0.4.8",
26
+ "nock": "^13.3.2",
27
27
  "nyc": "^15.1.0",
28
- "rewire": "^5.0.0",
29
- "sinon": "^15.0.1",
30
- "timekeeper": "^2.2.0"
28
+ "rewire": "^6.0.0",
29
+ "sinon": "^15.2.0",
30
+ "timekeeper": "^2.3.1"
31
31
  },
32
32
  "dependencies": {
33
- "async": "^3.2.4",
34
- "debug": "^4.3.4",
33
+ "async": "3.2.4",
34
+ "axios": "^1.4.0",
35
+ "debug": "4.3.4",
35
36
  "lodash.clonedeep": "^4.5.0",
36
37
  "lodash.filter": "^4.6.0",
37
38
  "lodash.remove": "^4.7.0",
38
- "moment": "^2.29.4",
39
- "protobufjs": "^7.1.2",
40
- "request": "^2.88.2",
41
- "request-promise-native": "^1.0.9",
42
- "retry": "^0.13.1"
39
+ "moment": "2.29.4",
40
+ "protobufjs": "^7.2.4",
41
+ "retry": "0.13.1"
43
42
  },
44
43
  "author": "Alert Logic Inc."
45
44
  }
package/test/al_mock.js CHANGED
@@ -16,7 +16,7 @@ const AIMS_CREDS = {
16
16
 
17
17
  const AIMS_AUTH = {
18
18
  auth : {
19
- user: AIMS_CREDS.access_key_id,
19
+ username: AIMS_CREDS.access_key_id,
20
20
  password: AIMS_CREDS.secret_key
21
21
  }
22
22
  };
@@ -147,7 +147,7 @@ describe('Unit Tests', function() {
147
147
 
148
148
  restC.post(TEST_PATH, {
149
149
  headers: { 'some_header': 'some_value' },
150
- body: TEST_BODY
150
+ data: TEST_BODY
151
151
  })
152
152
  .catch(err => {
153
153
  console.log(`err ${err}`);
@@ -129,10 +129,10 @@ describe('Common parse functions unit tests.', function() {
129
129
  done();
130
130
  });
131
131
 
132
- it('Wrong timestamp input', function(done) {
133
- var privParseTs = parseWire.__get__('parseTs');
134
- assert.deepEqual(privParseTs('foo'), {sec: 1234567, usec: null});
135
-
132
+ it('Wrong timestamp input', function (done) {
133
+ let parseWire1 = rewire('../parse');
134
+ var privParseTs = parseWire1.__get__('parseTs');
135
+ assert.deepEqual(privParseTs('foo'), { sec: 1234567, usec: null });
136
136
  done();
137
137
  });
138
138
 
@@ -80,7 +80,7 @@ describe('HTTP request retry tests', function() {
80
80
  var endpointsC = new EndpointsC(m_alMock.AL_API, aimsc, 'cwe');
81
81
 
82
82
  endpointsC.getEndpoint('azcollect', 'default').then( resp => {
83
- assert.equal(resp, undefined);
83
+ assert.equal(resp, '');
84
84
  done();
85
85
  });
86
86
  });
@@ -135,7 +135,8 @@ describe('HTTP request retry tests', function() {
135
135
  return done();
136
136
  })
137
137
  .catch(err => {
138
- assert.equal(err.statusCode, 401);
138
+ assert.equal(err.code , 'ERR_BAD_REQUEST');
139
+ assert.equal(err.response.status , 401);
139
140
  return done();
140
141
  });
141
142
  });
@@ -148,7 +149,7 @@ describe('HTTP request retry tests', function() {
148
149
  .post('/aims/v1/authenticate')
149
150
  .reply(201, m_alMock.AIMS_RESPONSE_200);
150
151
  var customRetry = function(resp) {
151
- if (resp.retryCode === customRetryCode) {
152
+ if (resp.data.retryCode === customRetryCode) {
152
153
  return true;
153
154
  } else {
154
155
  return false;
@@ -178,7 +179,7 @@ describe('HTTP request retry tests', function() {
178
179
  .post('/aims/v1/authenticate')
179
180
  .reply(201, m_alMock.AIMS_RESPONSE_200);
180
181
  var customRetry = function(resp) {
181
- if (resp.error.customError === customRetryCode) {
182
+ if (resp.customError === customRetryCode) {
182
183
  return false;
183
184
  } else {
184
185
  return true;
@@ -199,7 +200,7 @@ describe('HTTP request retry tests', function() {
199
200
  return done();
200
201
  })
201
202
  .catch(err =>{
202
- assert.equal(err.error.customError, customRetryCode);
203
+ assert.equal(err.customError, customRetryCode);
203
204
  return done();
204
205
  });
205
206
  });
@@ -222,7 +223,7 @@ describe('HTTP request retry tests', function() {
222
223
  m_alMock.AL_API, m_alMock.AIMS_CREDS, '/tmp', retryOptions);
223
224
  aimsc.authenticate()
224
225
  .catch(err => {
225
- assert.equal(err.statusCode, 500);
226
+ assert.equal(err.response.status, 500);
226
227
  var nowMoment = moment();
227
228
  const elapsedTime = nowMoment.diff(startTime, 'milliseconds');
228
229
  assert.ok(