Skip to content

Commit e45aebd

Browse files
committed
adding the ability to run headObject on the s3 connector
1 parent 8d7ac4c commit e45aebd

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

src/connectors/s3.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { Readable } from 'stream';
44
import {
55
CopyObjectCommand,
6-
DeleteObjectCommand, GetObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client,
6+
DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client,
77
} from '@aws-sdk/client-s3';
88
import { NodeHttpHandler } from '@smithy/node-http-handler';
99
import Promise from 'bluebird';
@@ -47,6 +47,15 @@ class Connector {
4747
return this.clients[pipelineId];
4848
}
4949

50+
headObject(inputParams, ctx) {
51+
const params = {
52+
Bucket: this.bucketName,
53+
...inputParams,
54+
};
55+
56+
return this._sendCommand(new HeadObjectCommand(params), ctx);
57+
}
58+
5059
putObject(inputParams, ctx) {
5160
const params = {
5261
Bucket: this.bucketName,

test/unit/connectors/s3.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Readable } from 'stream';
66
import { mockClient } from 'aws-sdk-client-mock';
77
import {
88
CopyObjectCommand,
9-
DeleteObjectCommand, GetObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client,
9+
DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client,
1010
} from '@aws-sdk/client-s3';
1111
import { sdkStreamMixin } from '@smithy/util-stream';
1212

@@ -199,4 +199,20 @@ describe('connectors/s3.js', () => {
199199
});
200200
expect(data).to.deep.equal({});
201201
});
202+
it('should head object', async () => {
203+
const spy = sinon.spy(() => ({}));
204+
mockS3.on(HeadObjectCommand).callsFake(spy);
205+
const inputParams = {
206+
Key: 'k1',
207+
};
208+
const data = await new Connector({
209+
debug: debug('s3'),
210+
bucketName: 'b1',
211+
}).headObject(inputParams);
212+
expect(spy).to.have.been.calledWith({
213+
Key: 'k1',
214+
Bucket: 'b1',
215+
});
216+
expect(data).to.deep.equal({});
217+
});
202218
});

0 commit comments

Comments
 (0)