Skip to content

Commit 7efb0ac

Browse files
authored
refactor removeBucketReplication api to ts (#1185)
* refactor removeBucketReplication api to ts * address review comments * update doc
1 parent f6a34ca commit 7efb0ac

File tree

7 files changed

+44
-35
lines changed

7 files changed

+44
-35
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ The full API Reference is available here.
166166

167167
#### Full Examples : Bucket Operations
168168

169-
- [list-buckets.js](https://github.com/minio/minio-js/blob/master/examples/list-buckets.js)
169+
- [list-buckets.mjs](https://github.com/minio/minio-js/blob/master/examples/list-buckets.mjs)
170170
- [list-objects.js](https://github.com/minio/minio-js/blob/master/examples/list-objects.js)
171171
- [list-objects-v2.js](https://github.com/minio/minio-js/blob/master/examples/list-objects-v2.js)
172172
- [list-objects-v2-with-metadata.js](https://github.com/minio/minio-js/blob/master/examples/list-objects-v2-with-metadata.js) (Extension)
@@ -186,7 +186,7 @@ The full API Reference is available here.
186186
- [set-object-lock-config.js](https://github.com/minio/minio-js/blob/master/examples/set-object-lock-config.js)
187187
- [set-bucket-replication.js](https://github.com/minio/minio-js/blob/master/examples/set-bucket-replication.js)
188188
- [get-bucket-replication.js](https://github.com/minio/minio-js/blob/master/examples/get-bucket-replication.js)
189-
- [remove-bucket-replication.js](https://github.com/minio/minio-js/blob/master/examples/remove-bucket-replication.js)
189+
- [remove-bucket-replication.mjs](https://github.com/minio/minio-js/blob/master/examples/remove-bucket-replication.mjs)
190190

191191
#### Full Examples : File Object Operations
192192

docs/API.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Please refer to: [list-buckets.mjs](..%2Fexamples%2Flist-buckets.mjs)
206206

207207
```js
208208
try {
209-
const buckets = await s3Client.listBuckets()
209+
const buckets = await minioClient.listBuckets()
210210
console.log('Success', buckets)
211211
} catch (err) {
212212
console.log(err.message)
@@ -581,26 +581,26 @@ minioClient.getBucketReplication('bucketname', function (err, replicationConfig)
581581

582582
<a name="removeBucketReplication"></a>
583583

584-
### removeBucketReplication(bucketName, callback)
584+
### removeBucketReplication(bucketName)
585585

586586
Remove replication config of a Bucket
587587

588588
**Parameters**
589589

590-
| Param | Type | Description |
591-
| --------------- | ---------- | ----------------------------------------------- |
592-
| `bucketName` | _string_ | Name of the bucket. |
593-
| `callback(err)` | _function_ | Callback is called with `err` in case of error. |
590+
| Param | Type | Description |
591+
| ------------ | -------- | ------------------- |
592+
| `bucketName` | _string_ | Name of the bucket. |
594593

595594
**Example**
595+
Please refer to : [remove-bucket-replication.mjs](..%2Fexamples%2Fremove-bucket-replication.mjs)
596596

597597
```js
598-
minioClient.removeBucketReplication('bucketname', function (err, replicationConfig) {
599-
if (err) {
600-
return console.log(err)
601-
}
598+
try {
599+
await minioClient.removeBucketReplication('source-bucket')
602600
console.log('Success')
603-
})
601+
} catch (err) {
602+
console.log(err.message)
603+
}
604604
```
605605

606606
<a name="setBucketTagging"></a>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are
1818
// dummy values, please replace them with original values.
1919

20-
var Minio = require('minio')
20+
import * as Minio from 'minio'
2121

22-
var s3Client = new Minio.Client({
22+
const s3Client = new Minio.Client({
2323
endPoint: 's3.amazonaws.com',
2424
accessKey: 'YOUR-ACCESSKEYID',
2525
secretKey: 'YOUR-SECRETACCESSKEY',
2626
})
2727

28-
s3Client.removeBucketReplication('bucketname', function (err) {
29-
if (err) {
30-
return console.log(err)
31-
}
28+
try {
29+
await s3Client.removeBucketReplication('source-bucket')
3230
console.log('Success')
33-
})
31+
} catch (err) {
32+
console.log(err.message)
33+
}

src/internal/client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,4 +887,15 @@ export class TypedClient {
887887
const xmlResult = await readAsString(httpRes)
888888
return xmlParsers.parseListBucket(xmlResult)
889889
}
890+
891+
async removeBucketReplication(bucketName: string): Promise<void>
892+
removeBucketReplication(bucketName: string, callback: NoResultCallback): void
893+
async removeBucketReplication(bucketName: string): Promise<void> {
894+
if (!isValidBucketName(bucketName)) {
895+
throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName)
896+
}
897+
const method = 'DELETE'
898+
const query = 'replication'
899+
await this.makeRequestAsyncOmit({ method, bucketName, query }, '', [200, 204], '')
900+
}
890901
}

src/minio.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ export class Client extends TypedClient {
290290
getBucketReplication(bucketName: string, callback: ResultCallback<ReplicationConfig>): void
291291
getBucketReplication(bucketName: string): Promise<ReplicationConfig>
292292

293-
removeBucketReplication(bucketName: string, callback: NoResultCallback): void
294-
removeBucketReplication(bucketName: string): Promise<void>
295-
296293
// Object operations
297294
getObject(bucketName: string, objectName: string, callback: ResultCallback<ReadableStream>): void
298295
getObject(bucketName: string, objectName: string): Promise<ReadableStream>

src/minio.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,15 +2388,6 @@ export class Client extends TypedClient {
23882388
})
23892389
}
23902390

2391-
removeBucketReplication(bucketName, cb) {
2392-
if (!isValidBucketName(bucketName)) {
2393-
throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName)
2394-
}
2395-
const method = 'DELETE'
2396-
const query = 'replication'
2397-
this.makeRequest({ method, bucketName, query }, '', [200, 204], '', false, cb)
2398-
}
2399-
24002391
getObjectLegalHold(bucketName, objectName, getOpts = {}, cb) {
24012392
if (!isValidBucketName(bucketName)) {
24022393
throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName)
@@ -2853,7 +2844,6 @@ Client.prototype.getBucketEncryption = promisify(Client.prototype.getBucketEncry
28532844
Client.prototype.removeBucketEncryption = promisify(Client.prototype.removeBucketEncryption)
28542845
Client.prototype.setBucketReplication = promisify(Client.prototype.setBucketReplication)
28552846
Client.prototype.getBucketReplication = promisify(Client.prototype.getBucketReplication)
2856-
Client.prototype.removeBucketReplication = promisify(Client.prototype.removeBucketReplication)
28572847
Client.prototype.setObjectLegalHold = promisify(Client.prototype.setObjectLegalHold)
28582848
Client.prototype.getObjectLegalHold = promisify(Client.prototype.getObjectLegalHold)
28592849
Client.prototype.composeObject = promisify(Client.prototype.composeObject)
@@ -2863,3 +2853,4 @@ Client.prototype.selectObjectContent = promisify(Client.prototype.selectObjectCo
28632853
Client.prototype.removeObject = callbackify(Client.prototype.removeObject)
28642854
Client.prototype.removeBucket = callbackify(Client.prototype.removeBucket)
28652855
Client.prototype.listBuckets = callbackify(Client.prototype.listBuckets)
2856+
Client.prototype.removeBucketReplication = callbackify(Client.prototype.removeBucketReplication)

tests/unit/test.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,14 +1393,24 @@ describe('Client', function () {
13931393
describe('removeBucketReplication(bucketName, callback)', () => {
13941394
it('should fail on null bucket', (done) => {
13951395
try {
1396-
client.removeBucketReplication(null, {}, function () {})
1396+
client.removeBucketReplication(null, function (err) {
1397+
if (err) {
1398+
return done()
1399+
}
1400+
done(new Error('callback should receive error'))
1401+
})
13971402
} catch (e) {
13981403
done()
13991404
}
14001405
})
14011406
it('should fail on empty bucket', (done) => {
14021407
try {
1403-
client.removeBucketReplication('', {}, function () {})
1408+
client.removeBucketReplication('', function (err) {
1409+
if (err) {
1410+
return done()
1411+
}
1412+
done(new Error('callback should receive error'))
1413+
})
14041414
} catch (e) {
14051415
done()
14061416
}

0 commit comments

Comments
 (0)