Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure _getBackbeatClient Always Returns BackbeatMetadataProxy #2439

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions extensions/lifecycle/bucketProcessor/LifecycleBucketProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ class LifecycleBucketProcessor {
}

/**
* Return an backbeat client instance
* Return metadata proxy with backbeat client
* @param {String} canonicalId - The canonical ID of the bucket owner.
* @param {String} accountId - The account ID of the bucket owner .
* @return {BackbeatClient} The S3 client instance to make requests with
* @return {BackbeatMetadataProxy} backbeatMetadataProxy - The metadata proxy with backbeat client
*/
_getBackbeatClient(canonicalId, accountId) {
const credentials = this.credentialsManager.getCredentials({
Expand All @@ -228,22 +228,21 @@ class LifecycleBucketProcessor {
}

const clientId = canonicalId;
const client = this.backbeatClients[clientId];
let client = this.backbeatClients[clientId];

if (!client) {
client = createBackbeatClient({
transport: this._transport,
port: this._s3Config.port,
host: this._s3Config.host,
credentials,
agent: this.s3Agent,
});

if (client) {
return client;
this.backbeatClients[clientId] = client;
}

this.backbeatClients[clientId] = createBackbeatClient({
transport: this._transport,
port: this._s3Config.port,
host: this._s3Config.host,
credentials,
agent: this.s3Agent,
});

return new BackbeatMetadataProxy(this._lcConfig)
.setBackbeatClient(this.backbeatClients[clientId]);
return new BackbeatMetadataProxy(this._lcConfig).setBackbeatClient(client);
}

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

const assert = require('assert');
const LifecycleBucketProcessor = require('../../../extensions/lifecycle/bucketProcessor/LifecycleBucketProcessor');
const BackbeatMetadataProxy = require('../../../lib/BackbeatMetadataProxy');

const zkConfig = {};
const kafkaConfig = {};
const lcConfig = { auth: {}, bucketProcessor: {} };
const repConfig = {};
const s3Config = { host: 'init.test.host', port: 8000 };

describe('LifecycleBucketProcessor', () => {
describe('_getBackbeatClient', () => {
let lbp;

beforeEach(() => {
lbp = new LifecycleBucketProcessor(zkConfig, kafkaConfig, lcConfig, repConfig, s3Config, 'http');
lbp.credentialsManager = {
getCredentials() {
return {
accessKeyId: 'ak0',
secretAccessKey: 'sk0',
};
},
};
});

it('should return an instance of BackbeatMetadataProxy', () => {
const canonicalId = 'cid0';
const accountId = 'id0';
const client = lbp._getBackbeatClient(canonicalId, accountId);

assert.ok(client instanceof BackbeatMetadataProxy, 'client is not an instance of BackbeatMetadataProxy');
});

it('should return an instance of BackbeatMetadataProxy after caching', () => {
const canonicalId = 'cid0';
const accountId = 'id0';
lbp._getBackbeatClient(canonicalId, accountId);
const client = lbp._getBackbeatClient(canonicalId, accountId);

assert.ok(client instanceof BackbeatMetadataProxy, 'client is not an instance of BackbeatMetadataProxy');
});
});
});