Skip to content

Commit

Permalink
Patch rock req initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
steevepay committed May 25, 2023
1 parent 6d8182f commit 8962224
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v2.2.2
- Patched rock-req options initialisation

### v2.2.1
- Updated package `rock-req` to `5.1.3`

Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const rock = require('rock-req');
const s3 = require('./s3.js');
const swift = require('./swift.js');

if (global.rockReqConf && typeof global.rockReqConf === 'object') {
Object.assign(rock.defaults, global.rockReqConf);
}

module.exports = (config) => {
/** Check the first credential and return storage type: S3 or Swift client */
const _auth = Array.isArray(config) && config.length > 0 ? config[0] : config;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tiny-storage-client",
"version": "2.2.1",
"version": "2.2.2",
"description": "Tiny node client to request distributed AWS S3 or the OpenStack Swift Object Storage.",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 1 addition & 11 deletions s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ const xmlToJson = require('./xmlToJson.js')

const isFnStream = o => o instanceof Function

if (global.rockReqConf && typeof global.rockReqConf === 'object') {
rock.defaults = {
...rock.defaults,
...global.rockReqConf
}
}

module.exports = (config) => {

let _config = {
Expand Down Expand Up @@ -267,10 +260,7 @@ module.exports = (config) => {

function setRockReqDefaults (newDefaults) {
if (newDefaults && typeof newDefaults === 'object') {
rock.defaults = {
...rock.defaults,
...newDefaults
};
Object.assign(rock.defaults, newDefaults);
}
}

Expand Down
11 changes: 8 additions & 3 deletions swift.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ module.exports = (config) => {
timeout: 5000
}

setStorages(config)

/**
* @description Authenticate and initialise the auth token and retreive the endpoint based on the region
*
Expand Down Expand Up @@ -696,6 +694,12 @@ module.exports = (config) => {
return { headers, queries, body }
}

function getRockReqDefaults() {
return rock.defaults;
}

setStorages(config)

return {
connection,
uploadFile,
Expand All @@ -709,6 +713,7 @@ module.exports = (config) => {
getStorages,
getConfig,
setLogFunction,
request
request,
getRockReqDefaults
}
}
6 changes: 2 additions & 4 deletions tests/s3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const _rockDefaults = { ...rock.defaults };
_rockDefaults.retryDelay = 200
global.rockReqConf = _rockDefaults;

const s3 = require('../s3.js');
const s3 = require('../index')
const assert = require('assert');
const nock = require('nock');
const fs = require('fs');
Expand Down Expand Up @@ -2568,11 +2568,9 @@ describe('S3 SDK', function () {
it("should set rock-req default values", function(done) {
const _newOptions = {
...storage.getRockReqDefaults(),
newOption: 1234,
maxRetry: 10
newOption: 1234
}
storage.setRockReqDefaults(_newOptions);
assert.strictEqual(storage.getRockReqDefaults().maxRetry, 10);
assert.strictEqual(storage.getRockReqDefaults().newOption, 1234);
done();
})
Expand Down
18 changes: 15 additions & 3 deletions tests/swift.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const storageSDK = require('../swift.js');
const storageSDK = require('../index.js');
const nock = require('nock');
const assert = require('assert');
const fs = require('fs');
Expand Down Expand Up @@ -52,8 +52,14 @@ const outputStreamFunction = function (opt, res) {
}


describe('Ovh Object Storage High Availability Node Client', function () {
let storage = storageSDK();
describe('Ovh Object Storage Swift', function () {
let storage = storageSDK([{
username : 'storage-1-user',
password : 'storage-1-password',
authUrl : authURL,
tenantName : 'storage-1-tenant',
region : 'GRA'
}]);

beforeEach(function (done) {
const firstNock = nock(authURL)
Expand Down Expand Up @@ -4881,6 +4887,12 @@ describe('Ovh Object Storage High Availability Node Client', function () {
});
});
});
describe('global.rockReqConf', function() {
it("should set rock-req default values", function(done) {
assert.strictEqual(storage.getRockReqDefaults().retryDelay, 200);
done();
})
})
});

let connectionResultSuccessV3 = {
Expand Down

0 comments on commit 8962224

Please sign in to comment.