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

Add metadata to get, fget and get_partial methods #522

Merged
merged 7 commits into from
May 14, 2017

Conversation

DrJackilD
Copy link
Contributor

Regard to this issue: #521 I want to add support for additional headers in get methods.

minio/api.py Outdated
@@ -698,6 +698,8 @@ def fget_object(self, bucket_name, object_name, file_path):
:param bucket_name: Bucket to read object from.
:param object_name: Name of the object to read.
:param file_path: Local file path to save the object.
:param metadata: Any additional metadata to be uploaded along
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is what you want to do? GET doesn't upload any object in-fact it downloads the object. How does adding another parameter to fget_object help here? .

Copy link
Contributor Author

@DrJackilD DrJackilD May 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As example I can provide a case, when you using SSE-C and want to provide custom headers to get decrypted file from S3:

    key = b'32byteslongsecretkeymustprovided'
    encryption_key = base64.b64encode(key).decode()
    encryption_key_md5 = base64.b64encode(hashlib.md5(key).digest()).decode()

    minio = Minio('s3.amazonaws.com', access_key=AWSAccessKeyId, secret_key=AWSSecretKey)

    obj = minio.get_object(S3_BUCKET, 'test_crypt.txt', 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
    })

    print(obj.read())

    minio.put_object(S3_BUCKET, 'test_crypt1.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
                     })

    obj = minio.get_object(S3_BUCKET, 'test_crypt1.txt', 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
    })

    print(obj.read())

@harshavardhana
Copy link
Member

key = b'32byteslongsecretkeymustprovided'
encryption_key = base64.b64encode(key).decode()
encryption_key_md5 = base64.b64encode(hashlib.md5(key).digest()).decode()

minio = Minio('s3.amazonaws.com', access_key=AWSAccessKeyId, secret_key=AWSSecretKey)

obj = minio.get_object('minio-vfs-test', 'test_crypt.txt', 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
})

print(obj.read())

minio.put_object('minio-vfs-test', 'test_crypt1.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
                 })

obj = minio.get_object('minio-vfs-test', 'test_crypt1.txt', 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
})

print(obj.read())

Then perhaps you need to update the comment.. to reflect the right purpose here. Rather than saying upload we should say that these are request headers.. and not metadata but rather just request_headers . Since these are request_headers http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectGET.html#get-object-sse-c-specific-request-headers

With this we can also support now 'If-Match', 'If-Modified-Since' etc.

Additionally it would be cleaner to get a full example added as well to examples/

@DrJackilD
Copy link
Contributor Author

DrJackilD commented May 13, 2017

@harshavardhana I'm agreed, that request_headers will be cleaner, I'm just take same name, as in the put_object, where this variable in fact just additional headers too. So, I suggest to left it as is, to be consistent with other methods. Agreed?

P. S. Also I saw that CI was failed, I'm looking what's happened now

@DrJackilD
Copy link
Contributor Author

Tests fixed and documentation is updated with example of usage

minio/api.py Outdated
@@ -698,8 +698,7 @@ def fget_object(self, bucket_name, object_name, file_path, metadata=None):
:param bucket_name: Bucket to read object from.
:param object_name: Name of the object to read.
:param file_path: Local file path to save the object.
:param metadata: Any additional metadata to be uploaded along
with your GET request.
:param metadata: Any additional metadata to be added to GET request's headers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO we should keep it as request headers, in put_object it is meant to be saved with the object. Here it is meant to be queried.. so it is better to named request_headers or req_headers makes the code more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, agreed, I will rename it right now :)

Copy link
Member

@harshavardhana harshavardhana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with If-Match, If-Modified-Since.. LGTM

@DrJackilD
Copy link
Contributor Author

DrJackilD commented May 14, 2017

@harshavardhana So, as far as you approved this PR, when I could expect this on the master branch? I want to use it in my project :)

@harshavardhana harshavardhana merged commit 8889020 into minio:master May 14, 2017
@DrJackilD DrJackilD deleted the add_metadata_to_get branch May 14, 2017 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants