Пример #1
0
class Operation:
    client = None

    def __init__(self):
        minio_conf = conf.Conf()
        self.client = Minio(minio_conf.get_endpoint(),
                            access_key=minio_conf.get_access_key(),
                            secret_key=minio_conf.get_secret_key(),
                            secure=minio_conf.get_secure())

    def make_bucket(self, bucket_name):
        try:
            self.client.make_bucket(bucket_name=bucket_name)
        except ResponseError as err:
            print err
            exit(0)
        print "cminio: create [%s] bucket success" % bucket_name

    def list_buckets(self):
        buckets = self.client.list_buckets()
        print '[bucket name]\t', '[create time]\t'
        for bucket in buckets:
            print '%s\t%s\t' % (bucket.name, bucket.creation_date)

    def bucket_exists(self, bucket_name):
        try:
            if self.client.bucket_exists(bucket_name=bucket_name):
                print "cminio: the [%s] bucket is exist" % bucket_name
            else:
                print "cminio: the [%s] bucket is not exist" % bucket_name
        except ResponseError as err:
            print err

    def list_objects(self, prefix, bucket_name, recursive):
        objects = self.client.list_objects(bucket_name=bucket_name,
                                           prefix=prefix,
                                           recursive=recursive)
        print "[bucket name]\t[object name]\t[object last modified]\t[etag]\t[size]\t[content type]\t"
        i = 0
        for object in objects:
            print "%s\t%s\t%s\t%s\t%s\t%s\t" % (
                object.bucket_name, object.object_name.encode('utf-8'),
                object.last_modified, object.etag, object.size,
                object.content_type)
            i = i + 1
        print "\n Total: %s object[s]" % i

    def get_bucket_policy(self, bucket_name):
        policy = self.client.get_bucket_policy(bucket_name=bucket_name)
        print "[%s] policy: %s" % (bucket_name, policy)

    def set_bucket_policy(self, bucket_name, path):
        bucket_policy = policy.Policy()
        self.client.set_bucket_policy(bucket_name,
                                      bucket_policy.policy_from_disk(path))

    def get_bucket_notification(self, bucket_name):
        notification = self.client.get_bucket_notification(
            bucket_name=bucket_name)
        print "[%s] bucket: %s" % (bucket_name, notification)

    def set_bucket_notification(self, bucket_name, notification):
        try:
            self.client.set_bucket_notification(bucket_name, notification)
        except ResponseError as err:
            print err

    def remove_all_bucket_notification(self, bucket_name):
        self.client.remove_all_bucket_notification(bucket_name)

    def get_object(self,
                   bucket_name,
                   object_name,
                   request_headers=None,
                   output=None):
        try:
            data = self.client.get_object(bucket_name,
                                          object_name,
                                          request_headers=request_headers)
            with open(output, "wb") as file_data:
                for d in data.stream(32 * 1024):
                    file_data.write(d)
        except ResponseError as err:
            print err
#
# 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.

from minio import Minio
from minio.error import ResponseError

client = Minio('s3.amazonaws.com',
               access_key='YOUR-ACCESSKEYID',
               secret_key='YOUR-SECRETACCESSKEY')

try:
    # Get the notifications configuration for a bucket.
    notification = client.get_bucket_notification('my-bucketname')
    # If no notification is present on the bucket:
    # notification == {}
except ResponseError as err:
    print(err)
Пример #3
0
    print(obj.bucket_name, obj.object_name.encode('utf-8'), obj.last_modified, obj.etag, obj.size, obj.content_type)

#列出桶中未完整上传的对象
uploads = minioClient.list_incomplete_uploads('bucket-niangu', prefix='my-prefixname', recursive=True)
for obj in uploads:
    print(obj.bucket_name, obj.object_name, obj.upload_id, obj.size)

#获取存储桶的当前策略
#policy = minioClient.get_bucket_policy('bucket-niangu')
#print(policy)

#设置桶的存储策略
#minioClient.set_bucket_policy('bucket-niangu', 'pre', Policy.READ_ONLY)

#获取桶上的通知配置
notification = minioClient.get_bucket_notification('bucket-niangu')
print(notification)

#设置桶的存储配置

#移除桶上配置的所有通知
#minioClient.remove_all_bucket_notification('bucket-niangu')
"""
#监听桶上的通知
events = minioClient.listen_bucket_notification('bucket-niangu', '', '',['s3:ObjectCreated:*',
                                                                                   's3:ObjectRemoved:*',
                                                                                   's3:ObjectAccessed:*'])
for event in events:
    print(event)

#下载一个对象
Пример #4
0
notification = {
    'QueueConfigurations': [{
        'Id':
        "1",
        'Arn':
        'arn:minio:sqs::1:amqp',
        'Events':
        ['s3:ObjectCreated:*', 's3:ObjectRemoved:*', 's3:ObjectAccessed:*']
    }]
}

if minioClient.bucket_exists(os.getenv('RAW_MEDIA_BUCKET', 'Token Not found')):
    print("bucket %s exists" %
          os.getenv('RAW_MEDIA_BUCKET', 'Token Not found'))
else:
    try:
        minioClient.make_bucket(
            os.getenv('RAW_MEDIA_BUCKET', 'Token Not found'))
    except ResponseError as err:
        print(err)

try:
    minioClient.set_bucket_notification(
        os.getenv('RAW_MEDIA_BUCKET', 'Token Not found'), notification)
    print(
        minioClient.get_bucket_notification(
            os.getenv('RAW_MEDIA_BUCKET', 'Token Not found')))
except ResponseError as err:
    # handle error response from service.
    print(err)
# -*- coding: utf-8 -*-
# MinIO Python Library for Amazon S3 Compatible Cloud Storage.
# Copyright (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.
# 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.

from minio import Minio

client = Minio(
    "play.min.io",
    access_key="Q3AM3UQ867SPQQA43P2F",
    secret_key="zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
)

config = client.get_bucket_notification("my-bucketname")