From 0a120625fdd8966c14acc3f6f1f81222e8f49b90 Mon Sep 17 00:00:00 2001 From: "Bala.FA" Date: Tue, 14 Apr 2020 23:41:50 +0530 Subject: [PATCH] fix formatting and use pythonic approach --- examples/aws_credentials.py | 3 +- examples/bucket_exists.py | 3 +- examples/chain_credentials.py | 12 ++++-- examples/copy_object.py | 13 +++--- examples/copy_object_with_metadata.py | 4 +- examples/fget_object.py | 7 ++-- examples/fput_object.py | 7 ++-- examples/get_object.py | 7 ++-- examples/get_partial_object.py | 7 ++-- examples/list_buckets.py | 3 +- examples/list_incomplete_uploads.py | 3 +- examples/list_objects.py | 3 +- examples/make_bucket.py | 3 +- examples/presigned_get_object.py | 3 +- examples/presigned_post_policy.py | 23 ++++++----- examples/presigned_put_object.py | 3 +- examples/progress.py | 42 ++++++++++--------- examples/put_and_get_encrypted_object.py | 47 ++++++++++++++++------ examples/put_and_get_object_sse-c.py | 18 +++++---- examples/put_object.py | 3 +- examples/put_object_sse-kms.py | 7 ++-- examples/put_object_sse-s3.py | 7 ++-- examples/remove_bucket.py | 3 +- examples/remove_incomplete_upload.py | 3 +- examples/remove_object.py | 3 +- examples/remove_objects.py | 10 +++-- examples/select_object_content.py | 51 +++++++++++++----------- examples/stat_object.py | 3 +- 28 files changed, 182 insertions(+), 119 deletions(-) diff --git a/examples/aws_credentials.py b/examples/aws_credentials.py index 457c0c8e..0abbbf92 100644 --- a/examples/aws_credentials.py +++ b/examples/aws_credentials.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2020 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/bucket_exists.py b/examples/bucket_exists.py index 7cd70e41..a07d647a 100644 --- a/examples/bucket_exists.py +++ b/examples/bucket_exists.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/chain_credentials.py b/examples/chain_credentials.py index 4a203c47..839fd653 100644 --- a/examples/chain_credentials.py +++ b/examples/chain_credentials.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2020 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2020 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,10 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -# A Chain credentials provider, provides a way of chaining multiple providers together -# and will pick the first available using priority order of the 'providers' list +# A Chain credentials provider, provides a way of chaining multiple providers +# together and will pick the first available using priority order of the +# 'providers' list -from minio.credentials import Chain, EnvAWS, EnvMinio, IamEc2MetaData +from minio import Minio +from minio.credentials import ( + Chain, EnvAWS, EnvMinio, IamEc2MetaData, Credentials) client = Minio('s3.amazonaws.com', credentials=Credentials( diff --git a/examples/copy_object.py b/examples/copy_object.py index 09c4b5b0..356113a8 100644 --- a/examples/copy_object.py +++ b/examples/copy_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2016 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2016 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +17,7 @@ # Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and # my-objectname are dummy values, please replace them with original values. -import time -from datetime import datetime +from datetime import datetime, timezone from minio import Minio, CopyConditions from minio.error import ResponseError @@ -28,12 +28,11 @@ # client.trace_on(sys.stderr) copy_conditions = CopyConditions() -# Set modified condition, copy object modified since 2014 April. -t = (2014, 4, 0, 0, 0, 0, 0, 0, 0) -mod_since = datetime.utcfromtimestamp(time.mktime(t)) +# Set modified condition, copy object modified since 1st April 2014. +mod_since = datetime(2014, 4, 1, tzinfo=timezone.utc) copy_conditions.set_modified_since(mod_since) -# Set unmodified condition, copy object unmodified since 2014 April. +# Set unmodified condition, copy object unmodified since 1st April 2014. # copy_conditions.set_unmodified_since(mod_since) # Set matching ETag condition, copy object which matches the following ETag. diff --git a/examples/copy_object_with_metadata.py b/examples/copy_object_with_metadata.py index 48125513..1dda9344 100644 --- a/examples/copy_object_with_metadata.py +++ b/examples/copy_object_with_metadata.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2016,2017,2018 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2016,2017,2018 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,6 +17,7 @@ # Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-testfile, my-bucketname and # my-objectname are dummy values, please replace them with original values. +from minio import Minio from minio.error import ResponseError client = Minio('s3.amazonaws.com', diff --git a/examples/fget_object.py b/examples/fget_object.py index cb548e16..a5c550a3 100644 --- a/examples/fget_object.py +++ b/examples/fget_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,8 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname are -# dummy values, please replace them with original values. +# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname +# are dummy values, please replace them with original values. from minio import Minio from minio.error import ResponseError diff --git a/examples/fput_object.py b/examples/fput_object.py index 557f453f..3567e279 100644 --- a/examples/fput_object.py +++ b/examples/fput_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,8 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and -# my-filepath dummy values, please replace them with original values. +# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname +# and my-filepath dummy values, please replace them with original values. from minio import Minio from minio.error import ResponseError diff --git a/examples/get_object.py b/examples/get_object.py index 9c504863..93ba6a92 100644 --- a/examples/get_object.py +++ b/examples/get_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,8 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and -# my-testfile are dummy values, please replace them with original values. +# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname +# and my-testfile are dummy values, please replace them with original values. from minio import Minio from minio.error import ResponseError diff --git a/examples/get_partial_object.py b/examples/get_partial_object.py index 83628d4b..6aaec111 100644 --- a/examples/get_partial_object.py +++ b/examples/get_partial_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,8 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname and -# my-testfile are dummy values, please replace them with original values. +# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname, my-objectname +# and my-testfile are dummy values, please replace them with original values. from minio import Minio from minio.error import ResponseError diff --git a/examples/list_buckets.py b/examples/list_buckets.py index 2f2505ba..193ff1fd 100644 --- a/examples/list_buckets.py +++ b/examples/list_buckets.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/list_incomplete_uploads.py b/examples/list_incomplete_uploads.py index 86ebb5c7..36b2d50d 100644 --- a/examples/list_incomplete_uploads.py +++ b/examples/list_incomplete_uploads.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/list_objects.py b/examples/list_objects.py index 28d4a658..53c6c674 100644 --- a/examples/list_objects.py +++ b/examples/list_objects.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/make_bucket.py b/examples/make_bucket.py index 170ce70a..b4c51122 100644 --- a/examples/make_bucket.py +++ b/examples/make_bucket.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/presigned_get_object.py b/examples/presigned_get_object.py index a884a2ac..fb8a13ab 100644 --- a/examples/presigned_get_object.py +++ b/examples/presigned_get_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/presigned_post_policy.py b/examples/presigned_post_policy.py index 85e0d332..20307791 100644 --- a/examples/presigned_post_policy.py +++ b/examples/presigned_post_policy.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,8 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Note: my-bucketname, my-objectname, YOUR-ACCESSKEYID, and YOUR-SECRETACCESSKEY -# are dummy values, please replace them with original values. +# Note: my-bucketname, my-objectname, YOUR-ACCESSKEYID, and +# YOUR-SECRETACCESSKEY are dummy values, please replace them with original +# values. from datetime import datetime, timedelta @@ -31,7 +33,7 @@ post_policy.set_content_length_range(10, 1024) # set expiry 10 days into future. -expires_date = datetime.utcnow()+timedelta(days=10) +expires_date = datetime.utcnow() + timedelta(days=10) post_policy.set_expires(expires_date) client = Minio('s3.amazonaws.com', @@ -39,14 +41,15 @@ secret_key='YOUR-SECRETACCESSKEY') try: - url_str, signed_form_data = client.presigned_post_policy(post_policy) - curl_str = 'curl -X POST {0}'.format(url_str) - curl_cmd = [curl_str] - for field in signed_form_data: - curl_cmd.append('-F {0}={1}'.format(field, signed_form_data[field])) + url, signed_form_data = client.presigned_post_policy(post_policy) + + curl_cmd = ( + ['curl -X POST {0}'.format(url)] + + ['-F {0}={1}'.format(k, v) for k, v in signed_form_data.items()] + + ['-F file=@'] + ) # print curl command to upload files. - curl_cmd.append('-F file=@') print(' '.join(curl_cmd)) except ResponseError as err: print(err) diff --git a/examples/presigned_put_object.py b/examples/presigned_put_object.py index 5ea283b9..c2c7fdf0 100644 --- a/examples/presigned_put_object.py +++ b/examples/presigned_put_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/progress.py b/examples/progress.py index 9dfddef3..7aa1df59 100644 --- a/examples/progress.py +++ b/examples/progress.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) -# 2018 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2018 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -73,7 +73,8 @@ def __init__(self, interval=1, stdout=sys.stdout): def set_meta(self, total_length, object_name): """ - Metadata settings for the object. This method called before uploading object + Metadata settings for the object. This method called before uploading + object :param total_length: Total length of object. :param object_name: Object name to be showed. """ @@ -82,7 +83,6 @@ def set_meta(self, total_length, object_name): self.prefix = self.object_name + ': ' if self.object_name else '' def run(self): - displayed_time = 0 while True: try: @@ -92,14 +92,18 @@ def run(self): elapsed_time = time.time() - self.initial_time if elapsed_time > displayed_time: displayed_time = elapsed_time - self.print_status(current_size=self.current_size, total_length=self.total_length, - displayed_time=displayed_time, prefix=self.prefix) + self.print_status(current_size=self.current_size, + total_length=self.total_length, + displayed_time=displayed_time, + prefix=self.prefix) continue current_size, total_length = task displayed_time = time.time() - self.initial_time - self.print_status(current_size=current_size, total_length=total_length, - displayed_time=displayed_time, prefix=self.prefix) + self.print_status(current_size=current_size, + total_length=total_length, + displayed_time=displayed_time, + prefix=self.prefix) self.display_queue.task_done() if current_size == total_length: self.done_progress() @@ -107,7 +111,8 @@ def run(self): def update(self, size): """ Update object size to be showed. This method called while uploading - :param size: Object size to be showed. The object size should be in bytes. + :param size: Object size to be showed. The object size should be in + bytes. """ if not isinstance(size, int): raise ValueError('{} type can not be displayed. ' @@ -123,9 +128,8 @@ def done_progress(self): self.current_size = 0 def print_status(self, current_size, total_length, displayed_time, prefix): - - formatted_str = prefix + \ - format_string(current_size, total_length, displayed_time) + formatted_str = prefix + format_string( + current_size, total_length, displayed_time) self.stdout.write(_REFRESH_CHAR + formatted_str + ' ' * max(self.last_printed_len - len(formatted_str), 0)) self.stdout.flush() @@ -160,15 +164,17 @@ def format_string(current_size, total_length, elapsed_time): n_to_mb / elapsed_time) if elapsed_time else _UNKNOWN_SIZE frac = float(current_size) / total_length bar_length = int(frac * _BAR_SIZE) - bar = _FINISHED_BAR * bar_length + \ - _REMAINING_BAR * (_BAR_SIZE - bar_length) + bar = (_FINISHED_BAR * bar_length + + _REMAINING_BAR * (_BAR_SIZE - bar_length)) percentage = _PERCENTAGE_FORMAT % (frac * 100) - left_str = seconds_to_time( - elapsed_time / current_size * (total_length - current_size)) if current_size else _UNKNOWN_SIZE + left_str = ( + seconds_to_time( + elapsed_time / current_size * (total_length - current_size)) + if current_size else _UNKNOWN_SIZE) humanized_total = _HUMANINZED_FORMAT % ( total_length / _KILOBYTE / _KILOBYTE) + _STR_MEGABYTE humanized_n = _HUMANINZED_FORMAT % n_to_mb + _STR_MEGABYTE - return _DISPLAY_FORMAT % ( - bar, humanized_n, humanized_total, percentage, elapsed_str, left_str, rate) + return _DISPLAY_FORMAT % (bar, humanized_n, humanized_total, percentage, + elapsed_str, left_str, rate) diff --git a/examples/put_and_get_encrypted_object.py b/examples/put_and_get_encrypted_object.py index 8572da72..6da98c9e 100644 --- a/examples/put_and_get_encrypted_object.py +++ b/examples/put_and_get_encrypted_object.py @@ -1,3 +1,22 @@ +# -*- coding: utf-8 -*- +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2019 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. + import base64 from io import BytesIO import hashlib @@ -21,20 +40,24 @@ def main(): minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId, secret_key=AWSSecretKey) - # Put object with special headers which encrypt object in S3 with provided key - minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content, content.getbuffer().nbytes, - metadata={ - 'x-amz-server-side-encryption-customer-algorithm': 'AES256', - 'x-amz-server-side-encryption-customer-key': encryption_key, - 'x-amz-server-side-encryption-customer-key-MD5': encryption_key_md5 - }) + # Put object with special headers which encrypt object in S3 with provided + # key + minio.put_object( + STORAGE_BUCKET, 'test_crypt.txt', content, content.getbuffer().nbytes, + metadata={ + 'x-amz-server-side-encryption-customer-algorithm': 'AES256', + 'x-amz-server-side-encryption-customer-key': encryption_key, + 'x-amz-server-side-encryption-customer-key-MD5': encryption_key_md5 + }) # Get decrypted object with same headers - obj = minio.get_object(STORAGE_BUCKET, 'test_crypt1.txt', request_headers={ - 'x-amz-server-side-encryption-customer-algorithm': 'AES256', - 'x-amz-server-side-encryption-customer-key': encryption_key, - 'x-amz-server-side-encryption-customer-key-MD5': encryption_key_md5 - }) + obj = minio.get_object( + STORAGE_BUCKET, 'test_crypt1.txt', + request_headers={ + 'x-amz-server-side-encryption-customer-algorithm': 'AES256', + 'x-amz-server-side-encryption-customer-key': encryption_key, + 'x-amz-server-side-encryption-customer-key-MD5': encryption_key_md5 + }) print(obj.read()) diff --git a/examples/put_and_get_object_sse-c.py b/examples/put_and_get_object_sse-c.py index 58f84e22..d440ceb0 100644 --- a/examples/put_and_get_object_sse-c.py +++ b/examples/put_and_get_object_sse-c.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2018 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2018 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +17,7 @@ # Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname are # dummy values, please replace them with original values. -import base64 from io import BytesIO -import hashlib from minio.api import Minio from minio.sse import SSE_C @@ -45,16 +44,19 @@ def main(): minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content, content.getbuffer().nbytes, sse=sse_customer_key) - # Create a a copy_SSE-C object to copy an object from source to destination object on the Server-Side + # Create a a copy_SSE-C object to copy an object from source to destination + # object on the Server-Side copy_sse_customer_key = copy_SSE_C(key) # Copy encrypted object on Server-Side from Source to Destination - obj = minio.copy_object(STORAGE_BUCKET, 'test_crypt_copy.txt', STORAGE_BUCKET+'/test_crypt.txt', - source_sse=copy_sse_customer_key, sse=sse_customer_key) + obj = minio.copy_object(STORAGE_BUCKET, 'test_crypt_copy.txt', + STORAGE_BUCKET + '/test_crypt.txt', + source_sse=copy_sse_customer_key, + sse=sse_customer_key) # Get decrypted object with SSE_C object passed in as param - obj = minio.get_object( - STORAGE_BUCKET, 'test_crypt_copy.txt', sse=sse_customer_key) + obj = minio.get_object(STORAGE_BUCKET, 'test_crypt_copy.txt', + sse=sse_customer_key) print(obj.read()) diff --git a/examples/put_object.py b/examples/put_object.py index c9bcc328..8ddf7947 100644 --- a/examples/put_object.py +++ b/examples/put_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/put_object_sse-kms.py b/examples/put_object_sse-kms.py index 1410b2d0..00566a25 100644 --- a/examples/put_object_sse-kms.py +++ b/examples/put_object_sse-kms.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2018 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2018 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -28,7 +29,6 @@ def main(): - minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId, secret_key=AWSSecretKey) @@ -40,7 +40,8 @@ def main(): # Create an SSE-KMS object with a Valid KMS key_id and context sse_kms_obj = SSE_KMS(key_id, context) - # Put object with special headers from SSE_C object which encrypt object in S3 with provided key + # Put object with special headers from SSE_C object which encrypt object in + # S3 with provided key minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content, content.getbuffer().nbytes, sse=sse_kms_obj) diff --git a/examples/put_object_sse-s3.py b/examples/put_object_sse-s3.py index 5d8b8374..87621c21 100644 --- a/examples/put_object_sse-s3.py +++ b/examples/put_object_sse-s3.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2018 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2018 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,7 +30,6 @@ def main(): - minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId, secret_key=AWSSecretKey) @@ -38,7 +38,8 @@ def main(): # Create an SSE_S3 object sse_s3_obj = SSE_S3() - # Put object with from SSE_S3 object which encrypt object in S3 with provided key + # Put object with from SSE_S3 object which encrypt object in S3 with + # provided key minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content, content.getbuffer().nbytes, sse=sse_s3_obj) diff --git a/examples/remove_bucket.py b/examples/remove_bucket.py index 8a597695..3a9ecbd7 100644 --- a/examples/remove_bucket.py +++ b/examples/remove_bucket.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/remove_incomplete_upload.py b/examples/remove_incomplete_upload.py index cf85b361..f5da0f72 100644 --- a/examples/remove_incomplete_upload.py +++ b/examples/remove_incomplete_upload.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/remove_object.py b/examples/remove_object.py index 900ce314..3320e270 100644 --- a/examples/remove_object.py +++ b/examples/remove_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/examples/remove_objects.py b/examples/remove_objects.py index b1f1433a..ab2618ff 100644 --- a/examples/remove_objects.py +++ b/examples/remove_objects.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,9 +26,10 @@ # Remove a prefix recursively. try: - def get_name(object): return object.object_name - names = map(get_name, client.list_objects_v2( - 'my-bucketname', 'my-prefix', recursive=True)) + names = map( + lambda x: x.object_name, + client.list_objects_v2('my-bucketname', 'my-prefix', recursive=True) + ) for err in client.remove_objects('my-bucketname', names): print("Deletion Error: {}".format(err)) except ResponseError as err: diff --git a/examples/select_object_content.py b/examples/select_object_content.py index b725cf5f..8aa03e33 100644 --- a/examples/select_object_content.py +++ b/examples/select_object_content.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) -# 2019 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2019 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,11 +18,13 @@ from minio import Minio from minio.error import ResponseError from minio.select.errors import SelectCRCValidationError, SelectMessageError -from minio.select.options import (SelectObjectOptions, CSVInput, - JSONInput, RequestProgress, - ParquetInput, InputSerialization, - OutputSerialization, CSVOutput, - JsonOutput) +from minio.select.options import (SelectObjectOptions, RequestProgress, + InputSerialization, OutputSerialization) +from minio.select.options import CSVInput +from minio.select.options import CSVOutput +# from minio.select.options import JSONOutput +# from minio.select.options import JsonInput +# from minio.select.options import ParquetInput client = Minio('s3.amazonaws.com', access_key='YOUR-ACCESSKEY', @@ -32,28 +34,29 @@ expression="select * from s3object", input_serialization=InputSerialization( compression_type="NONE", - csv=CSVInput(FileHeaderInfo="USE", - RecordDelimiter="\n", - FieldDelimiter=",", - QuoteCharacter='"', - QuoteEscapeCharacter='"', - Comments="#", - AllowQuotedRecordDelimiter="FALSE", - ), + csv=CSVInput( + FileHeaderInfo="USE", + RecordDelimiter="\n", + FieldDelimiter=",", + QuoteCharacter='"', + QuoteEscapeCharacter='"', + Comments="#", + AllowQuotedRecordDelimiter="FALSE", + ), # If input is JSON - # json=JSONInput(Type="DOCUMENT",) + # json=JSONInput(Type="DOCUMENT") ), output_serialization=OutputSerialization( - csv=CSVOutput(QuoteFields="ASNEEDED", - RecordDelimiter="\n", - FieldDelimiter=",", - QuoteCharacter='"', - QuoteEscapeCharacter='"',) + csv=CSVOutput( + QuoteFields="ASNEEDED", + RecordDelimiter="\n", + FieldDelimiter=",", + QuoteCharacter='"', + QuoteEscapeCharacter='"', + ), - # json = JsonOutput( - # RecordDelimiter="\n", - # ) + # json = JsonOutput(RecordDelimiter="\n") ), request_progress=RequestProgress( enabled="False" diff --git a/examples/stat_object.py b/examples/stat_object.py index acaafcbb..86ebcdda 100644 --- a/examples/stat_object.py +++ b/examples/stat_object.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# MinIO Python Library for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc. +# MinIO Python Library for Amazon S3 Compatible Cloud Storage, +# (C) 2015 MinIO, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License.