Skip to content

Commit

Permalink
blacklist lifecycle buckets and accounts when listing from mongodb
Browse files Browse the repository at this point in the history
Issue: BB-537
  • Loading branch information
Kerkesni committed Oct 9, 2024
1 parent c37df8e commit ba5d9fd
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 5 deletions.
24 changes: 19 additions & 5 deletions extensions/lifecycle/conductor/LifecycleConductor.js
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,25 @@ class LifecycleConductor {
lastSentVersion = stat.version;
}

const filter = {};
if (entry) {
filter._id = { $gt: entry };
}

if (this.accountsBlacklisted.size > 0) {
filter['value.owner'] = { $nin: Array.from(this.accountsBlacklisted) };
}

if (this.bucketsBlacklisted.size > 0) {
if (filter._id === undefined) {
filter._id = {};
}
filter._id.$nin = Array.from(this.bucketsBlacklisted);
}

const cursor = this._mongodbClient
.getCollection('__metastore')
.find(
entry ? { _id: { $gt: entry } } : {}
)
.find(filter)
.project({ '_id': 1, 'value.owner': 1, 'value.lifecycleConfiguration': 1 });

return done(null, cursor);
Expand All @@ -712,8 +726,8 @@ class LifecycleConductor {
async.during(
test => process.nextTick(
() => cursor.hasNext()
.then(res => test(null, res))
.catch(test)),
.then(res => test(null, res))
.catch(test)),
next => {
const breakerState = this._circuitBreaker.state;
const queueInfo = {
Expand Down
133 changes: 133 additions & 0 deletions tests/unit/lifecycle/LifecycleConductor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,138 @@ describe('Lifecycle Conductor', () => {
done();
});
});

it('should not use any filter when listing from from mongodb', done => {
const lcConductor = makeLifecycleConductorWithFilters({
bucketSource: 'mongodb',
}, []);

Check failure on line 587 in tests/unit/lifecycle/LifecycleConductor.spec.js

View workflow job for this annotation

GitHub Actions / tests

Trailing spaces not allowed
const findStub = sinon.stub().returns({
project: () => ({
hasNext: sinon.stub().resolves(false),
})
});
lcConductor._mongodbClient = {
getIndexingJobs: (_, cb) => cb(null, ['job1', 'job2']),
getCollection: () => ({ find: findStub })
};
sinon.stub(lcConductor._zkClient, 'getData').yields(null, null, null);
lcConductor.listBuckets(queue, fakeLogger, err => {
assert.ifError(err);
assert.deepEqual(findStub.getCall(0).args[0], {});
done();
});
});

it('should filter by account when listing from from mongodb', done => {
const lcConductor = makeLifecycleConductorWithFilters({
accountsDenied: [`${accountName1}:${account1}`],
bucketSource: 'mongodb',
}, []);
const findStub = sinon.stub().returns({
project: () => ({
hasNext: sinon.stub().resolves(false),
})
});
lcConductor._mongodbClient = {
getIndexingJobs: (_, cb) => cb(null, ['job1', 'job2']),
getCollection: () => ({ find: findStub })
};
sinon.stub(lcConductor._zkClient, 'getData').yields(null, null, null);
lcConductor.listBuckets(queue, fakeLogger, err => {
assert.ifError(err);
assert.deepEqual(findStub.getCall(0).args[0], {
'value.owner': {
$nin: [
'ab288756448dc58f61482903131e7ae533553d20b52b0e2ef80235599a1b9143',
],
},
});
done();
});
});

it('should filter by bucket when listing from from mongodb', done => {
const lcConductor = makeLifecycleConductorWithFilters({
bucketsDenied: [bucket2],
bucketSource: 'mongodb',
}, []);
const findStub = sinon.stub().returns({
project: () => ({
hasNext: sinon.stub().resolves(false),
})
});
lcConductor._mongodbClient = {
getIndexingJobs: (_, cb) => cb(null, ['job1', 'job2']),
getCollection: () => ({ find: findStub })
};
sinon.stub(lcConductor._zkClient, 'getData').yields(null, null, null);
lcConductor.listBuckets(queue, fakeLogger, err => {
assert.ifError(err);
assert.deepEqual(findStub.getCall(0).args[0], {
_id: {
$nin: ['bucket2'],
},
});
done();
});
});

it('should use the resume marker when listing from from mongodb', done => {
const lcConductor = makeLifecycleConductorWithFilters({
bucketSource: 'mongodb',
}, []);
const findStub = sinon.stub().returns({
project: () => ({
hasNext: sinon.stub().resolves(false),
})
});
lcConductor._mongodbClient = {
getIndexingJobs: (_, cb) => cb(null, ['job1', 'job2']),
getCollection: () => ({ find: findStub })
};
sinon.stub(lcConductor._zkClient, 'getData').yields(null, Buffer.from('bucket1'), null);
lcConductor.listBuckets(queue, fakeLogger, err => {
assert.ifError(err);
assert.deepEqual(findStub.getCall(0).args[0], {
_id: {
$gt: 'bucket1',
},
});
done();
});
});

it('should filter by account and bucket when listing from from mongodb', done => {
const lcConductor = makeLifecycleConductorWithFilters({
accountsDenied: [`${accountName1}:${account1}`],
bucketsDenied: [bucket2],
bucketSource: 'mongodb',
}, []);
const findStub = sinon.stub().returns({
project: () => ({
hasNext: sinon.stub().resolves(false),
})
});
lcConductor._mongodbClient = {
getIndexingJobs: (_, cb) => cb(null, ['job1', 'job2']),
getCollection: () => ({ find: findStub })
};
sinon.stub(lcConductor._zkClient, 'getData').yields(null, Buffer.from('bucket1'), null);
lcConductor.listBuckets(queue, fakeLogger, err => {
assert.ifError(err);
assert.deepEqual(findStub.getCall(0).args[0], {
'_id': {
$gt: 'bucket1',
$nin: ['bucket2'],
},
'value.owner': {
$nin: [
'ab288756448dc58f61482903131e7ae533553d20b52b0e2ef80235599a1b9143',
],
},
});
done();
});
});
});
});

0 comments on commit ba5d9fd

Please sign in to comment.