Skip to content

Commit 02f28a9

Browse files
authored
Merge pull request #195 from ProsperWorks/basic-metadata-support
add support for metadata passthru
2 parents 1bc216a + 7c342f9 commit 02f28a9

5 files changed

Lines changed: 36 additions & 1 deletion

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ Useful when deploying applications to [fake-s3](https://github.com/jubos/fake-s3
228228

229229
*Default:* `0`
230230

231+
### metadata
232+
233+
Metadata to be sent with the files. This should be an object that will be passed directly to the `Metadata` key in the `putObject` call of the AWS S3 SDK. Keys will be automatically prefixed with `x-amz-meta-` by the AWS SDK. Note that the AWS SDK treats all metadata values as strings. You should typecast your values to strings for explicit control.
234+
235+
*Example value*: `{ 'release-id': process.env.RELEASE_ID }`
236+
237+
*Default:* `null`
231238

232239
### signatureVersion
233240

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
expires: EXPIRE_IN_2030,
2626
dotFolders: false,
2727
batchSize: 0,
28+
metadata: null,
2829
defaultMimeType: 'application/octet-stream',
2930
distDir: function(context) {
3031
return context.distDir;
@@ -68,6 +69,7 @@ module.exports = {
6869
var dotFolders = this.readConfig('dotFolders');
6970
var serverSideEncryption = this.readConfig('serverSideEncryption');
7071
var batchSize = this.readConfig('batchSize');
72+
var metadata = this.readConfig('metadata');
7173
var defaultMimeType = this.readConfig('defaultMimeType');
7274

7375
var filesToUpload = distFiles.filter(minimatch.filter(filePattern, { matchBase: true, dot: dotFolders }));
@@ -98,6 +100,7 @@ module.exports = {
98100
cacheControl: cacheControl,
99101
expires: expires,
100102
batchSize: batchSize,
103+
metadata: metadata,
101104
defaultMimeType: defaultMimeType
102105
};
103106

lib/s3.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ module.exports = CoreObject.extend({
141141
var brotliCompressedFilePaths = options.brotliCompressedFilePaths || [];
142142
var cacheControl = options.cacheControl;
143143
var expires = options.expires;
144+
var metadata = options.metadata;
144145
var serverSideEncryption = options.serverSideEncryption;
145146

146147
var defaultType = options.defaultMimeType || mime.getType('bin');
@@ -187,6 +188,10 @@ module.exports = CoreObject.extend({
187188
params.ServerSideEncryption = serverSideEncryption;
188189
}
189190

191+
if (metadata) {
192+
params.Metadata = metadata;
193+
}
194+
190195
if (isGzipped) {
191196
params.ContentEncoding = 'gzip';
192197
}

tests/index-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('s3 plugin', function() {
131131
return previous;
132132
}, []);
133133

134-
assert.equal(messages.length, 8);
134+
assert.equal(messages.length, 9);
135135
});
136136

137137
describe('required config', function() {

tests/lib/s3-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ describe('s3', function() {
149149
});
150150
});
151151

152+
it('sets Metadata using metadata', function() {
153+
var s3Params;
154+
s3Client.putObject = function(params, cb) {
155+
s3Params = params;
156+
cb();
157+
};
158+
159+
var options = {
160+
filePaths: ['app.css'],
161+
cwd: process.cwd() + '/tests/fixtures/dist',
162+
prefix: 'js-app',
163+
metadata: { 'test-key': 'test-value' }
164+
};
165+
166+
return assert.isFulfilled(subject.upload(options))
167+
.then(function() {
168+
assert.deepEqual(s3Params.Metadata, { 'test-key': 'test-value' });
169+
});
170+
});
171+
152172
it('sends the correct content type params for gzipped files with .gz extension', function() {
153173
var s3Params;
154174
s3Client.putObject = function(params, cb) {

0 commit comments

Comments
 (0)