From 85aa4115f3f4f5183f38fdde0a9356a30f4946da Mon Sep 17 00:00:00 2001 From: xuty <xty50337@hotmail.com> Date: Wed, 1 Apr 2020 20:11:54 +0800 Subject: [PATCH] finish all --- CHANGELOG.md | 4 ++++ README.md | 7 +++++-- lib/src/minio.dart | 45 ++++++++++++++++++++++++++++++++++++++++++++- pubspec.yaml | 2 +- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7252306..6cf6c31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.6 + +- support policy apis + ## 0.1.5 - support notification apis diff --git a/README.md b/README.md index 639551e..0541a2c 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ This is the _unofficial_ MinIO Dart Client SDK that provides simple APIs to acce | [listBuckets] | [getPartialObject] | [presignedGetObject] | [setBucketNotification] | | [bucketExists] | [fGetObject] | [presignedPutObject] | [removeAllBucketNotification] | | [removeBucket] | [putObject] | [presignedPostPolicy]| [listenBucketNotification] | -| [listObjects] | [fPutObject] | | getBucketPolicy | -| [listObjectsV2] | [copyObject] | | setBucketPolicy | +| [listObjects] | [fPutObject] | | [getBucketPolicy] | +| [listObjectsV2] | [copyObject] | | [setBucketPolicy] | | [listIncompleteUploads] | [statObject] | | | | | [removeObject] | | | | | [removeObjects] | | | @@ -101,3 +101,6 @@ MIT [setBucketNotification]: https://pub.dev/documentation/minio/latest/minio/Minio/setBucketNotification.html [removeAllBucketNotification]: https://pub.dev/documentation/minio/latest/minio/Minio/removeAllBucketNotification.html [listenBucketNotification]: https://pub.dev/documentation/minio/latest/minio/Minio/listenBucketNotification.html + +[getBucketPolicy]: https://pub.dev/documentation/minio/latest/minio/Minio/getBucketPolicy.html +[setBucketPolicy]: https://pub.dev/documentation/minio/latest/minio/Minio/setBucketPolicy.html diff --git a/lib/src/minio.dart b/lib/src/minio.dart index de21301..885cf9e 100644 --- a/lib/src/minio.dart +++ b/lib/src/minio.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:http/http.dart'; import 'package:minio/models.dart'; import 'package:minio/src/minio_client.dart'; @@ -229,6 +231,23 @@ class Minio { return NotificationConfiguration.fromXml(node.rootElement); } + /// Get the bucket policy associated with the specified bucket. If `objectPrefix` + /// is not empty, the bucket policy will be filtered based on object permissions + /// as well. + Future<Map<String, dynamic>> getBucketPolicy(bucket) async { + MinioInvalidBucketNameError.check(bucket); + + final resp = await _client.request( + method: 'GET', + bucket: bucket, + resource: 'policy', + ); + + validate(resp, expect: 200); + + return json.decode(resp.body); + } + /// gets the region of the bucket Future<String> getBucketRegion(String bucket) async { MinioInvalidBucketNameError.check(bucket); @@ -890,7 +909,9 @@ class Minio { // Remove all the notification configurations in the S3 provider Future<void> setBucketNotification( - String bucket, NotificationConfiguration config) async { + String bucket, + NotificationConfiguration config, + ) async { MinioInvalidBucketNameError.check(bucket); assert(config != null); @@ -904,6 +925,28 @@ class Minio { validate(resp, expect: 200); } + /// Set the bucket policy on the specified bucket. + /// + /// [policy] is detailed [here](https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html). + Future<void> setBucketPolicy( + String bucket, [ + Map<String, dynamic> policy, + ]) async { + MinioInvalidBucketNameError.check(bucket); + + final method = policy != null ? 'PUT' : 'DELETE'; + final payload = policy != null ? json.encode(policy) : ''; + + final resp = await _client.request( + method: method, + bucket: bucket, + resource: 'policy', + payload: payload, + ); + + validate(resp, expect: 204); + } + /// Stat information of the object. Future<StatObjectResult> statObject(String bucket, String object) async { MinioInvalidBucketNameError.check(bucket); diff --git a/pubspec.yaml b/pubspec.yaml index b4dd52c..47766c6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: minio description: Unofficial MinIO Dart Client SDK that provides simple APIs to access any Amazon S3 compatible object storage server. -version: 0.1.5 +version: 0.1.6 homepage: https://github.com/xtyxtyx/minio-dart issue_tracker: https://github.com/xtyxtyx/minio-dart/issues -- GitLab