Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@f5devcentral/atg-storage

Package Overview
Dependencies
Maintainers
18
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@f5devcentral/atg-storage - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

src/.storageDataGroup.js.swp

4

CHANGELOG.md

@@ -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

7

package.json
{
"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();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc