diff --git a/lib/constants.ts b/lib/constants.ts index 55016b4a1..6406c306f 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -32,6 +32,7 @@ export const maximumMetaHeadersSize = 2136; export const emptyFileMd5 = 'd41d8cd98f00b204e9800998ecf8427e'; // Version 2 changes the format of the data location property // Version 3 adds the dataStoreName attribute +// Version 3.1 backport of Version 7 on top of 3 // Version 4 add the Creation-Time and Content-Language attributes, // and add support for x-ms-meta-* headers in UserMetadata // Version 5 adds the azureInfo structure @@ -41,7 +42,11 @@ export const emptyFileMd5 = 'd41d8cd98f00b204e9800998ecf8427e'; // any metadata of the object. // version 6 also adds the "isPHD" flag that is used to indicate that the master // object is a placeholder and is not up to date. -export const mdModelVersion = 6; +// Version 7 adds the "bucketOwnerId" attribute to the object metadata. +// This is set when the owner of the bucket is different from the owner-id of the object. +// This can happen in cases of cross-account permissions where the object +// is uploaded by a different account than the one that owns the bucket. +export const mdModelVersion = 7; /* * 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 diff --git a/lib/models/ObjectMD.ts b/lib/models/ObjectMD.ts index 5492c08b9..4d7baeecb 100644 --- a/lib/models/ObjectMD.ts +++ b/lib/models/ObjectMD.ts @@ -37,6 +37,9 @@ export type ReplicationInfo = { export type ObjectMDData = { 'owner-display-name': string; + // The canonical Id of the account used to create the object. + // This can be different than the bucket owner if cross-account + // permissions are used to create the object. 'owner-id': string; 'cache-control': string; 'content-disposition': string; @@ -90,6 +93,9 @@ export type ObjectMDData = { // the master is set as a placeholder and gets updated with the new latest // version data after a certain amount of time. isPHD: boolean; + // This is the canonical Id for the bucket owner. + // This is only set when it differs from `owner-id`. + bucketOwnerId?: string; }; /** @@ -1481,4 +1487,30 @@ export default class ObjectMD { getIsPHD() { return this._data.isPHD; } + + /** + * Set bucket owner id + * @param canonicalId - bucket owner id + * @return itself + */ + setBucketOwnerId(canonicalId: string) { + this._data.bucketOwnerId = canonicalId; + return this; + } + + /** + * Returns bucket owner id + * @return bucket owner id + */ + getBucketOwnerId() { + return this._data.bucketOwnerId; + } + + /** + * Returns the model version of the object metadata + * @return {number|undefined} + */ + getModelVersion(): number | undefined { + return this._data['md-model-version']; + } } diff --git a/package.json b/package.json index 975420195..fb8c063aa 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "engines": { "node": ">=16" }, - "version": "8.1.158", + "version": "8.1.159", "description": "Common utilities for the S3 project components", "main": "build/index.js", "repository": { diff --git a/tests/unit/models/ObjectMD.spec.js b/tests/unit/models/ObjectMD.spec.js index 9c5e68025..d5e616be5 100644 --- a/tests/unit/models/ObjectMD.spec.js +++ b/tests/unit/models/ObjectMD.spec.js @@ -139,6 +139,9 @@ describe('ObjectMD class setters/getters', () => { ['OriginOp', null, ''], ['Deleted', null, false], ['IsPHD', null, false], + ['BucketOwnerId', null, undefined], + ['BucketOwnerId', 'abcdef'], + ['ModelVersion', null, constants.mdModelVersion], ].forEach(test => { const property = test[0]; const testValue = test[1];