MCPcopy Index your code
hub / github.com/scality/cloudserver / buildAttributesXml

Function buildAttributesXml

lib/api/apiUtils/object/objectAttributes.js:60–109  ·  view source on GitHub ↗

* buildAttributesXml - Builds XML reponse for requested object attributes * @param {Object} objectMD - The internal metadata object for the file/object. * @param {string} [objectMD.content-md5] - The MD5 hash used for the ETag. * @param {string} [objectMD.x-amz-storage-class] - The storage tier o

(objectMD, userMetadata, requestedAttrs, xml)

Source from the content-addressed store, hash-verified

58 * @returns {void} - this function does not return a value, it mutates the `xml` param.
59 */
60function buildAttributesXml(objectMD, userMetadata, requestedAttrs, xml) {
61 const customAttributes = new Set();
62 for (const attribute of requestedAttrs) {
63 switch (attribute) {
64 case 'ETag':
65 xml.push(`<ETag>${objectMD['content-md5']}</ETag>`);
66 break;
67 case 'ObjectParts': {
68 const partCount = getPartCountFromMd5(objectMD);
69 if (partCount) {
70 xml.push(
71 '<ObjectParts>',
72 `<PartsCount>${partCount}</PartsCount>`,
73 '</ObjectParts>',
74 );
75 }
76 break;
77 }
78 case 'StorageClass':
79 xml.push(`<StorageClass>${objectMD['x-amz-storage-class']}</StorageClass>`);
80 break;
81 case 'ObjectSize':
82 xml.push(`<ObjectSize>${objectMD['content-length']}</ObjectSize>`);
83 break;
84 case 'RestoreStatus':
85 xml.push('<RestoreStatus>');
86 xml.push(`<IsRestoreInProgress>${!!objectMD.restoreStatus?.inProgress}</IsRestoreInProgress>`);
87
88 if (objectMD.restoreStatus?.expiryDate) {
89 xml.push(`<RestoreExpiryDate>${objectMD.restoreStatus?.expiryDate}</RestoreExpiryDate>`);
90 }
91
92 xml.push('</RestoreStatus>');
93 break;
94 case 'x-amz-meta-*':
95 for (const key of Object.keys(userMetadata)) {
96 customAttributes.add(key);
97 }
98 break;
99 default:
100 if (userMetadata[attribute]) {
101 customAttributes.add(attribute);
102 }
103 }
104 }
105
106 for (const key of customAttributes) {
107 xml.push(`<${key}>${userMetadata[key]}</${key}>`);
108 }
109}
110
111module.exports = {
112 parseAttributesHeaders,

Callers 4

buildXmlResponseFunction · 0.85
processVersionsFunction · 0.85
processMasterVersionsFunction · 0.85

Calls 1

getPartCountFromMd5Function · 0.85

Tested by

no test coverage detected