Skip to content

Commit

Permalink
refactor setObjectLegalHold and getObjectLegalHold api
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx committed Aug 2, 2023
1 parent 83fb55e commit c5d88db
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 264 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ The full API Reference is available here.
- [put-object-tagging.js](https://github.com/minio/minio-js/blob/master/examples/put-object-tagging.js)
- [get-object-tagging.js](https://github.com/minio/minio-js/blob/master/examples/get-object-tagging.js)
- [remove-object-tagging.js](https://github.com/minio/minio-js/blob/master/examples/remove-object-tagging.js)
- [set-object-legal-hold.js](https://github.com/minio/minio-js/blob/master/examples/set-object-legalhold.js)
- [get-object-legal-hold.js](https://github.com/minio/minio-js/blob/master/examples/get-object-legal-hold.js)
- [set-object-legal-hold.js](https://github.com/minio/minio-js/blob/master/examples/set-object-legalhold.mjs)
- [get-object-legal-hold.js](https://github.com/minio/minio-js/blob/master/examples/get-object-legal-hold.mjs)
- [compose-object.js](https://github.com/minio/minio-js/blob/master/examples/compose-object.js)
- [select-object-content.js](https://github.com/minio/minio-js/blob/master/examples/select-object-content.js)

Expand Down
62 changes: 20 additions & 42 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1606,89 +1606,67 @@ minioClient.getObjectTagging(

<a name="getObjectLegalHold"></a>

### getObjectLegalHold(bucketName, objectName, getOpts [, callback])
### getObjectLegalHold(bucketName, objectName, getOpts)

Get legal hold on an object.

**Parameters**

| Param | Type | Description |
| --------------- | ---------- | ---------------------------------------------------------------------------------------------------------------------- |
| `bucketName` | _string_ | Name of the bucket. |
| `objectName` | _string_ | Name of the object. |
| `getOpts` | _object_ | Legal hold configuration options. e.g `{versionId:'my-version-uuid'}` defaults to `{}` . |
| `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. |
| `getOpts` | _object_ | Legal hold configuration options. e.g `{versionId:'my-version-uuid'}` defaults to `{}` . |

**Example 1**

Get Legal hold of an object.

```js
minioClient.getObjectLegalHold('bucketName', 'objectName', {}, function (err, res) {
if (err) {
return console.log('Unable to get legal hold config for the object', err.message)
}
console.log('Success', res)
})
const legalholdStatus = await minioClient.getObjectLegalHold('bucketName', 'objectName')
```

**Example 2**

Get Legal hold of an object with versionId.

```js
minioClient.getObjectLegalHold('bucketName', 'objectName', { versionId: 'my-obj-version-uuid' }, function (err, res) {
if (err) {
return console.log('Unable to get legal hold config for the object', err.message)
}
console.log('Success', res)
const legalholdStatus = await minioClient.getObjectLegalHold('bucketName', 'objectName', {
versionId: 'my-obj-version-uuid',
})
```

<a name="setObjectLegalHold"></a>

### setObjectLegalHold(bucketName, objectName, [,setOpts, callback])
### setObjectLegalHold(bucketName, objectName, [,setOpts])

Set legal hold on an object.

**Parameters**

| Param | Type | Description |
| --------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| `bucketName` | _string_ | Name of the bucket. |
| `objectName` | _string_ | Name of the object. |
| `setOpts` | _object_ | Legal hold configuration options to set. e.g `{versionId:'my-version-uuid', status:'ON or OFF'}` defaults to `{status:'ON'}` if not passed. |
| `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. |
| `setOpts` | _object_ | Legal hold configuration options to set. e.g `{versionId:'my-version-uuid', status:'ON or OFF'}` defaults to `{status:'ON'}` if not passed. |

**Example 1**

Set Legal hold of an object.

```js
minioClient.setObjectLegalHold('bucketName', 'objectName', { Status: 'ON' }, function (err, res) {
if (err) {
return console.log('Unable to set legal hold config for the object', err.message)
}
console.log('Success')
})
const legalholdStatus = await minioClient.setObjectLegalHold('bucketName', 'objectName', { Status: 'ON' })
```

**Example 2**

Set Legal hold of an object with versionId.

```js
minioClient.setObjectLegalHold(
'bucketName',
'objectName',
{ Status: 'ON', versionId: 'my-obj-version-uuid' },
function (err, res) {
if (err) {
return console.log('Unable to set legal hold config for the object version', err.message)
}
console.log('Success')
},
)
const legalholdStatus = await minioClient.setObjectLegalHold('bucketName', 'objectName', {
Status: 'ON',
versionId: 'my-obj-version-uuid',
})
```

<a name="composeObject"></a>
Expand Down
56 changes: 0 additions & 56 deletions examples/get-object-legal-hold.js

This file was deleted.

57 changes: 57 additions & 0 deletions examples/get-object-legal-hold.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* MinIO Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
import * as Minio from 'minio'

const s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY',
})

s3Client.getObjectLegalHold('test-l-bucket', 'inspect-data.enc', (e, res) => {
if (e) {
console.log('CB Error 1', e.message)
return
}
console.log('CB Success Res', res)
})

s3Client.getObjectLegalHold('test-l-bucket', null, (e, res) => {
if (e) {
console.log('CB Error 2', e.message)
return
}
console.log('CB Success Res 2', res)
})

try {
const buckets = await s3Client.getObjectLegalHold('test-l-bucket', 'inspect-data.enc', { versionId: 1234 })
console.log('Default Success', buckets)
} catch (err) {
console.log('Error::', err.message)
}
/*
// with version Id
try {
const buckets = await s3Client.getObjectLegalHold(null, 'inspect-data.enc', {versionId:'d24cbb1b-81c2-449d-b6d0-8a5f19b66b05'})
console.log('Version Success', buckets)
} catch (err) {
console.log(err.message)
}
*/
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,29 @@
// 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',
})

//Set legal hold config of an object.
s3Client.setObjectLegalHold('bucketName', 'objectName', { status: 'ON' }, function (err, res) {
if (err) {
return console.log('Unable to set legal hold config for the object', err)
}
try {
//Set legal hold config of an object.
await s3Client.setObjectLegalHold('bucketname', 'objectName')
console.log('Success')
})
} catch (err) {
console.log(err.message)
}

//Set legal hold config of an object with versionId.
s3Client.setObjectLegalHold(
'bucketName',
'objectName',
{ status: 'ON', versionId: 'my-obj-version-uuid' },
function (err, res) {
if (err) {
return console.log('Unable to set legal hold config for the object version', err)
}
console.log('Success')
},
)
try {
//Set legal hold config of an object version.
await s3Client.setObjectLegalHold('bucketname', 'objectName', {
status: 'ON',
versionId: '67d3a60d-e837-4218-96d3-44733cdc7c6f',
})
console.log('Success')
} catch (err) {
console.log(err.message)
}
Loading

0 comments on commit c5d88db

Please sign in to comment.