Skip to content

Commit

Permalink
Address review comments by Kannappan and Ersan
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx committed Apr 12, 2021
1 parent 8ea7d25 commit d64ae74
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 7 deletions.
10 changes: 5 additions & 5 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ 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)
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')
})
```
Expand Down Expand Up @@ -473,13 +473,13 @@ __Parameters__
| Param | Type | Description |
| ---| ---|---|
| `bucketname` | _string_ | Name of the bucket. |
| `lockConfig` | _object_ | Versioning Configuration can be either `{}` to reset or object with all of the following keys: `{mode , unit , validity:number}` `mode` - accepts either COMPLIANCE or COMPLIANCE , `unit` accepts either Days or Years `validity` accepts any valid number in respective unit specified |
| `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){
s3Client.setObjectLockConfig('my-bucketname', {mode:"COMPLIANCE", unit:'Days', validity:10 }, function (err){
if (err) {
return console.log(err)
}
Expand Down Expand Up @@ -514,14 +514,14 @@ __Parameters__
|`callback(err, lockConfig)` | _function_ | Callback is called with `err` in case of error. else it is called with lock configuration |

__Example __
Get object lock on a Bucket
Get object lock configuration on a Bucket

```js
s3Client.getObjectLockConfig('my-bucketname', function (err, lockConfig){
if (err) {
return console.log(err)
}
console.log("Success",lockConfig)
console.log(lockConfig)
})
```
## 3. Object operations
Expand Down
2 changes: 1 addition & 1 deletion examples/get-object-lock-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ s3Client.getObjectLockConfig('my-bucketname', function (err,lockConfig){
if (err) {
return console.log(err)
}
console.log("Success", lockConfig)
console.log(lockConfig)
})
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")
})
6 changes: 5 additions & 1 deletion src/main/minio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,11 @@ export class Client {
const builder = new xml2js.Builder({rootName:'ObjectLockConfiguration', renderOpts:{'pretty':false}, headless:true})
const payload = builder.buildObject(config)

this.makeRequest({method, bucketName, query}, payload, 200, '', false, cb)
const headers = {}
const md5digest = Crypto.createHash('md5').update(payload).digest()
headers['Content-MD5'] = md5digest.toString('base64')

this.makeRequest({method, bucketName, query, headers}, payload, 200, '', false, cb)
}

getObjectLockConfig(bucketName, cb) {
Expand Down
7 changes: 7 additions & 0 deletions src/test/functional/functional-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ describe('functional tests', function() {
} else {
playConfig.useSSL = true
}
playConfig={
useSSL:false,
endPoint:"localhost",
port:9000,
accessKey:"minio",
secretKey:"minio123"
}
// dataDir is falsy if we need to generate data on the fly. Otherwise, it will be
// a directory with files to read from, i.e. /mint/data.
var dataDir = process.env['MINT_DATA_DIR']
Expand Down

0 comments on commit d64ae74

Please sign in to comment.