Skip to content

Commit

Permalink
ft(ZENKO-1616): Update ObjectMD model for azure blob api
Browse files Browse the repository at this point in the history
  • Loading branch information
tmacro committed Apr 1, 2019
1 parent 6791d1b commit 5929051
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ module.exports = {
emptyFileMd5: 'd41d8cd98f00b204e9800998ecf8427e',
// Version 2 changes the format of the data location property
// Version 3 adds the dataStoreName attribute
mdModelVersion: 3,
// Version 4 add the Creation-Time and Content-Language attributes,
// and add support for x-ms-meta-* headers in UserMetadata
mdModelVersion: 4,
/*
* Splitter is used to build the object name for the overview of a
* multipart upload and to build the object names for each part of a
Expand Down
56 changes: 55 additions & 1 deletion lib/models/ObjectMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ class ObjectMD {
} else {
this._updateFromParsedJSON(objMd);
}
if (!this._data['creation-time']) {
this.setCreationTime(this.getLastModified());
}
} else {
// set newly-created object md modified time to current time
this._data['last-modified'] = new Date().toJSON();
const dt = new Date().toJSON();
this.setLastModified(dt);
this.setCreationTime(dt);
}
// set latest md model version now that we ensured
// backward-compat conversion
Expand Down Expand Up @@ -85,6 +90,8 @@ class ObjectMD {
'content-length': 0,
'content-type': '',
'content-md5': '',
'content-language': '',
'creation-time': undefined,
// simple/no version. will expand once object versioning is
// introduced
'x-amz-version-id': 'null',
Expand Down Expand Up @@ -352,6 +359,50 @@ class ObjectMD {
return this._data['content-md5'];
}

/**
* Set content-language
*
* @param {string} contentLanguage - content-language
* @return {ObjectMD} itself
*/
setContentLanguage(contentLanguage) {
this._data['content-language'] = contentLanguage;
return this;
}

/**
* Returns content-language
*
* @return {string} content-language
*/
getContentLanguage() {
return this._data['content-language'];
}

/**
* Set Creation Date
*
* @param {string} creationTime - Creation Date
* @return {ObjectMD} itself
*/
setCreationTime(creationTime) {
this._data['creation-time'] = creationTime;
return this;
}

/**
* Returns Creation Date
*
* @return {string} Creation Date
*/
getCreationTime() {
// If creation-time is not set fallback to LastModified
if (!this._data['creation-time']) {
return this.getLastModified();
}
return this._data['creation-time'];
}

/**
* Set version id
*
Expand Down Expand Up @@ -916,6 +967,9 @@ class ObjectMD {
Object.keys(metaHeaders).forEach(key => {
if (key.startsWith('x-amz-meta-')) {
this._data[key] = metaHeaders[key];
} else if (key.startsWith('x-ms-meta-')) {
const _key = key.replace('x-ms-meta-', 'x-amz-meta-');
this._data[_key] = metaHeaders[key];
}
});
// If a multipart object and the acl is already parsed, we update it
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/models/ObjectMD.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ describe('ObjectMD class setters/getters', () => {
['LastModified', new Date().toJSON()],
['ContentMd5', null, ''],
['ContentMd5', 'content-md5'],
['ContentLanguage', null, ''],
['ContentLanguage', 'content-language', ''],
['CreationTime', new Date().toJSON()],
['AmzVersionId', null, 'null'],
['AmzVersionId', 'version-id'],
['AmzServerVersionId', null, ''],
Expand Down Expand Up @@ -215,8 +218,10 @@ describe('ObjectMD class setters/getters', () => {
md.setUserMetadata({
'x-amz-meta-foo': 'bar',
'x-amz-meta-baz': 'qux',
// this one should be filtered out
// This one should be filtered out
'x-amz-storage-class': 'STANDARD_IA',
// This one should be changed to 'x-amz-meta-foobar'
'x-ms-meta-foobar': 'bar',
// ACLs are updated
'acl': {
FULL_CONTROL: ['john'],
Expand All @@ -225,6 +230,7 @@ describe('ObjectMD class setters/getters', () => {
assert.deepStrictEqual(JSON.parse(md.getUserMetadata()), {
'x-amz-meta-foo': 'bar',
'x-amz-meta-baz': 'qux',
'x-amz-meta-foobar': 'bar',
});
assert.deepStrictEqual(md.getAcl(), {
FULL_CONTROL: ['john'],
Expand Down Expand Up @@ -333,6 +339,8 @@ describe('getAttributes static method', () => {
'content-length': true,
'content-type': true,
'content-md5': true,
'content-language': true,
'creation-time': true,
'x-amz-version-id': true,
'x-amz-server-version-id': true,
'x-amz-storage-class': true,
Expand Down

0 comments on commit 5929051

Please sign in to comment.