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 Object lock config APIs #919

Merged
merged 4 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The full API Reference is available here.
* [`listIncompleteUploads`](https://docs.min.io/docs/javascript-client-api-reference#listIncompleteUploads)
* [`getBucketVersioning`](https://docs.min.io/docs/javascript-client-api-reference#getBucketVersioning)
* [`setBucketVersioning`](https://docs.min.io/docs/javascript-client-api-reference#setBucketVersioning)
* [`getObjectLockConfig`](https://docs.min.io/docs/javascript-client-api-reference#getObjectLockConfig)
* [`setObjectLockConfig`](https://docs.min.io/docs/javascript-client-api-reference#setObjectLockConfig)

### API Reference : File Object Operations

Expand Down Expand Up @@ -176,6 +178,8 @@ The full API Reference is available here.
* [list-incomplete-uploads.js](https://github.com/minio/minio-js/blob/master/examples/list-incomplete-uploads.js)
* [get-bucket-versioning.js](https://github.com/minio/minio-js/blob/master/examples/get-bucket-versioning.js)
* [set-bucket-versioning.js](https://github.com/minio/minio-js/blob/master/examples/set-bucket-versioning.js)
* [get-object-lock-config.js](https://github.com/minio/minio-js/blob/master/examples/get-object-lock-config.js)
* [set-object-lock-config.js](https://github.com/minio/minio-js/blob/master/examples/set-object-lock-config.js)

#### Full Examples : File Object Operations
* [fput-object.js](https://github.com/minio/minio-js/blob/master/examples/fput-object.js)
Expand Down
75 changes: 74 additions & 1 deletion docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var s3Client = new Minio.Client({
## 2. Bucket operations
<a name="makeBucket"></a>

### makeBucket(bucketName, region[, callback])
### makeBucket(bucketName, region[, makeOpts , callback])

Creates a new bucket.

Expand All @@ -124,6 +124,7 @@ __Parameters__
|---|---|---|
|`bucketName` | _string_ | Name of the bucket. |
| `region` | _string_ | Region where the bucket is created. This parameter is optional. Default value is us-east-1. |
| `makeOpts` | _object_ | Options to create a bucket. e.g `{ObjectLocking:true}` (Optional)
|`callback(err)` |_function_ | Callback function with `err` as the error argument. `err` is null if the bucket is successfully created. If no callback is passed, a `Promise` is returned. |


Expand All @@ -137,6 +138,16 @@ minioClient.makeBucket('mybucket', 'us-east-1', function(err) {
})
```

__Example 1__
Create a bucket with object locking enabled.

```js
minioClient.makeBucket('mybucket', 'us-east-1', { ObjectLocking:true }, function(err) {
if (err) return console.log('Error creating bucket with object lock.', err)
console.log('Bucket created successfully in "us-east-1" and enabled object lock')
})
```

<a name="listBuckets"></a>
### listBuckets([callback])

Expand Down Expand Up @@ -451,6 +462,68 @@ minioClient.setBucketVersioning('bucketname',versioningConfig, function (err){
})
```

<a name="setObjectLockConfig"></a>
### setObjectLockConfig(bucketName, lockConfig [, callback])

Set Object lock config on a Bucket

__Parameters__


| Param | Type | Description |
| ---| ---|---|
| `bucketname` | _string_ | Name of the bucket. |
| `lockConfig` | _object_ | Lock Configuration can be either `{}` to reset or object with all of the following key/value pairs: `{mode: ["COMPLIANCE"/'GOVERNANCE'], unit: ["Days"/"Years"], validity: <a-valid-number-for-unit>}` |
|`callback(err)` | _function_ | Callback is called with `err` in case of error.|

__Example 1__

```js
s3Client.setObjectLockConfig('my-bucketname', {mode:"COMPLIANCE", unit:'Days', validity:10 }, function (err){
if (err) {
return console.log(err)
}
console.log("Success")
})
```

__Example 2__
To reset/remove object lock config on a bucket.

```js
s3Client.setObjectLockConfig('my-bucketname', {}, function (err){
if (err) {
return console.log(err)
}
console.log("Success")
})
```


<a name="getObjectLockConfig"></a>
### getObjectLockConfig(bucketName [, callback])

Get Lock config on a Bucket

__Parameters__


| Param | Type | Description |
| ---| ---|---|
| `bucketname` | _string_ | Name of the bucket. |
|`callback(err, lockConfig)` | _function_ | Callback is called with `err` in case of error. else it is called with lock configuration |

__Example __
Get object lock configuration on a Bucket

```js
s3Client.getObjectLockConfig('my-bucketname', function (err, lockConfig){
if (err) {
return console.log(err)
}
console.log(lockConfig)
})
```
## 3. Object operations

<a name="getObject"></a>
Expand Down
34 changes: 34 additions & 0 deletions examples/get-object-lock-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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'
})


s3Client.getObjectLockConfig('my-bucketname', function (err,lockConfig){
if (err) {
return console.log(err)
}
console.log(lockConfig)
})
10 changes: 8 additions & 2 deletions examples/make-bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
// dummy values, please replace them with original values.

var Minio = require('minio')

Expand All @@ -31,3 +31,9 @@ s3Client.makeBucket('my-bucketname', 'us-west-1', function(e) {
}
console.log("Success")
})

// Create a bucket with object locking enabled.
s3Client.makeBucket('mybucket', 'us-east-1', { ObjectLocking:true }, function(err) {
if (err) return console.log('Error creating bucket with lock .', err)
console.log('Bucket created successfully in "us-east-1" and enabled object lock')
})
34 changes: 34 additions & 0 deletions examples/reset-object-lock-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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'
})

//Example to reset/remove object lock config.
s3Client.setObjectLockConfig('my-bucketname', {}, function (err){
if (err) {
return console.log(err)
}
console.log("Success")
})
42 changes: 42 additions & 0 deletions examples/set-object-lock-config.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 Object lock on a bucket
s3Client.setObjectLockConfig('my-bucketname', {mode:"COMPLIANCE",unit:'Days', validity:10 }, function (err){
if (err) {
return console.log(err)
}
console.log("Success")
})

//To reset/remove object lock config.
s3Client.setObjectLockConfig('my-bucketname', {}, function (err){
if (err) {
return console.log(err)
}
console.log("Success")
})
prakashsvmx marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 11 additions & 1 deletion src/main/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,4 +368,14 @@ export function sanitizeETag(etag='') {
var replaceChars = {'"':'','&quot;':'','&#34;':'','&QUOT;':'','&#x00022':''}
return etag.replace(/^("|&quot;|&#34;)|("|&quot;|&#34;)$/g, m => replaceChars[m])

}
}

export const RETENTION_MODES ={
GOVERNANCE:"GOVERNANCE",
COMPLIANCE:"COMPLIANCE"
}

export const RETENTION_VALIDITY_UNITS={
DAYS:"Days",
YEARS:"Years"
}
Loading