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

refactor removeBucketReplication api to ts #1185

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The full API Reference is available here.

#### Full Examples : Bucket Operations

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

#### Full Examples : File Object Operations

Expand Down
22 changes: 11 additions & 11 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Please refer to: [list-buckets.mjs](..%2Fexamples%2Flist-buckets.mjs)

```js
try {
const buckets = await s3Client.listBuckets()
const buckets = await minioClient.listBuckets()
console.log('Success', buckets)
} catch (err) {
console.log(err.message)
Expand Down Expand Up @@ -581,26 +581,26 @@ minioClient.getBucketReplication('bucketname', function (err, replicationConfig)

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

### removeBucketReplication(bucketName, callback)
### removeBucketReplication(bucketName)

Remove replication config of a Bucket

**Parameters**

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

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

```js
minioClient.removeBucketReplication('bucketname', function (err, replicationConfig) {
if (err) {
return console.log(err)
}
try {
minioClient.removeBucketReplication('source-bucket')
prakashsvmx marked this conversation as resolved.
Show resolved Hide resolved
prakashsvmx marked this conversation as resolved.
Show resolved Hide resolved
console.log('Success')
})
} catch (err) {
console.log(err.message)
}
```

<a name="setBucketTagging"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
// 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',
})

s3Client.removeBucketReplication('bucketname', function (err) {
if (err) {
return console.log(err)
}
try {
await s3Client.removeBucketReplication('source-bucket')
console.log('Success')
})
} catch (err) {
console.log(err.message)
}
11 changes: 11 additions & 0 deletions src/internal/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,4 +887,15 @@ export class TypedClient {
const xmlResult = await readAsString(httpRes)
return xmlParsers.parseListBucket(xmlResult)
}

async removeBucketReplication(bucketName: string): Promise<void>
removeBucketReplication(bucketName: string, callback: NoResultCallback): void
prakashsvmx marked this conversation as resolved.
Show resolved Hide resolved
async removeBucketReplication(bucketName: string): Promise<void> {
if (!isValidBucketName(bucketName)) {
throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName)
}
const method = 'DELETE'
const query = 'replication'
await this.makeRequestAsyncOmit({ method, bucketName, query }, '', [200, 204], '')
}
}
3 changes: 0 additions & 3 deletions src/minio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ export class Client extends TypedClient {
getBucketReplication(bucketName: string, callback: ResultCallback<ReplicationConfig>): void
getBucketReplication(bucketName: string): Promise<ReplicationConfig>

removeBucketReplication(bucketName: string, callback: NoResultCallback): void
removeBucketReplication(bucketName: string): Promise<void>

// Object operations
getObject(bucketName: string, objectName: string, callback: ResultCallback<ReadableStream>): void
getObject(bucketName: string, objectName: string): Promise<ReadableStream>
Expand Down
11 changes: 1 addition & 10 deletions src/minio.js
Original file line number Diff line number Diff line change
Expand Up @@ -2388,15 +2388,6 @@ export class Client extends TypedClient {
})
}

removeBucketReplication(bucketName, cb) {
if (!isValidBucketName(bucketName)) {
throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName)
}
const method = 'DELETE'
const query = 'replication'
this.makeRequest({ method, bucketName, query }, '', [200, 204], '', false, cb)
}

getObjectLegalHold(bucketName, objectName, getOpts = {}, cb) {
if (!isValidBucketName(bucketName)) {
throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName)
Expand Down Expand Up @@ -2853,7 +2844,6 @@ Client.prototype.getBucketEncryption = promisify(Client.prototype.getBucketEncry
Client.prototype.removeBucketEncryption = promisify(Client.prototype.removeBucketEncryption)
Client.prototype.setBucketReplication = promisify(Client.prototype.setBucketReplication)
Client.prototype.getBucketReplication = promisify(Client.prototype.getBucketReplication)
Client.prototype.removeBucketReplication = promisify(Client.prototype.removeBucketReplication)
Client.prototype.setObjectLegalHold = promisify(Client.prototype.setObjectLegalHold)
Client.prototype.getObjectLegalHold = promisify(Client.prototype.getObjectLegalHold)
Client.prototype.composeObject = promisify(Client.prototype.composeObject)
Expand All @@ -2863,3 +2853,4 @@ Client.prototype.selectObjectContent = promisify(Client.prototype.selectObjectCo
Client.prototype.removeObject = callbackify(Client.prototype.removeObject)
Client.prototype.removeBucket = callbackify(Client.prototype.removeBucket)
Client.prototype.listBuckets = callbackify(Client.prototype.listBuckets)
Client.prototype.removeBucketReplication = callbackify(Client.prototype.removeBucketReplication)
14 changes: 12 additions & 2 deletions tests/unit/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1393,14 +1393,24 @@ describe('Client', function () {
describe('removeBucketReplication(bucketName, callback)', () => {
it('should fail on null bucket', (done) => {
try {
client.removeBucketReplication(null, {}, function () {})
client.removeBucketReplication(null, function (err) {
if (err) {
return done()
}
done(new Error('callback should receive error'))
})
} catch (e) {
done()
}
})
it('should fail on empty bucket', (done) => {
try {
client.removeBucketReplication('', {}, function () {})
client.removeBucketReplication('', function (err) {
if (err) {
return done()
}
done(new Error('callback should receive error'))
})
} catch (e) {
done()
}
Expand Down