def to_put_bucket_replication()

in oss2/xml_utils.py [0:0]


def to_put_bucket_replication(replication_config):
    root = ElementTree.Element('ReplicationConfiguration')
    rule = ElementTree.SubElement(root, 'Rule')
    if replication_config.rule_id:
        _add_text_child(rule, 'ID', replication_config.rule_id)

    destination = ElementTree.SubElement(rule, 'Destination')
    _add_text_child(destination, 'Bucket', replication_config.target_bucket_name)
    _add_text_child(destination, 'Location', replication_config.target_bucket_location)

    if replication_config.target_transfer_type:
        _add_text_child(destination, 'TransferType', replication_config.target_transfer_type)

    if replication_config.is_enable_historical_object_replication is False:
        _add_text_child(rule, 'HistoricalObjectReplication', 'disabled')
    else:
        _add_text_child(rule, 'HistoricalObjectReplication', 'enabled')

    if replication_config.prefix_list:
        prefix_list_node = ElementTree.SubElement(rule, 'PrefixSet')
        for prefix in replication_config.prefix_list:
            _add_text_child(prefix_list_node, 'Prefix', prefix)

    if replication_config.action_list:
        actions = ''
        for action in replication_config.action_list:
            actions += action
            actions += ','
        actions = actions[:-1]
        _add_text_child(rule, 'Action', actions)

    if replication_config.sync_role_name:
        _add_text_child(rule, 'SyncRole', replication_config.sync_role_name)

    if replication_config.replica_kms_keyid:
        encryption_config = ElementTree.SubElement(rule, 'EncryptionConfiguration')
        _add_text_child(encryption_config, 'ReplicaKmsKeyID', replication_config.replica_kms_keyid)

    if replication_config.sse_kms_encrypted_objects_status in ['Enabled', 'Disabled']:
        criteria = ElementTree.SubElement(rule, 'SourceSelectionCriteria')
        sse_kms_encrypted_objects = ElementTree.SubElement(criteria, 'SseKmsEncryptedObjects')
        _add_text_child(sse_kms_encrypted_objects, 'Status', replication_config.sse_kms_encrypted_objects_status)

    return _node_to_string(root)