@f5devcentral/atg-storage
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -8,2 +8,6 @@ # Changelog | ||
## [1.3.2] - 2022-3-18 | ||
## Changed | ||
- Prevent persist from exiting early, when task is kicked off | ||
## [1.3.1] - 2022-3-11 | ||
@@ -10,0 +14,0 @@ ## Fixed |
{ | ||
"name": "@f5devcentral/atg-storage", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"author": "F5 Networks", | ||
@@ -28,3 +28,5 @@ "license": "Apache-2.0", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"@f5devcentral/atg-shared-utilities": "^0.4.3" | ||
}, | ||
"devDependencies": { | ||
@@ -41,2 +43,3 @@ "@f5devcentral/eslint-config-f5-atg": "^0.1.6", | ||
"mock-fs": "^4.14.0", | ||
"nock": "10.0.0", | ||
"nyc": "^15.1.0", | ||
@@ -43,0 +46,0 @@ "sinon": "^12.0.1", |
'use strict'; | ||
const http = require('http'); | ||
const zlib = require('zlib'); | ||
@@ -12,2 +11,5 @@ const fs = require('fs'); | ||
const promiseUtil = require('@f5devcentral/atg-shared-utilities').promiseUtils; | ||
const request = require('@f5devcentral/atg-shared-utilities').requestUtils; | ||
const ZLIB_OPTIONS = { | ||
@@ -186,2 +188,54 @@ level: zlib.Z_BEST_COMPRESSION, | ||
function waitForCompletion(path, remainingRetries) { | ||
const opts = { | ||
protocol: 'http:', | ||
host: 'localhost', | ||
port: 8100, | ||
path, | ||
method: 'GET', | ||
why: 'checking for task completion', | ||
headers: { | ||
Authorization: `Basic ${Buffer.from('admin:').toString('base64')}`, | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
return Promise.resolve() | ||
.then(() => request.send(opts)) | ||
.then((response) => { | ||
if (response._taskState === 'VALIDATING') { | ||
if (remainingRetries > 0) { | ||
return promiseUtil.delay(500) | ||
.then(() => waitForCompletion(path, remainingRetries - 1)); | ||
} | ||
throw new Error('Configuration save taking longer than expected'); | ||
} | ||
if (response._taskState === 'FAILED') { | ||
throw new Error(`Configuration save failed during execution: ${JSON.stringify(response)}`); | ||
} | ||
return Promise.resolve(); | ||
}) | ||
.catch((error) => { | ||
function isAllowedError() { | ||
if (error.message.indexOf('TimeoutException') > -1) { | ||
return true; | ||
} | ||
if (error.message.indexOf('response=400') > -1) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
if (remainingRetries > 0 && isAllowedError()) { | ||
return promiseUtil.delay(500) | ||
.then(() => waitForCompletion(path, remainingRetries - 1)); | ||
} | ||
throw error; | ||
}); | ||
} | ||
class StorageDataGroup { | ||
@@ -365,16 +419,2 @@ constructor(path, options) { | ||
persist() { | ||
const opts = { | ||
host: 'localhost', | ||
port: 8100, | ||
path: '/mgmt/tm/task/sys/config', | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Basic ${Buffer.from('admin:').toString('base64')}`, | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
const payload = { | ||
command: 'save' | ||
}; | ||
if (!this._dirty) { | ||
@@ -384,36 +424,50 @@ return Promise.resolve(); | ||
let taskId; | ||
return Promise.resolve() | ||
.then(() => new Promise((resolve, reject) => { | ||
const req = http.request(opts, (res) => { | ||
const buffer = []; | ||
res.setEncoding('utf8'); | ||
res.on('data', (data) => { | ||
buffer.push(data); | ||
}); | ||
res.on('end', () => { | ||
let body = buffer.join(''); | ||
body = body || '{}'; | ||
try { | ||
body = JSON.parse(body); | ||
} catch (e) { | ||
return reject(new Error(`Invalid response object from ${opts.method} to ${opts.path}`)); | ||
} | ||
return resolve({ | ||
status: res.statusCode, | ||
headers: res.headers, | ||
body | ||
}); | ||
}); | ||
}); | ||
.then(() => { | ||
const opts = { | ||
protocol: 'http:', | ||
host: 'localhost', | ||
port: 8100, | ||
path: '/mgmt/tm/task/sys/config', | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Basic ${Buffer.from('admin:').toString('base64')}`, | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
const payload = { | ||
command: 'save' | ||
}; | ||
req.on('error', (e) => { | ||
reject(new Error(`${opts.host}:${e.message}`)); | ||
}); | ||
return request.send(opts, payload); | ||
}) | ||
.then((res) => { | ||
if (res._taskState !== 'STARTED') { | ||
return Promise.reject(new Error(`failed to submit save sys config task:${JSON.stringify(res)}`)); | ||
} | ||
taskId = res._taskId; | ||
const opts = { | ||
protocol: 'http:', | ||
host: 'localhost', | ||
port: 8100, | ||
path: `/mgmt/tm/task/sys/config/${taskId}`, | ||
method: 'PUT', | ||
headers: { | ||
Authorization: `Basic ${Buffer.from('admin:').toString('base64')}`, | ||
'Content-Type': 'application/json' | ||
} | ||
}; | ||
const payload = { _taskState: 'VALIDATING' }; | ||
req.end(JSON.stringify(payload)); | ||
})) | ||
.then((response) => { | ||
if (response.status !== 200) { | ||
return Promise.reject(new Error(`failed to save sys config:${JSON.stringify(response.body)}`)); | ||
return request.send(opts, payload); | ||
}) | ||
.then((res) => { | ||
if (res.code !== 202) { | ||
return Promise.reject(new Error(`failed to update save sys config task:${JSON.stringify(res)}`)); | ||
} | ||
return waitForCompletion(`/mgmt/tm/task/sys/config/${taskId}`, 120); | ||
}) | ||
.then(() => { | ||
this._dirty = false; | ||
@@ -420,0 +474,0 @@ return Promise.resolve(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
69344
9
490
1
14
+ Added@f5devcentral/atg-shared-utilities@0.4.11(transitive)
+ Addedansi-color@0.2.1(transitive)
+ Addedbufrw@1.4.0(transitive)
+ Addederror@7.0.27.2.1(transitive)
+ Addedhexer@1.5.0(transitive)
+ Addedjaeger-client@3.19.0(transitive)
+ Addedlong@2.4.0(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addednode-int64@0.4.0(transitive)
+ Addedopentracing@0.14.7(transitive)
+ Addedprocess@0.10.1(transitive)
+ Addedstring-template@0.2.1(transitive)
+ Addedthriftrw@3.12.0(transitive)
+ Addeduuid@8.3.2(transitive)
+ Addedxorshift@1.2.0(transitive)
+ Addedxtend@4.0.2(transitive)