Skip to content

Commit

Permalink
fix formatting as per pep8 in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana committed Apr 14, 2020
1 parent a30dfa0 commit cb15f0a
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 78 deletions.
2 changes: 1 addition & 1 deletion examples/aws_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
# Initialize Minio with IamEc2MetaData custom
client = Minio('s3.amazonaws.com',
credentials=Credentials(
provider=IamEc2MetaData(endpoint='custom.endpoint')
provider=IamEc2MetaData(endpoint='custom.endpoint')
))
10 changes: 5 additions & 5 deletions examples/chain_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
client = Minio('s3.amazonaws.com',
credentials=Credentials(
provider=Chain(
providers=[
IamEc2MetaData(),
EnvAWS(),
EnvMinio()
]
providers=[
IamEc2MetaData(),
EnvAWS(),
EnvMinio()
]
)
))
3 changes: 2 additions & 1 deletion examples/fput_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
# Put an object 'my-objectname-csv' with progress.
progress = Progress()
try:
client.fput_object('my-bucketname', 'my-objectname', 'my-filepath', progress=progress)
client.fput_object('my-bucketname', 'my-objectname',
'my-filepath', progress=progress)
except ResponseError as err:
print(err)
2 changes: 1 addition & 1 deletion examples/list_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
# List all object paths in bucket that begin with my-prefixname using
# V2 listing API.
objects = client.list_objects_v2('my-bucketname', prefix='my-prefixname',
recursive=True)
recursive=True)
for obj in objects:
print(obj.bucket_name, obj.object_name.encode('utf-8'), obj.last_modified,
obj.etag, obj.size, obj.content_type)
21 changes: 14 additions & 7 deletions examples/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ 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()
Expand All @@ -122,8 +124,10 @@ def done_progress(self):

def print_status(self, current_size, total_length, displayed_time, prefix):

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))
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()
self.last_printed_len = len(formatted_str)

Expand Down Expand Up @@ -152,15 +156,18 @@ def format_string(current_size, total_length, elapsed_time):
n_to_mb = current_size / _KILOBYTE / _KILOBYTE
elapsed_str = seconds_to_time(elapsed_time)

rate = _RATE_FORMAT % (n_to_mb / elapsed_time) if elapsed_time else _UNKNOWN_SIZE
rate = _RATE_FORMAT % (
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

humanized_total = _HUMANINZED_FORMAT % (total_length / _KILOBYTE / _KILOBYTE) + _STR_MEGABYTE
humanized_total = _HUMANINZED_FORMAT % (
total_length / _KILOBYTE / _KILOBYTE) + _STR_MEGABYTE
humanized_n = _HUMANINZED_FORMAT % n_to_mb + _STR_MEGABYTE

return _DISPLAY_FORMAT % (
Expand Down
6 changes: 4 additions & 2 deletions examples/put_and_get_encrypted_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ def main():
encryption_key = base64.b64encode(key).decode()
encryption_key_md5 = base64.b64encode(hashlib.md5(key).digest()).decode()

minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId, secret_key=AWSSecretKey)
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
})
})

# Get decrypted object with same headers
obj = minio.get_object(STORAGE_BUCKET, 'test_crypt1.txt', request_headers={
Expand All @@ -37,5 +38,6 @@ def main():

print(obj.read())


if __name__ == '__main__':
main()
18 changes: 11 additions & 7 deletions examples/put_and_get_object_sse-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,30 @@
def main():
content = BytesIO(b'Hello again')

minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId, secret_key=AWSSecretKey)
minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId,
secret_key=AWSSecretKey)

# Create an SSE-C object with a 32 byte customer_key
key = b'32byteslongsecretkeymustprovided'
sse_customer_key = SSE_C(key)

# Put object with SSE_C object passed as a param
minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content, content.getbuffer().nbytes, sse=sse_customer_key)
# Put object with SSE_C object passed as a param
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
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)
# 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)

# 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())


if __name__ == '__main__':
main()
13 changes: 8 additions & 5 deletions examples/put_object_sse-kms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,27 @@


def main():

minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId, secret_key=AWSSecretKey)

minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId,
secret_key=AWSSecretKey)

content = BytesIO(b'Some Data to be stored')

key_id = 'YOUR-KMS-KEY'
context = {'Key1':'Value1', 'Key2':'Value2'}
context = {'Key1': 'Value1', 'Key2': 'Value2'}

# 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
minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content, content.getbuffer().nbytes, sse=sse_kms_obj)
minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content,
content.getbuffer().nbytes, sse=sse_kms_obj)

# Get decrypted object with same headers
obj = minio.get_object(STORAGE_BUCKET, 'test_crypt.txt')

print(obj.read())


if __name__ == '__main__':
main()
15 changes: 9 additions & 6 deletions examples/put_object_sse-s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,24 @@


def main():

minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId, secret_key=AWSSecretKey)

minio = Minio(STORAGE_ENDPOINT, access_key=AWSAccessKeyId,
secret_key=AWSSecretKey)

content = BytesIO(b'Hello again')
#Create an SSE_S3 object

# 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
minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content, content.getbuffer().nbytes, sse=sse_s3_obj)
minio.put_object(STORAGE_BUCKET, 'test_crypt.txt', content,
content.getbuffer().nbytes, sse=sse_s3_obj)

# Get decrypted object with same headers
obj = minio.get_object(STORAGE_BUCKET, 'test_crypt.txt')

print(obj.read())


if __name__ == '__main__':
main()
5 changes: 3 additions & 2 deletions examples/remove_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

# Remove a prefix recursively.
try:
get_name = lambda object: object.object_name
names = map(get_name, client.list_objects_v2('my-bucketname', 'my-prefix', recursive=True))
def get_name(object): return object.object_name
names = map(get_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:
Expand Down
6 changes: 3 additions & 3 deletions examples/select_object_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
),
# If input is JSON
# json=JSONInput(Type="DOCUMENT",)
),
),

output_serialization=OutputSerialization(
csv=CSVOutput(QuoteFields="ASNEEDED",
Expand All @@ -54,11 +54,11 @@
# json = JsonOutput(
# RecordDelimiter="\n",
# )
),
),
request_progress=RequestProgress(
enabled="False"
)
)
)

try:
data = client.select_object_content('your-bucket', 'your-object', options)
Expand Down
76 changes: 38 additions & 38 deletions examples/set_bucket_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@
try:
# Set bucket policy to read-only for bucket 'my-bucketname'
policy_read_only = {
"Version":"2012-10-17",
"Statement":[
"Version": "2012-10-17",
"Statement": [
{
"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"*"},
"Action":"s3:GetBucketLocation",
"Resource":"arn:aws:s3:::my-bucketname"
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": "s3:GetBucketLocation",
"Resource": "arn:aws:s3:::my-bucketname"
},
{
"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"*"},
"Action":"s3:ListBucket",
"Resource":"arn:aws:s3:::my-bucketname"
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::my-bucketname"
},
{
"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"*"},
"Action":"s3:GetObject",
"Resource":"arn:aws:s3:::my-bucketname/*"
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucketname/*"
}
]
}
Expand Down Expand Up @@ -83,10 +83,10 @@
},
{
"Action": ["s3:ListMultipartUploadParts",
"s3:GetObject",
"s3:AbortMultipartUpload",
"s3:DeleteObject",
"s3:PutObject"],
"s3:GetObject",
"s3:AbortMultipartUpload",
"s3:DeleteObject",
"s3:PutObject"],
"Sid": "",
"Resource": ["arn:aws:s3:::my-bucketname/*"],
"Effect": "Allow",
Expand All @@ -98,26 +98,26 @@

# Set bucket policy to write-only for bucket 'my-bucketname'
policy_write_only = {
"Version":"2012-10-17",
"Statement":[
"Version": "2012-10-17",
"Statement": [
{
"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"*"},
"Action":"s3:GetBucketLocation",
"Resource":"arn:aws:s3:::my-bucketname"
},
{"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"*"},
"Action":"s3:ListBucketMultipartUploads",
"Resource":"arn:aws:s3:::my-bucketname"
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": "s3:GetBucketLocation",
"Resource": "arn:aws:s3:::my-bucketname"
},
{"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": "s3:ListBucketMultipartUploads",
"Resource": "arn:aws:s3:::my-bucketname"
},
{
"Sid":"",
"Effect":"Allow",
"Principal":{"AWS":"*"},
"Action":[
"Sid": "",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Action": [
"s3:ListMultipartUploadParts",
"s3:AbortMultipartUpload",
"s3:DeleteObject",
Expand Down

0 comments on commit cb15f0a

Please sign in to comment.