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 {set,get,delete}_bucket_replication APIs. #979

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 86 additions & 4 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ s3Client = Minio(
| [`bucket_exists`](#bucket_exists) | [`copy_object`](#copy_object) | [`presigned_post_policy`](#presigned_post_policy) | [`delete_bucket_policy`](#delete_bucket_policy) |
| [`remove_bucket`](#remove_bucket) | [`stat_object`](#stat_object) | | [`get_bucket_notification`](#get_bucket_notification) |
| [`list_objects`](#list_objects) | [`remove_object`](#remove_object) | | [`set_bucket_notification`](#set_bucket_notification) |
| [`get_bucket_versioning`](#get_bucket_versioning) | [`remove_objects`](#remove_objects) | | [`remove_all_bucket_notification`](#remove_all_bucket_notification) |
| [`set_bucket_versioning`](#set_bucket_versioning) | [`fput_object`](#fput_object) | | [`listen_bucket_notification`](#listen_bucket_notification) |
| | [`fget_object`](#fget_object) | | [`get_bucket_encryption`](#get_bucket_encryption) |
| | [`select_object_content`](#select_object_content) | | [`put_bucket_encryption`](#put_bucket_encryption) |
| [`get_bucket_versioning`](#get_bucket_versioning) | [`remove_objects`](#remove_objects) | | [`remove_all_bucket_notification`](#remove_all_bucket_notification) |
| [`set_bucket_versioning`](#set_bucket_versioning) | [`fput_object`](#fput_object) | | [`listen_bucket_notification`](#listen_bucket_notification) |
| [`delete_bucket_replication`](#delete_bucket_replication) | [`fget_object`](#fget_object) | | [`get_bucket_encryption`](#get_bucket_encryption) |
| [`get_bucket_replication`](#get_bucket_replication) | [`remove_objects`](#remove_objects) | | [`remove_all_bucket_notification`](#remove_all_bucket_notification) |
| [`set_bucket_replication`](#set_bucket_replication) | [`select_object_content`](#select_object_content) | | [`put_bucket_encryption`](#put_bucket_encryption) |
| | | | [`delete_bucket_encryption`](#delete_bucket_encryption) |

## 1. Constructor
Expand Down Expand Up @@ -616,6 +617,87 @@ __Example__
minio.set_bucket_versioning("my-bucketname", VersioningConfig("Enabled"))
```

<a name="delete_bucket_replication"></a>

### delete_bucket_replication(bucket_name)

Delete replication configuration of a bucket.

__Parameters__

| Param | Type | Description |
|:----------------|:------|:--------------------|
| ``bucket_name`` | _str_ | Name of the bucket. |

__Example__

```py
minio.delete_bucket_replication("my-bucketname")
```

<a name="get_bucket_replication"></a>

### get_bucket_replication(bucket_name)

Get replication configuration of a bucket.

__Parameters__

| Param | Type | Description |
|:----------------|:------|:--------------------|
| ``bucket_name`` | _str_ | Name of the bucket. |

| Return |
|:----------------------------------------|
| _ReplicationConfig_ object. |

__Example__

```py
config = minio.get_bucket_replication("my-bucketname")
```

<a name="set_bucket_replication"></a>

### set_bucket_replication(bucket_name, config)

Set replication configuration to a bucket.

__Parameters__

| Param | Type | Description |
|:----------------|:--------------------|:---------------------------|
| ``bucket_name`` | _str_ | Name of the bucket. |
| ``config`` | _ReplicationConfig_ | Replication configuration. |

__Example__

```py
config = ReplicationConfig(
"REPLACE-WITH-ACTUAL-ROLE",
[
Rule(
Destination(
"REPLACE-WITH-ACTUAL-DESTINATION-BUCKET-ARN",
),
ENABLED,
delete_marker_replication=DeleteMarkerReplication(
DISABLED,
),
rule_filter=Filter(
AndOperator(
"TaxDocs",
{"key1": "value1", "key2": "value2"},
),
),
rule_id="rule1",
priority=1,
),
],
)
minio.set_bucket_replication("my-bucketname", config)
```

## 3. Object operations

<a name="get_object"></a>
Expand Down
28 changes: 28 additions & 0 deletions examples/delete_bucket_replication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- 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",
)

client.delete_bucket_replication("my-bucketname")
28 changes: 28 additions & 0 deletions examples/get_bucket_replication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- 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_replication("my-bucketname")
53 changes: 53 additions & 0 deletions examples/set_bucket_replication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- 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
from minio.commonconfig import DISABLED, ENABLED, AndOperator, Filter
from minio.replicationconfig import (DeleteMarkerReplication, Destination,
ReplicationConfig, Rule)

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

config = ReplicationConfig(
"REPLACE-WITH-ACTUAL-ROLE",
[
Rule(
Destination(
"REPLACE-WITH-ACTUAL-DESTINATION-BUCKET-ARN",
),
ENABLED,
delete_marker_replication=DeleteMarkerReplication(
DISABLED,
),
rule_filter=Filter(
AndOperator(
"TaxDocs",
{"key1": "value1", "key2": "value2"},
),
),
rule_id="rule1",
priority=1,
),
],
)
client.set_bucket_replication("my-bucketname", config)
79 changes: 79 additions & 0 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@
parse_multi_delete_response,
parse_multipart_upload_result,
parse_new_multipart_upload, parse_versioning_config)
from .replicationconfig import ReplicationConfig
from .select import SelectObjectReader
from .signer import (AMZ_DATE_FORMAT, SIGN_V4_ALGORITHM, get_credential_string,
post_presign_v4, presign_v4, sign_v4_s3)
from .sse import SseCustomerKey
from .thread_pool import ThreadPool
from .xml import marshal, unmarshal
from .xml_marshal import (marshal_bucket_notifications,
marshal_complete_multipart,
marshal_versioning_config,
Expand Down Expand Up @@ -1753,6 +1755,83 @@ def presigned_post_policy(self, post_policy):
post_policy.form_data,
)

def delete_bucket_replication(self, bucket_name):
"""
Delete replication configuration of a bucket.

:param bucket_name: Name of the bucket.

Example::
minio.delete_bucket_replication("my-bucketname")
"""
check_bucket_name(bucket_name)
self._execute("DELETE", bucket_name, query_params={"replication": ""})

def get_bucket_replication(self, bucket_name):
"""
Get bucket replication configuration of a bucket.

:param bucket_name: Name of the bucket.
:return: :class:`ReplicationConfig <ReplicationConfig>` object.

Example::
config = minio.get_bucket_replication("my-bucketname")
"""
check_bucket_name(bucket_name)
try:
response = self._execute(
"GET", bucket_name, query_params={"replication": ""},
)
return unmarshal(ReplicationConfig, response.data.decode())
except S3Error as exc:
if exc.code != "ReplicationConfigurationNotFoundError":
raise
return None

def set_bucket_replication(self, bucket_name, config):
"""
Set bucket replication configuration to a bucket.

:param bucket_name: Name of the bucket.
:param config: :class:`ReplicationConfig <ReplicationConfig>` object.

Example::
config = ReplicationConfig(
"REPLACE-WITH-ACTUAL-ROLE",
[
Rule(
Destination(
"REPLACE-WITH-ACTUAL-DESTINATION-BUCKET-ARN",
),
ENABLED,
delete_marker_replication=DeleteMarkerReplication(
DISABLED,
),
rule_filter=Filter(
AndOperator(
"TaxDocs",
{"key1": "value1", "key2": "value2"},
),
),
rule_id="rule1",
priority=1,
),
],
)
minio.set_bucket_replication("my-bucketname", config)
"""
check_bucket_name(bucket_name)
if not isinstance(config, ReplicationConfig):
raise ValueError("config must be ReplicationConfig type")
body = marshal(config)
self._execute(
"PUT",
bucket_name,
body=body,
headers={"Content-MD5": md5sum_hash(body)},
query_params={"replication": ""},
)

def _list_objects( # pylint: disable=too-many-arguments,too-many-branches
self,
bucket_name,
Expand Down
Loading