def get_Inventory_configuration_from_element()

in oss2/xml_utils.py [0:0]


def get_Inventory_configuration_from_element(elem):
    root = elem
    result = InventoryConfiguration()

    result.inventory_id = _find_tag(root, 'Id')
    result.is_enabled = _find_bool(root, 'IsEnabled')
    result.included_object_versions = _find_tag(root, 'IncludedObjectVersions')

    if root.find("Filter") is not None:
        prefix = None
        last_modify_begin_time_stamp = None
        last_modify_end_time_stamp = None
        lower_size_bound = None
        upper_size_bound = None
        storage_class = None
        if root.find("Filter/Prefix") is not None:
            prefix = _find_tag(root, 'Filter/Prefix')
        if root.find("Filter/LastModifyBeginTimeStamp") is not None:
            last_modify_begin_time_stamp = _find_tag_with_default(root, 'Filter/LastModifyBeginTimeStamp', None)
        if root.find("Filter/LastModifyEndTimeStamp") is not None:
            last_modify_end_time_stamp = _find_tag_with_default(root, 'Filter/LastModifyEndTimeStamp', None)
        if root.find("Filter/LowerSizeBound") is not None:
            lower_size_bound = _find_tag_with_default(root, 'Filter/LowerSizeBound', None)
        if root.find("Filter/UpperSizeBound") is not None:
            upper_size_bound = _find_tag_with_default(root, 'Filter/UpperSizeBound', None)
        if root.find("Filter/StorageClass") is not None:
            storage_class = _find_tag_with_default(root, 'Filter/StorageClass', None)
        result.inventory_filter = InventoryFilter(prefix=prefix, last_modify_begin_time_stamp=last_modify_begin_time_stamp,
                                                  last_modify_end_time_stamp=last_modify_end_time_stamp, lower_size_bound=lower_size_bound,
                                                  upper_size_bound=upper_size_bound, storage_class=storage_class)

    if root.find("Schedule/Frequency") is not None:
        result.inventory_schedule = InventorySchedule(_find_tag(root, 'Schedule/Frequency'))

    result.optional_fields =  _find_all_tags(root, "OptionalFields/Field")

    if root.find("Destination/OSSBucketDestination") is not None:
        bucket_distin_node = root.find("Destination/OSSBucketDestination")
        account_id = None
        role_arn = None
        bucket = None
        inventory_format = None
        prefix = None
        sse_kms_encryption = None
        sse_oss_encryption = None

        if bucket_distin_node.find('AccountId') is not None:
            account_id = _find_tag(bucket_distin_node, 'AccountId')
        if bucket_distin_node.find('RoleArn') is not None:
            role_arn = _find_tag(bucket_distin_node, 'RoleArn')
        if bucket_distin_node.find('Bucket') is not None:
            origin_bucket = _find_tag(bucket_distin_node, 'Bucket')
            if origin_bucket.startswith('acs:oss:::'):
                bucket = origin_bucket.replace('acs:oss:::', '')

        if bucket_distin_node.find('Format') is not None:
            inventory_format = _find_tag(bucket_distin_node, 'Format')
        if bucket_distin_node.find('Prefix') is not None:
            prefix = _find_tag(bucket_distin_node, 'Prefix')

        sse_kms_node = bucket_distin_node.find("Encryption/SSE-KMS")
        if sse_kms_node is not None:
            sse_kms_encryption = InventoryServerSideEncryptionKMS(_find_tag(sse_kms_node, 'KeyId'))
        elif bucket_distin_node.find("Encryption/SSE-OSS") is not None:
            sse_oss_encryption = InventoryServerSideEncryptionOSS()

        bucket_destination = InventoryBucketDestination(account_id=account_id, role_arn=role_arn, 
                bucket=bucket, inventory_format=inventory_format, prefix=prefix, 
                sse_kms_encryption=sse_kms_encryption, sse_oss_encryption=sse_oss_encryption)
 
        result.inventory_destination = InventoryDestination(bucket_destination)

    return result