From be572b5d2a14b1e2a41e97fda6f8f12c5d8561b3 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 30 Oct 2023 02:14:13 +0800 Subject: [PATCH 1/8] put --- src/internal/client.ts | 61 +++++++++++++++++++++++++++++++++++++++++- src/internal/type.ts | 46 ++++++++++++++++++------------- src/minio.d.ts | 25 +++-------------- src/minio.js | 61 ++---------------------------------------- 4 files changed, 94 insertions(+), 99 deletions(-) diff --git a/src/internal/client.ts b/src/internal/client.ts index 82bea52e..e61bc55b 100644 --- a/src/internal/client.ts +++ b/src/internal/client.ts @@ -9,7 +9,7 @@ import xml2js from 'xml2js' import { CredentialProvider } from '../CredentialProvider.ts' import * as errors from '../errors.ts' -import { DEFAULT_REGION, LEGAL_HOLD_STATUS } from '../helpers.ts' +import { DEFAULT_REGION, LEGAL_HOLD_STATUS, RETENTION_MODES } from '../helpers.ts' import { signV4 } from '../signing.ts' import { Extensions } from './extensions.ts' import { @@ -52,6 +52,7 @@ import type { RequestHeaders, ResponseHeader, ResultCallback, + Retention, StatObjectOpts, Tag, Transport, @@ -1166,4 +1167,62 @@ export class TypedClient { const body = await readAsString(response) return xmlParsers.parseTagging(body) } + + async putObjectRetention( + bucketName: string, + objectName: string, + retentionOpts: Retention = {}, + ): Promise { + if (!isValidBucketName(bucketName)) { + throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName) + } + if (!isValidObjectName(objectName)) { + throw new errors.InvalidObjectNameError(`Invalid object name: ${objectName}`) + } + if (!isObject(retentionOpts)) { + throw new errors.InvalidArgumentError('retentionOpts should be of type "object"') + } else { + if (retentionOpts.governanceBypass && !isBoolean(retentionOpts.governanceBypass)) { + throw new errors.InvalidArgumentError('Invalid value for governanceBypass', retentionOpts.governanceBypass) + } + if ( + retentionOpts.mode && + ![RETENTION_MODES.COMPLIANCE, RETENTION_MODES.GOVERNANCE].includes(retentionOpts.mode) + ) { + throw new errors.InvalidArgumentError('Invalid object retention mode ', retentionOpts.mode) + } + if (retentionOpts.retainUntilDate && !isString(retentionOpts.retainUntilDate)) { + throw new errors.InvalidArgumentError('Invalid value for retainUntilDate', retentionOpts.retainUntilDate) + } + if (retentionOpts.versionId && !isString(retentionOpts.versionId)) { + throw new errors.InvalidArgumentError('Invalid value for versionId', retentionOpts.versionId) + } + } + + const method = 'PUT' + let query = 'retention' + + const headers: RequestHeaders = {} + if (retentionOpts.governanceBypass) { + headers['X-Amz-Bypass-Governance-Retention'] = true + } + + const builder = new xml2js.Builder({ rootName: 'Retention', renderOpts: { pretty: false }, headless: true }) + const params: Record = {} + + if (retentionOpts.mode) { + params.Mode = retentionOpts.mode + } + if (retentionOpts.retainUntilDate) { + params.RetainUntilDate = retentionOpts.retainUntilDate + } + if (retentionOpts.versionId) { + query += `&versionId=${retentionOpts.versionId}` + } + + let payload = builder.buildObject(params) + + headers['Content-MD5'] = toMd5(payload) + await this.makeRequestAsyncOmit({ method, bucketName, objectName, query, headers }, payload, [200, 204]) + } } diff --git a/src/internal/type.ts b/src/internal/type.ts index 130bfff2..29a12aaa 100644 --- a/src/internal/type.ts +++ b/src/internal/type.ts @@ -16,13 +16,13 @@ export type RequestHeaders = Record +export type IsoDate = string + diff --git a/src/minio.d.ts b/src/minio.d.ts index 13162a2b..8e26b00c 100644 --- a/src/minio.d.ts +++ b/src/minio.d.ts @@ -43,7 +43,9 @@ import type { SourceSelectionCriteria, Tag, VersionIdentificator, + RetentionOptions, Retention, EmptyObject, IsoDate } from './internal/type.ts' +import { EmptyObject } from './internal/type.ts' export * from './helpers.ts' export type { Region } from './internal/s3-endpoints.ts' @@ -52,7 +54,7 @@ export type { BucketItem, BucketItemCopy, BucketItemFromList, - BucketItemStat, + BucketItemStat, EmptyObject, IsoDate, BucketItemWithMetadata, BucketStream, ClientOptions, @@ -66,6 +68,7 @@ export type { NoResultCallback, PutObjectLegalHoldOptions, RemoveOptions, + RetentionOptions, Retention, ReplicaModifications, ReplicationConfig, ReplicationConfigOpts, @@ -111,13 +114,9 @@ export type LockUnit = RETENTION_VALIDITY_UNITS export type VersioningConfig = Record export type TagList = Record -export type EmptyObject = Record export type Lifecycle = LifecycleConfig | null | '' export type Lock = LockConfig | EmptyObject export type Encryption = EncryptionConfig | EmptyObject -export type Retention = RetentionOptions | EmptyObject -export type IsoDate = string - export interface PostPolicyResult { postURL: string formData: { @@ -152,13 +151,6 @@ export interface EncryptionRule { [key: string]: any } -export interface RetentionOptions { - versionId: string - mode?: RETENTION_MODES - retainUntilDate?: IsoDate - governanceBypass?: boolean -} - export interface LegalHoldOptions { versionId: string status: LEGAL_HOLD_STATUS @@ -375,15 +367,6 @@ export class Client extends TypedClient { removeIncompleteUpload(bucketName: string, objectName: string, callback: NoResultCallback): void removeIncompleteUpload(bucketName: string, objectName: string): Promise - putObjectRetention(bucketName: string, objectName: string, callback: NoResultCallback): void - putObjectRetention( - bucketName: string, - objectName: string, - retentionOptions: Retention, - callback: NoResultCallback, - ): void - putObjectRetention(bucketName: string, objectName: string, retentionOptions?: Retention): Promise - getObjectRetention( bucketName: string, objectName: string, diff --git a/src/minio.js b/src/minio.js index 71cddf7d..774a9124 100644 --- a/src/minio.js +++ b/src/minio.js @@ -110,7 +110,7 @@ export class Client extends TypedClient { return this.partSize } var partSize = this.partSize - for (;;) { + for (; ;) { // while(true) {...} throws linting error. // If partSize is big enough to accomodate the object size, then use it. if (partSize * 10000 > size) { @@ -1984,63 +1984,6 @@ export class Client extends TypedClient { }) } - putObjectRetention(bucketName, objectName, retentionOpts = {}, cb) { - if (!isValidBucketName(bucketName)) { - throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName) - } - if (!isValidObjectName(objectName)) { - throw new errors.InvalidObjectNameError(`Invalid object name: ${objectName}`) - } - if (!isObject(retentionOpts)) { - throw new errors.InvalidArgumentError('retentionOpts should be of type "object"') - } else { - if (retentionOpts.governanceBypass && !isBoolean(retentionOpts.governanceBypass)) { - throw new errors.InvalidArgumentError('Invalid value for governanceBypass', retentionOpts.governanceBypass) - } - if ( - retentionOpts.mode && - ![RETENTION_MODES.COMPLIANCE, RETENTION_MODES.GOVERNANCE].includes(retentionOpts.mode) - ) { - throw new errors.InvalidArgumentError('Invalid object retention mode ', retentionOpts.mode) - } - if (retentionOpts.retainUntilDate && !isString(retentionOpts.retainUntilDate)) { - throw new errors.InvalidArgumentError('Invalid value for retainUntilDate', retentionOpts.retainUntilDate) - } - if (retentionOpts.versionId && !isString(retentionOpts.versionId)) { - throw new errors.InvalidArgumentError('Invalid value for versionId', retentionOpts.versionId) - } - } - if (!isFunction(cb)) { - throw new TypeError('callback should be of type "function"') - } - - const method = 'PUT' - let query = 'retention' - - const headers = {} - if (retentionOpts.governanceBypass) { - headers['X-Amz-Bypass-Governance-Retention'] = true - } - - const builder = new xml2js.Builder({ rootName: 'Retention', renderOpts: { pretty: false }, headless: true }) - const params = {} - - if (retentionOpts.mode) { - params.Mode = retentionOpts.mode - } - if (retentionOpts.retainUntilDate) { - params.RetainUntilDate = retentionOpts.retainUntilDate - } - if (retentionOpts.versionId) { - query += `&versionId=${retentionOpts.versionId}` - } - - let payload = builder.buildObject(params) - - headers['Content-MD5'] = toMd5(payload) - this.makeRequest({ method, bucketName, objectName, query, headers }, payload, [200, 204], '', false, cb) - } - getObjectRetention(bucketName, objectName, getOpts, cb) { if (!isValidBucketName(bucketName)) { throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName) @@ -2498,7 +2441,6 @@ Client.prototype.getBucketLifecycle = promisify(Client.prototype.getBucketLifecy Client.prototype.removeBucketLifecycle = promisify(Client.prototype.removeBucketLifecycle) Client.prototype.setObjectLockConfig = promisify(Client.prototype.setObjectLockConfig) Client.prototype.getObjectLockConfig = promisify(Client.prototype.getObjectLockConfig) -Client.prototype.putObjectRetention = promisify(Client.prototype.putObjectRetention) Client.prototype.getObjectRetention = promisify(Client.prototype.getObjectRetention) Client.prototype.setBucketEncryption = promisify(Client.prototype.setBucketEncryption) Client.prototype.getBucketEncryption = promisify(Client.prototype.getBucketEncryption) @@ -2518,3 +2460,4 @@ Client.prototype.getObjectLegalHold = callbackify(Client.prototype.getObjectLega Client.prototype.setObjectLegalHold = callbackify(Client.prototype.setObjectLegalHold) Client.prototype.getBucketTagging = callbackify(Client.prototype.getBucketTagging) Client.prototype.getObjectTagging = callbackify(Client.prototype.getObjectTagging) +Client.prototype.putObjectRetention = callbackify(Client.prototype.putObjectRetention) From 9127d8dd461e283ec72ecc5e73630f8337133192 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 30 Oct 2023 02:25:03 +0800 Subject: [PATCH 2/8] lint fix --- src/internal/client.ts | 10 +++------- src/internal/type.ts | 37 ++++++++++++++++++------------------- src/minio.d.ts | 13 +++++++++---- src/minio.js | 2 +- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/internal/client.ts b/src/internal/client.ts index e61bc55b..47789ebc 100644 --- a/src/internal/client.ts +++ b/src/internal/client.ts @@ -1168,11 +1168,7 @@ export class TypedClient { return xmlParsers.parseTagging(body) } - async putObjectRetention( - bucketName: string, - objectName: string, - retentionOpts: Retention = {}, - ): Promise { + async putObjectRetention(bucketName: string, objectName: string, retentionOpts: Retention = {}): Promise { if (!isValidBucketName(bucketName)) { throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName) } @@ -1189,7 +1185,7 @@ export class TypedClient { retentionOpts.mode && ![RETENTION_MODES.COMPLIANCE, RETENTION_MODES.GOVERNANCE].includes(retentionOpts.mode) ) { - throw new errors.InvalidArgumentError('Invalid object retention mode ', retentionOpts.mode) + throw new errors.InvalidArgumentError(`Invalid object retention mode: ${retentionOpts.mode}`) } if (retentionOpts.retainUntilDate && !isString(retentionOpts.retainUntilDate)) { throw new errors.InvalidArgumentError('Invalid value for retainUntilDate', retentionOpts.retainUntilDate) @@ -1220,7 +1216,7 @@ export class TypedClient { query += `&versionId=${retentionOpts.versionId}` } - let payload = builder.buildObject(params) + const payload = builder.buildObject(params) headers['Content-MD5'] = toMd5(payload) await this.makeRequestAsyncOmit({ method, bucketName, objectName, query, headers }, payload, [200, 204]) diff --git a/src/internal/type.ts b/src/internal/type.ts index 29a12aaa..f6d9c737 100644 --- a/src/internal/type.ts +++ b/src/internal/type.ts @@ -16,13 +16,13 @@ export type RequestHeaders = Record export type IsoDate = string - diff --git a/src/minio.d.ts b/src/minio.d.ts index 8e26b00c..d93803a4 100644 --- a/src/minio.d.ts +++ b/src/minio.d.ts @@ -23,9 +23,11 @@ import type { BucketItemStat, BucketItemWithMetadata, BucketStream, + EmptyObject, ExistingObjectReplication, GetObjectLegalHoldOptions, IncompleteUploadedBucketItem, + IsoDate, ItemBucketMetadata, ItemBucketMetadataList, LegalHoldStatus, @@ -40,12 +42,12 @@ import type { ReplicationRuleFilter, ReplicationRuleStatus, ResultCallback, + Retention, + RetentionOptions, SourceSelectionCriteria, Tag, VersionIdentificator, - RetentionOptions, Retention, EmptyObject, IsoDate } from './internal/type.ts' -import { EmptyObject } from './internal/type.ts' export * from './helpers.ts' export type { Region } from './internal/s3-endpoints.ts' @@ -54,13 +56,15 @@ export type { BucketItem, BucketItemCopy, BucketItemFromList, - BucketItemStat, EmptyObject, IsoDate, + BucketItemStat, BucketItemWithMetadata, BucketStream, ClientOptions, + EmptyObject, ExistingObjectReplication, GetObjectLegalHoldOptions, IncompleteUploadedBucketItem, + IsoDate, ItemBucketMetadata, ItemBucketMetadataList, LegalHoldStatus, @@ -68,7 +72,6 @@ export type { NoResultCallback, PutObjectLegalHoldOptions, RemoveOptions, - RetentionOptions, Retention, ReplicaModifications, ReplicationConfig, ReplicationConfigOpts, @@ -77,6 +80,8 @@ export type { ReplicationRuleDestination, ReplicationRuleFilter, ReplicationRuleStatus, + Retention, + RetentionOptions, SourceSelectionCriteria, Tag, VersionIdentificator, diff --git a/src/minio.js b/src/minio.js index 774a9124..c35ae196 100644 --- a/src/minio.js +++ b/src/minio.js @@ -110,7 +110,7 @@ export class Client extends TypedClient { return this.partSize } var partSize = this.partSize - for (; ;) { + for (;;) { // while(true) {...} throws linting error. // If partSize is big enough to accomodate the object size, then use it. if (partSize * 10000 > size) { From 1ed96cf310f32f285d71951d5c8a15fdf3d44b64 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 30 Oct 2023 02:26:38 +0800 Subject: [PATCH 3/8] fix template string --- src/internal/client.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/internal/client.ts b/src/internal/client.ts index 47789ebc..19286fc1 100644 --- a/src/internal/client.ts +++ b/src/internal/client.ts @@ -1170,7 +1170,7 @@ export class TypedClient { async putObjectRetention(bucketName: string, objectName: string, retentionOpts: Retention = {}): Promise { if (!isValidBucketName(bucketName)) { - throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName) + throw new errors.InvalidBucketNameError(`Invalid bucket name: ${bucketName}`) } if (!isValidObjectName(objectName)) { throw new errors.InvalidObjectNameError(`Invalid object name: ${objectName}`) @@ -1179,7 +1179,7 @@ export class TypedClient { throw new errors.InvalidArgumentError('retentionOpts should be of type "object"') } else { if (retentionOpts.governanceBypass && !isBoolean(retentionOpts.governanceBypass)) { - throw new errors.InvalidArgumentError('Invalid value for governanceBypass', retentionOpts.governanceBypass) + throw new errors.InvalidArgumentError(`Invalid value for governanceBypass: ${retentionOpts.governanceBypass}`) } if ( retentionOpts.mode && @@ -1188,10 +1188,10 @@ export class TypedClient { throw new errors.InvalidArgumentError(`Invalid object retention mode: ${retentionOpts.mode}`) } if (retentionOpts.retainUntilDate && !isString(retentionOpts.retainUntilDate)) { - throw new errors.InvalidArgumentError('Invalid value for retainUntilDate', retentionOpts.retainUntilDate) + throw new errors.InvalidArgumentError(`Invalid value for retainUntilDate: ${retentionOpts.retainUntilDate}`) } if (retentionOpts.versionId && !isString(retentionOpts.versionId)) { - throw new errors.InvalidArgumentError('Invalid value for versionId', retentionOpts.versionId) + throw new errors.InvalidArgumentError(`Invalid value for versionId: ${retentionOpts.versionId}`) } } From 0ee8f79ed8674f8c9b2c9f37c8332032e2276b27 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 30 Oct 2023 02:31:25 +0800 Subject: [PATCH 4/8] fix test --- docs/API.md | 29 ++++++---------- tests/unit/test.js | 84 +++++++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 53 deletions(-) diff --git a/docs/API.md b/docs/API.md index 3d7e5c2c..5b8c8a80 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1420,18 +1420,17 @@ minioClient.removeIncompleteUpload('mybucket', 'photo.jpg', function (err) { -### putObjectRetention(bucketName, objectName [, retentionOpts] [, callback]) +### async putObjectRetention(bucketName, objectName [, retentionOpts]) Apply retention on an object. **Parameters** -| Param | Type | Description | -| --------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `bucketName` | _string_ | Name of the bucket. | -| `objectName` | _string_ | Name of the object. | -| `retentionOpts` | _object_ | Options for retention like : `{ governanceBypass:true/false ,mode:COMPLIANCE/GOVERNANCE, retainUntilDate: _date_ , versionId:"my-versionId" }` Default is `{}` (Optional) | -| `callback(err)` | _function_ | Callback function is called with non `null` value in case of error. If no callback is passed, a `Promise` is returned. | +| Param | Type | Description | +| --------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `bucketName` | _string_ | Name of the bucket. | +| `objectName` | _string_ | Name of the object. | +| `retentionOpts` | _object_ | Options for retention like : `{ governanceBypass:true/false ,mode:COMPLIANCE/GOVERNANCE, retainUntilDate: _date_ , versionId:"my-versionId" }` Default is `{}` (Optional) | **Example** Apply object retention on an object @@ -1445,17 +1444,11 @@ expirationDate.setDate(expirationDate.getDate() + 1) expirationDate.setUTCHours(0, 0, 0, 0) //Should be start of the day.(midnight) const versionId = 'e67b4b08-144d-4fc4-ba15-43c3f7f9ba74' -const objRetPromise = minioClient.putObjectRetention( - bucketName, - objectName, - { Mode: 'GOVERNANCE', retainUntilDate: retainUntilDate.toISOString(), versionId: versionId }, - function (err) { - if (err) { - return console.log(err) - } - console.log('Success') - }, -) +const objRetPromise = await minioClient.putObjectRetention(bucketName, objectName, { + Mode: 'GOVERNANCE', + retainUntilDate: retainUntilDate.toISOString(), + versionId: versionId, +}) ``` diff --git a/tests/unit/test.js b/tests/unit/test.js index ed19d368..cf4e5429 100644 --- a/tests/unit/test.js +++ b/tests/unit/test.js @@ -1184,54 +1184,68 @@ describe('Client', function () { } }) it('should fail on empty bucket', (done) => { - try { - client.putObjectRetention('', '', {}, function () {}) - } catch (e) { - done() - } + client.putObjectRetention('', '', {}, function (err) { + if (err) { + done() + } else { + done(new Error('expecting error')) + } + }) }) it('should fail on null object', (done) => { - try { - client.putObjectRetention('my-bucket', null, {}, function () {}) - } catch (e) { - done() - } + client.putObjectRetention('my-bucket', null, {}, function (err) { + if (err) { + done() + } else { + done(new Error('expecting error')) + } + }) }) it('should fail on empty object', (done) => { - try { - client.putObjectRetention('my-bucket', '', {}, function () {}) - } catch (e) { - done() - } + client.putObjectRetention('my-bucket', '', {}, function (err) { + if (err) { + done() + } else { + done(new Error('expecting error')) + } + }) }) it('should fail on passing invalid mode ', (done) => { - try { - client.putObjectRetention('my-bucket', 'my-object', { mode: 'invalid_mode' }, function () {}) - } catch (e) { - done() - } + client.putObjectRetention('my-bucket', 'my-object', { mode: 'invalid_mode' }, function (err) { + if (err) { + done() + } else { + done(new Error('expecting error')) + } + }) }) it('should fail on passing invalid governanceBypass ', (done) => { - try { - client.putObjectRetention('my-bucket', 'my-object', { governanceBypass: 'nonbool' }, function () {}) - } catch (e) { - done() - } + client.putObjectRetention('my-bucket', 'my-object', { governanceBypass: 'nonbool' }, function (err) { + if (err) { + done() + } else { + done(new Error('expecting error')) + } + }) }) it('should fail on passing invalid (null) retainUntilDate ', (done) => { - try { - client.putObjectRetention('my-bucket', 'my-object', { retainUntilDate: 12345 }, function () {}) - } catch (e) { - done() - } + client.putObjectRetention('my-bucket', 'my-object', { retainUntilDate: 12345 }, function (err) { + if (err) { + done() + } else { + done(new Error('expecting error')) + } + }) }) it('should fail on passing invalid versionId ', (done) => { - try { - client.putObjectRetention('my-bucket', { versionId: 'COMPLIANCE' }, function () {}) - } catch (e) { - done() - } + client.putObjectRetention('my-bucket', { versionId: 'COMPLIANCE' }, function (err) { + if (err) { + done() + } else { + done(new Error('expecting error')) + } + }) }) }) }) From 06059be59ced55a4d152db26a3d8c865f43dd1f7 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 30 Oct 2023 02:32:55 +0800 Subject: [PATCH 5/8] fix example --- docs/API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/API.md b/docs/API.md index 5b8c8a80..474bdcc7 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1444,7 +1444,7 @@ expirationDate.setDate(expirationDate.getDate() + 1) expirationDate.setUTCHours(0, 0, 0, 0) //Should be start of the day.(midnight) const versionId = 'e67b4b08-144d-4fc4-ba15-43c3f7f9ba74' -const objRetPromise = await minioClient.putObjectRetention(bucketName, objectName, { +await minioClient.putObjectRetention(bucketName, objectName, { Mode: 'GOVERNANCE', retainUntilDate: retainUntilDate.toISOString(), versionId: versionId, From 3ee5b80e133895ddbca14d5ff997900873cb9c90 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 30 Oct 2023 02:34:08 +0800 Subject: [PATCH 6/8] fix test --- tests/unit/test.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/unit/test.js b/tests/unit/test.js index cf4e5429..422fe893 100644 --- a/tests/unit/test.js +++ b/tests/unit/test.js @@ -1177,11 +1177,13 @@ describe('Client', function () { describe('putObjectRetention(bucket, objectName, retentionConfig, callback)', () => { it('should fail on null bucket', (done) => { - try { - client.putObjectRetention(null, '', {}, function () {}) - } catch (e) { - done() - } + client.putObjectRetention(null, '', {}, function (err) { + if (err) { + done() + } else { + done(new Error('expecting error')) + } + }) }) it('should fail on empty bucket', (done) => { client.putObjectRetention('', '', {}, function (err) { From 7157f32c86dab06790c529a69a5e6ccc9f45ffcf Mon Sep 17 00:00:00 2001 From: Trim21 Date: Thu, 2 Nov 2023 19:01:24 +0800 Subject: [PATCH 7/8] Update put-object-retention.js --- examples/put-object-retention.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/examples/put-object-retention.js b/examples/put-object-retention.js index 55f6d920..d57b958f 100644 --- a/examples/put-object-retention.js +++ b/examples/put-object-retention.js @@ -17,9 +17,9 @@ // Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are // dummy values, please replace them with original values. -var Minio = require('minio') +import * as Minio from 'minio' -var s3Client = new Minio.Client({ +const s3Client = new Minio.Client({ endPoint: 's3.amazonaws.com', accessKey: 'YOUR-ACCESSKEYID', secretKey: 'YOUR-SECRETACCESSKEY', @@ -33,15 +33,8 @@ expirationDate.setDate(expirationDate.getDate() + 1) expirationDate.setUTCHours(0, 0, 0, 0) //Should be start of the day.(midnight) const versionId = 'my-versionId' -const objRetPromise = s3Client.putObjectRetention(bucketName, objectName, { +await s3Client.putObjectRetention(bucketName, objectName, { mode: 'GOVERNANCE', retainUntilDate: expirationDate.toISOString(), versionId: versionId, }) -objRetPromise - .then(() => { - console.log('Success') - }) - .catch((e) => { - console.log(' Error', e) - }) From 2917862777990b1347a44d6de7a33cd6e77a523d Mon Sep 17 00:00:00 2001 From: Trim21 Date: Fri, 3 Nov 2023 22:49:43 +0800 Subject: [PATCH 8/8] fix lint warning --- src/internal/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/client.ts b/src/internal/client.ts index 19286fc1..1ae95cfe 100644 --- a/src/internal/client.ts +++ b/src/internal/client.ts @@ -1204,7 +1204,7 @@ export class TypedClient { } const builder = new xml2js.Builder({ rootName: 'Retention', renderOpts: { pretty: false }, headless: true }) - const params: Record = {} + const params: Record = {} if (retentionOpts.mode) { params.Mode = retentionOpts.mode