putBucketInventory.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.putBucketInventory = void 0;
  4. const checkBucketName_1 = require("../utils/checkBucketName");
  5. const obj2xml_1 = require("../utils/obj2xml");
  6. /**
  7. * putBucketInventory
  8. * @param {String} bucketName - bucket name
  9. * @param {Inventory} inventory
  10. * @param {Object} options
  11. */
  12. async function putBucketInventory(bucketName, inventory, options = {}) {
  13. const subres = Object.assign({ inventory: '', inventoryId: inventory.id }, options.subres);
  14. checkBucketName_1.checkBucketName(bucketName);
  15. const { OSSBucketDestination, optionalFields, includedObjectVersions } = inventory;
  16. const destinationBucketPrefix = 'acs:oss:::';
  17. const rolePrefix = `acs:ram::${OSSBucketDestination.accountId}:role/`;
  18. const paramXMLObj = {
  19. InventoryConfiguration: {
  20. Id: inventory.id,
  21. IsEnabled: inventory.isEnabled,
  22. Filter: {
  23. Prefix: inventory.prefix || ''
  24. },
  25. Destination: {
  26. OSSBucketDestination: {
  27. Format: OSSBucketDestination.format,
  28. AccountId: OSSBucketDestination.accountId,
  29. RoleArn: `${rolePrefix}${OSSBucketDestination.rolename}`,
  30. Bucket: `${destinationBucketPrefix}${OSSBucketDestination.bucket}`,
  31. Prefix: OSSBucketDestination.prefix || '',
  32. Encryption: OSSBucketDestination.encryption || ''
  33. }
  34. },
  35. Schedule: {
  36. Frequency: inventory.frequency
  37. },
  38. IncludedObjectVersions: includedObjectVersions,
  39. OptionalFields: {
  40. Field: (optionalFields === null || optionalFields === void 0 ? void 0 : optionalFields.field) || []
  41. }
  42. }
  43. };
  44. const paramXML = obj2xml_1.obj2xml(paramXMLObj, {
  45. headers: true,
  46. firstUpperCase: true
  47. });
  48. const params = this._bucketRequestParams('PUT', bucketName, subres, options);
  49. params.successStatuses = [200];
  50. params.mime = 'xml';
  51. params.content = paramXML;
  52. const result = await this.request(params);
  53. return {
  54. status: result.status,
  55. res: result.res
  56. };
  57. }
  58. exports.putBucketInventory = putBucketInventory;