Skip to content

Commit

Permalink
VaultClientWrapper fallback to auth config when vaultadmin config not…
Browse files Browse the repository at this point in the history
… defined

Issue: BB-622
  • Loading branch information
Kerkesni committed Nov 7, 2024
1 parent 6694ca8 commit 840f6bf
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
4 changes: 3 additions & 1 deletion extensions/utils/VaultClientWrapper.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const assert = require('assert');
const { ChainableTemporaryCredentials } = require('aws-sdk');
const { errorUtils } = require('arsenal');

Expand All @@ -11,7 +12,8 @@ class VaultClientWrapper {
this._authConfig = authConfig;
this._transport = this._authConfig.transport;
this._clientId = id;
this._vaultConf = vaultConf;
this._vaultConf = vaultConf || this._authConfig.vault;
assert(this._vaultConf, 'Vault configuration is missing');
this.logger = logger;

const Agent = this._transport === 'https' ? HttpsAgent.Agent : HttpAgent.Agent;
Expand Down
21 changes: 21 additions & 0 deletions tests/functional/lifecycle/LifecycleConductor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ describe('lifecycle conductor', function lifecycleConductor() {
backlogControl: {
enabled: true,
},
auth: {
type: 'none',
vault: {
host: '127.0.0.1',
port: 8500,
},
},
},
bucketProcessor: {
groupId: 'a',
Expand Down Expand Up @@ -283,6 +290,13 @@ describe('lifecycle conductor', function lifecycleConductor() {
backlogControl: {
enabled: true,
},
auth: {
type: 'none',
vault: {
host: '127.0.0.1',
port: 8500,
},
},
},
bucketProcessor: {
groupId: 'a',
Expand Down Expand Up @@ -546,6 +560,13 @@ describe('lifecycle conductor', function lifecycleConductor() {
bucketd: {
host: '127.0.0.1',
},
auth: {
type: 'none',
vault: {
host: '127.0.0.1',
port: 8500,
},
},
},
},
mockBucketd: true,
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/lifecycle/configObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const lcConfig = {
cronRule: '*/5 * * * * *',
concurrentIndexesBuildLimit: 2,
bucketSource: 'mongodb',
vaultAdmin: {
host: '127.0.0.1',
port: 8500,
},
},
bucketProcessor: {
groupId: `bucket-processor-test-${Math.random()}`,
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/gc/GarbageCollector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ describe('garbage collector', function garbageCollector() {
consumer: {
groupId: 'backbeat-gc-consumer-group',
},
vaultAdmin: {
host: '127.0.0.1',
port: 8500,
},
},
});
gcTask = new GarbageCollectorTask(gc);
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/lifecycle/LifecycleConductor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ function makeLifecycleConductorWithFilters(options, markers) {
accounts: accountsDenied,
},
},
vaultAdmin: {
host: '127.0.0.1',
port: 8500,
},
},
};

Expand Down
34 changes: 34 additions & 0 deletions tests/unit/utils/VaultClientWrapper.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'; // eslint-disable-line

const assert = require('assert');
const sinon = require('sinon');

const FakeLogger = require('../../utils/fakeLogger');
const VaultClientWrapper = require('../../../extensions/utils/VaultClientWrapper');
const { errors } = require('arsenal');

describe('VaultClientWrapper', () => {
afterEach(() => {
sinon.restore();
});

describe('constructor', () => {
it('should fallback to authConfig vault if vaultConf is not provided', () => {
const vaultClientWrapper = new VaultClientWrapper(
'id',
undefined,
{ type: 'none', vault: { host: '127.0.0.1', port: 8500 } },
FakeLogger,
);
assert.strictEqual(vaultClientWrapper._vaultConf.host, '127.0.0.1');
assert.strictEqual(vaultClientWrapper._vaultConf.port, 8500);
});

it('should throw an error if vault configuration is missing', () => {
assert.throws(() =>
new VaultClientWrapper('id', undefined, { type: 'none' }, FakeLogger),
);
});
});

});

0 comments on commit 840f6bf

Please sign in to comment.