Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get/set legal hold APIs #925

Merged
merged 5 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,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)

#### Full Examples : Presigned Operations
* [presigned-getobject.js](https://github.com/minio/minio-js/blob/master/examples/presigned-getobject.js)
Expand Down
100 changes: 92 additions & 8 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ var s3Client = new Minio.Client({
| [`setBucketLifecycle`](#setBucketLifecycle) | [`putObjectTagging`](#putObjectTagging) |
| [`getBucketLifecycle`](#getBucketLifecycle) | [`removeObjectTagging`](#removeObjectTagging) |
| [`removeBucketLifecycle`](#removeBucketLifecycle) | [`getObjectTagging`](#getObjectTagging) |
| [`setObjectLockConfig`](#setObjectLockConfig) | [`putObjectRetention`](#putObjectRetention) |
| [`getObjectLockConfig`](#getObjectLockConfig) | [`getObjectRetention`](#getObjectRetention) |
|[`setBucketEncryption`](#setBucketEncryption) | |
|[`getBucketEncryption`](#getBucketEncryption) | |
|[`removeBucketEncryption`](#removeBucketEncryption) | |
| [`removeBucketLifecycle`](#removeBucketLifecycle) | |
| [`setObjectLockConfig`](#setObjectLockConfig) | [`getObjectLegalHold`](#getObjectLegalHold) |
| [`getBucketEncryption`](#getBucketEncryption) | [`setObjectLegalHold`](#setObjectLegalHold) |
| [`getObjectLockConfig`](#getObjectLockConfig) | [`getObjectLegalHold`](#getObjectLegalHold) |
| [`getBucketEncryption`](#getBucketEncryption) | [`setObjectLegalHold`](#setObjectLegalHold) |
| [`setBucketEncryption`](#setBucketEncryption) | |
| [`removeBucketEncryption`](#removeBucketEncryption) | |
| [`setBucketReplication`](#setBucketReplication)| |
| [`getBucketReplication`](#getBucketReplication)| |
| [`removeBucketReplication`](#removeBucketReplication)| |


| [`setBucketEncryption`](#setBucketEncryption) | |
| [`getBucketEncryption`](#getBucketEncryption) | |
| [`removeBucketEncryption`](#removeBucketEncryption) | |


## 1. Constructor
Expand Down Expand Up @@ -1590,6 +1591,89 @@ minioClient.getObjectTagging('bucketname', 'object-name', {versionId:"my-object-
})
```

<a name="getObjectLegalHold"></a>
### getObjectLegalHold(bucketName, objectName, getOpts [, callback])

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. |


__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)
})
```

__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)
prakashsvmx marked this conversation as resolved.
Show resolved Hide resolved
})
```


<a name="setObjectLegalHold"></a>
### setObjectLegalHold(bucketName, objectName, [,setOpts, callback])

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. |


__Example__
prakashsvmx marked this conversation as resolved.
Show resolved Hide resolved

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')
})
```

__Example 1__

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')
})
```

## 4. Presigned operations

Presigned URLs are generated for temporary download/upload access to private objects.
Expand Down
54 changes: 54 additions & 0 deletions examples/get-object-legal-hold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.

var Minio = require('minio')

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

//Get Legalhold config
s3Client.getObjectLegalHold('bucketName', 'objectName', {}, function(err, res) {
if (err) {
return console.log('Unable to get legal hold config for the object', err.message) // Print only the message.
}
console.log(res)
})

//With versionId
s3Client.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) // Print only the message.
}
console.log(res)
})

//Promise based version:
const objectLegalHoldPromise = s3Client.getObjectLegalHold('bucketName', 'objectName', { versionId:'my-obj-version-uuid' })
objectLegalHoldPromise.then((data) => {
console.log("Success...", data)
})
.catch((e)=>{
// Print only the error message. if called on an object without object lock config.
// e.g: "The specified object does not have a ObjectLock configuration"
console.log(e.message)

})
42 changes: 42 additions & 0 deletions examples/set-object-legal-hold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.

var Minio = require('minio')

var 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)
}
console.log('Success')
})

//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')
})
5 changes: 5 additions & 0 deletions src/main/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,8 @@ export const RETENTION_VALIDITY_UNITS={
DAYS:"Days",
YEARS:"Years"
}

export const LEGAL_HOLD_STATUS={
ENABLED:"ON",
DISABLED:"OFF"
}
Loading