Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
python3-s3fuse-plugin / usr / lib / python3.6 / site-packages / s3fuse / __pycache__ / vaults3.cpython-36.opt-1.pyc
Size: Mime:
3

†ƒ¬`^pã@spdZddlZddlZddlZddlZddlZddlZddlmZdZ	dZ
dZdd„Zd	d
„Z
Gdd„deƒZdS)
z Trilio S3 Backend implimentation

    This module contains the back end implimentation of all of all S3 specific
    support.
éN)ÚClientErrorÚs3ièz$80bc80ff-0c51-4534-86a2-ec5e719643c2cCs&|jdd}|tjdddƒjƒ}|S)zè Utility function used to convert a datetime to an OS timestamp.

    Args:
        modified_time (datetime): Datatime object to convert to a Unix Epoc timestamp.

    Returns:
        The value of modified_time as a timestamp.
    N)Ztzinfoi²é)ÚreplaceÚdatetimeZ
total_seconds)Z
modified_timeZ
naive_timeZ
delta_seconds©rú/usr/lib/python3.6/vaults3.pyÚ_make_timestamps	r	cCsZyF|j|dtjjdddddddƒ}|j||d	d
|j||dWn‚YnXdS)
a Validates the S3 credentials / permission on the provided bucket.

    Args:
        s3_client : Initialized boto3 S3 client object
        s3_bucket : User provided S3 bucket
    Returns:
        Does not return anything, But raises exception if validation fails.

    )ÚBucketztvault_config/z.workload_f5190be6-7f80-4856-8c24-149cb40500c5/z.snapshot_f2e5c6a7-3c21-4b7f-969c-915bb408c64f/z+vm_id_e81d1ac8-b49a-4ccf-9d92-5f1ef358f1be/z3vm_res_id_72477d99-c475-4a5d-90ae-2560f5f3b319_vda/z.deac2b8a-dca9-4415-adc1-f3c6598204ed-segments/z0000000000000000.00000000z	Test Data)r
ÚKeyÚBody)r
rN)Zhead_bucketÚosÚpathÚjoinÚ
put_objectÚ
delete_object)Ú	s3_clientZ	s3_bucketZlong_keyrrrÚvalidate_s3_client,s
rc@sžeZdZdZdd„Zdd„Zdd„Zdd	„Zd
d„Zd'd
d„Z	dd„Z
dd„Zd(dd„Zdd„Z
d)dd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„ZdS)*Ú	S3Backendz´ S3 Backend implimentation.

    A Wrapper for the AWS S3 boto3 and botocore API. This class encapsulates all S3
    operations and exposes them as a backend storage instance.
    c
Csæd}d}|ddkr2tjj|dt|dƒd}ntjjt|dƒd}|ddkrtjd|d	d
|d|d|d
|d	d||dd}n4tjd|d	d
|d|d|d
|d	d|d}t||dƒ||_|d|_dS)NZs3_signatureÚdefaultZs3_read_timeout)Zsignature_versionÚread_timeout)rZs3_ssl_certÚrZ
os_optionsÚregion_nameZs3_sslÚuserÚkeyZobject_storage_url)rÚuse_sslÚaws_access_key_idÚaws_secret_access_keyÚendpoint_urlÚconfigZverify)rrrrrrZbucket)ÚbotocoreZclientZConfigÚintÚboto3rÚ_S3Backend__clientÚ_S3Backend__bucket_name)ÚselfÚoptionsZ
config_objectrrrrÚ__init__Rs.



zS3Backend.__init__cCs–yzxtt|ƒdkrvg}|dt…}x0|D](}|jdƒr@|dd…}|jd|iƒq&W|jj|jd|id|td…}qWWntk
r‚YnXdS)zß Utility method that takes a list of objects and puts it in the correct format
            for the S3 delete_objects() API.

        Args:
            object_list (list): A list of objects with the correct S3 path.
        rNú/rrZObjects)r
ZDelete)ÚlenÚMAX_S3_PAGE_SIZEÚ
startswithÚappendr#Zdelete_objectsr$r)r%Úobject_listZobject_delete_listZ	list_partÚobjrrrZ__delete_object_list€s


zS3Backend.__delete_object_listcCs˜y|g}|jjdƒ}|j|j|d}xL|D]D}d|kr(|jdt|dƒƒdkr(x|dD]}|j|dƒqVWq(W|j|ƒWntk
r’‚YnXdS)z‘ Utility method used to perform a rmdir operation on an object hierarchy

        Args:
            object_tree (str): Object/Tree path.
        Úlist_objects)r
ÚPrefixÚContentsÚKeyCountrrN)	r#Ú
get_paginatorÚpaginater$Úgetr)r,Ú_S3Backend__delete_object_listr)r%Úobject_treer-Úlist_paginatorÚ
page_iteratorÚobjectsr.rrrZ__delete_object_tree™s
 zS3Backend.__delete_object_treecCs|j|ƒdS)zó Delete a list of objects.

        Args:
            object_list (list): List of objects. Each with a full object path
                                in correct format.
            options (dic): Dictionary of configuration options.
        N)r6)r%r-r&rrrÚdelete_object_list®szS3Backend.delete_object_listcCszy^|s
dSdj|ƒ}|jdƒr*|dd…}d|krF|jj|j|dn|jj|j|ddWntk
rt‚YnXdS)a Delete an object from the S3 object store.

        The object and any segments stored in the segment directory will be
        removed.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.
        Nr(rz	-segments)r
rz	.manifest)rr+r#rr$r)r%Úargsr&Úobject_namerrrr¸s





zS3Backend.delete_objectrcCs¤td|ƒ}y~xxtd|ƒD]j}y|jj|j|ddStk
r€}z2|jdddkrn|d|krntjdƒw‚WYdd}~XqXqWWntk
rž‚YnXdS)a Utility method used to wait for a S3 object to become available.

        This routine will keep performing a head_object() request every second
        for "retries" number of times. This was added to work around any potential
        eventual consistancey issues when uploading to AWS.

        Args:
            object_name (str): Name of the object.
            retries (int): Optional parameter that defaults to 1.

        Returns:
            Returns when the object is available or ClientError not found exception.
        rr)r
rNÚResponseMetadataÚHTTPStatusCodei”)	ÚmaxÚranger#Úhead_objectr$rÚresponseÚtimeÚsleep)r%r=ÚretriesÚretryÚerrorrrrZ__wait_for_objectÖs


zS3Backend.__wait_for_objectcCsÄ|jdƒd}y*|jj|j|d}tj|dj|dƒƒStk
r¾}zj|jdddkr`‚nNy6|j	|d	ƒ|jj|j|d}tj|dj|dƒƒStk
r¬‚YnXWYd
d
}~XnXd
S)zÓ Download and return the object manifest as a json array.

            Args:
                object_name (str): Name of the object.

            Returns:
                Object manifest as a dictionary.
        r(z	.manifest)r
rrÚ
ContentLengthr>r?iӎ
N)
Ústripr#Z
get_objectr$ÚjsonÚloadsÚreadrrCÚ_S3Backend__wait_for_object)r%r=Ú
manifest_nameZresprHrrrÚget_object_manifestõs	
zS3Backend.get_object_manifestcCsRy"dj|ƒ}|jj|j||jƒWn*tk
r8‚Yntk
rL‚YnXdS)a? Download a file from the S3 object store.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.

        Returns:
            On success, the contents of the object are downloaded to file identidfied
            by options.out_file.
        r(N)rr#Z
download_filer$Zout_filerÚ	Exception)r%r<r&r=rrrÚdownload_objects
zS3Backend.download_objectNTcCsDtƒ}dj|ƒ}|ddk	rB|d|d}|jdƒrB|dd…}yât}|dk	r^|tkr^|}|jjdƒ}|s†|j|jdd|id}	n|j|j|d|id}	x€|	D]v}
d	|
koÈ|
jd
t	|
d	ƒƒdkrÂ|d}xì|
d	D]à}|dk	oôt	|ƒ|krt
|ƒStjj
|djdƒƒ\}
}|d
kr\tjj
|
ƒ\}}t	|ƒdkrÞ|dkrÞ||krÞ|j|ƒqÞtjj
|ƒ\}}||
kr~|
|ksÞ|dksÞ|d|kr–qÞ|dks¨|
|krÞ|j|j
ddƒdƒqÞWd|
kr¤xP|
dD]D}|dk	røt	|ƒ|krøt
|ƒS|djtƒsÔ|j|dƒqÔWq¤Wt
|ƒStk
r>‚YnXdS)a° Return a list of objects based on the provided prefix.

        Used to generate a directory listing based on a prefix path
        constructed from the object parts in args[] and the options.prefix.

        Args:
            args (list): List of prefix keyParts
            options (dic): Dictionary of configuration options
            max_items (int): Maximum number of objects in a list query. Default is
                unlimited but when testing for an empty directory a smaller
                number can be used to limit the query and size of the list that
                is returned.
            strict_path_filter (bool): Defaults to True in order to only return
                objects with the exact same prefix. Individual segment listings
                set this to False in order to get a match on the segment offset.

        Returns:
            On success a list of unique items to be used as a directory listing.
        r(ÚprefixNrr/ZPageSize)r
Z	DelimiterÚPaginationConfig)r
r0rUr1r2rrzx.hiddenrFz	.manifestZCommonPrefixesr0éÿÿÿÿ)ÚsetrÚendswithr*r#r3r4r$r5r)Úlistr
rÚsplitÚrstripÚaddr+Ú_SEGMENT_PREFIXr)r%r<r&Z	max_itemsÚstrict_path_filterZ
object_setrTZ	page_sizer8r9r:Zsplit_tokenÚitemrr=Z	root_pathZsub_dirÚ_Z
object_prefixrrrr/%sZ

"

zS3Backend.list_objectscCsfyJg}tjj|jƒ\}}|j||dd}x|D]}|j|d|ƒq.W|Stk
r`‚YnXdS)a& Returns a list of object segments based on a prefix.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.

        Returns:
            A list of segments in the object store that match the supplied prefix.
        F)r^r(N)r
rrZrTr/r,r)r%r<r&Zsegment_listZ
segments_pathr`r-r_rrrÚ
list_segmentsˆs

zS3Backend.list_segmentsc/Cs„td|ƒ}yZxRtd|ƒD]B}y|jj|j|d}|Stk
r^}z|jdddkrLy|jj|j|dd}|Stk
rJ}z°|jdddkr8d|kry|jj|j|d	d}|Stk
r}z6|jdddkr
|d|kr
tjdƒw‚WYd
d
}~XnX|d|kr8tjdƒw‚WYd
d
}~XnX‚WYd
d
}~XqXqWWntk
r~‚YnXd
S)a= Utility method that gets an object head from the repository with retry support.

        The default is to try once. Admittedly, this is ugly because the
        provided object name might be a terminal object or a "directory" so
        we need to try both cases for each retry attempt. When retry > 1, there is
        a 1 second delay between attempts.

        Args:
            object_name (str): Name of the object.
            retries (int): Optional parameter, default is 1 attempt.

        Returns:
            Object head dictionary or Boto3 exception.
        rr)r
rr>r?i”r(z	-segmentsz	.manifestN)	r@rAr#rBr$rrCrDrE)r%r=rFrGZobj_headersrHrrrZ__get_object_headersžsB






zS3Backend.__get_object_headerscCs2dddddœ}i|d<i|dd<dj|ƒ}yè|sHttjjƒƒ|d<|S|j|ƒ}t|d	ƒ|d<||d<|jd
dƒdks†|d
dkrŽd|d<x0|ddjƒD]\}}d|kr ||d|<q Wt|ddjddƒƒdkrö|ddjddƒ|d<n|d
|d<|d|d<|SWntk
r,‚YnXdS)a) Get "operating system like" stat data for the given object.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.

        Returns:
            A stat structure containing object information required by caller.
        rrF)Ú	timestampÚsizeÚetagÚ	directoryZheadersÚMetadatar(rbZLastModifiedÚContentTypez
text/plainzapplication/x-directoryrITrez
x-object-metazx-object-meta-segment-countzx-object-meta-total-sizerczx-account-bytes-usedN)	rr	rZnowÚ_S3Backend__get_object_headersr5Úitemsr!r)r%r<r&Z	stat_datar=Z
obj_headerrÚvaluerrrÚstat_objectÐs2


zS3Backend.stat_objectcCsdj|ƒ}|j||ƒdS)zÎ Create an object that represents a directory in the object store.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.
        r(N)rÚ_S3Backend__create_folder)r%r<r&Z
new_folderrrrÚmkdir_objectüs
zS3Backend.mkdir_objectcCsDdj|ƒd}|jdƒr$|dd…}|j|ƒ|jj|j|ddS)zÎ Remove an object that represents a directory in the object store.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.
        r(rN)r
r)rr+Ú_S3Backend__delete_object_treer#rr$)r%r<r&r7rrrÚrmdir_objects


zS3Backend.rmdir_objectc
Cs|y`x*|D]"}|jdƒ|d<|jddƒ|d<qWtj|ƒ}|jdƒd}|jj|j|||dd	Wntk
rv‚YnXd
S)a? Upload a new object manifest to the object store.

        Args:
            object_name (str): Name of the object. A ".manifest" will be added.
            put_headers (dic): Dictionary of meta data to be added to the object.
            manifest_data (dic): The manifest data which becomes the body of file.
        rÚnamerdrÚhashr(z	.manifestz
text/plain)r
rrfrrgN)ÚpoprLÚdumpsrKr#rr$r)r%r=Zput_headersZ
manifest_dataZsegment_dataZmanifestrPrrrÚupload_object_manifests


z S3Backend.upload_object_manifestc)CsXy|jj|j|dWn:tk
rR}z|jdddkrB|jdƒ}d}xð|D]è}|dkrdP||d}y|jj|j|dWqVtk
r<}z˜|jdddkr*|ddkrÔ|jj|j|d	d
dnVy|jj|j|dd
dWn:tk
r(}z|jdddkr‚WYdd}~XnXwVWYdd}~XqVXqVWWYdd}~XnXdS)a< Utility method used to create a object directory structure.

        The entire path is split and each directory level is created as an object
        if it does not exist.

        Args:
            folder_name (str): The entire folder name.
            options (dic): Dictionary of configuration options.
        )r
rr>r?i”r(rZsupport_empty_dirTzx.hiddenz
Do Not Remove)r
rrzTrilioVault directory objectzapplication/x-directory)r
rrrgi™N)r#rBr$rrCrZr)r%Zfolder_namer&rHÚ
path_partsÚnew_pathÚpartrrrZ__create_folder0s4




zS3Backend.__create_foldercCs¨|dd…}y€|jdkr<|jtjj|dd|dƒ|ƒ|jdk	rŠt|ddƒ0}|jj||j	|dd|ddd	id
WdQRXWnt
k
r¢‚YnXdS)zµ Upload an object to the S3 object store.

        Args:
            args (list): List of object name parts.
            options (dic): Dictionary of configuration options.
        rNFrr(r=Úrbrgzapplication/octet-stream)r
rZ	ExtraArgs)Z
path_validrlr
rÚdirnamer=Úopenr#Zupload_fileobjr$r)r%r<r&ÚfilesÚdatarrrÚ
upload_object`s

zS3Backend.upload_object)r)NT)r)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r'r6rnr;rrOrQrSr/rarhrkrmrortrlr}rrrrrLs$.


c
2,0r)rrrDrLr
r"r Zbotocore.exceptionsrZBASENAMEr*r]r	rÚobjectrrrrrÚ<module>s