Skip to content

Commit

Permalink
LifecycleQueuePopulator: avoid creating vaultClientWrapper when not n…
Browse files Browse the repository at this point in the history
…eeded

Issue: BB-622
  • Loading branch information
Kerkesni committed Nov 7, 2024
1 parent 840f6bf commit fc9e8b7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
24 changes: 16 additions & 8 deletions extensions/lifecycle/LifecycleQueuePopulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class LifecycleQueuePopulator extends QueuePopulatorExtension {
super(params);
this._authConfig = params.authConfig;

this.vaultClientWrapper = new VaultClientWrapper(
LIFEYCLE_POPULATOR_CLIENT_ID,
params.vaultAdmin,
this._authConfig,
this.log,
);

if (this._authConfig.type === authTypeAssumeRole) {
if (this._authConfig?.type === authTypeAssumeRole) {
this.vaultClientWrapper = new VaultClientWrapper(
LIFEYCLE_POPULATOR_CLIENT_ID,
params.vaultAdmin,
this._authConfig,
this.log,
);

this.vaultClientWrapper.init();
}

Expand Down Expand Up @@ -238,6 +238,10 @@ class LifecycleQueuePopulator extends QueuePopulatorExtension {
}

_handleRestoreOp(entry) {
if (!this.vaultClientWrapper) {
return;
}

if (entry.type !== 'put' ||
entry.key.startsWith(mpuBucketPrefix)) {
return;
Expand Down Expand Up @@ -391,6 +395,10 @@ class LifecycleQueuePopulator extends QueuePopulatorExtension {
}

_handleDeleteOp(entry) {
if (!this.vaultClientWrapper) {
return;
}

const value = JSON.parse(entry.value);

// if object is not archived there is nothing to do here
Expand Down
13 changes: 11 additions & 2 deletions tests/unit/lifecycle/LifecycleQueuePopulator.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ describe('LifecycleQueuePopulator', () => {
}, 100);
}

describe('constructor', () => {
it('should not create vaultClientWrapper when no auth config passed', () => {
const params = {};
const lcqp = new LifecycleQueuePopulator(params);
assert.strictEqual(lcqp.vaultClientWrapper, undefined);
});
});

describe('Producer', () => {
let lcqp;
beforeEach(() => {
Expand Down Expand Up @@ -387,7 +395,6 @@ describe('LifecycleQueuePopulator', () => {
});
});


describe(':_handleDeleteOp', () => {
const kafkaSendStub = sinon.stub().yields();
const objMd = {
Expand Down Expand Up @@ -545,7 +552,9 @@ describe('LifecycleQueuePopulator', () => {
},
].forEach(params => {
it(params.it, () => {
lcqp.vaultClientWrapper.getAccountId = sinon.stub().yields(...params.getAccountIdResponse);
lcqp.vaultClientWrapper = {
getAccountId: sinon.stub().yields(...params.getAccountIdResponse),
};
const timestamp = new Date();
const entry = {
type: params.type,
Expand Down

0 comments on commit fc9e8b7

Please sign in to comment.