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

䓍aJšã@sldZddlZddlZddlZddlZddlZddlZddlmZdZ	dZ
dZdZdd	„Z
Gd
d„deƒ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-ec5e719643c2iôcCs&|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	c@sÆeZdZdZdd„Zdd„Zdd„Zdd	„Zd
d„Zdd
„Z	d1dd„Z
dd„Zdd„Zdd„Z
d2dd„Zdd„Zd3dd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'd(„Zd)d*„Zd+d,„Zd-d.„Zd/d0„ZdS)4Ú	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}||_|jdƒr&t|jdƒƒnt}|ddkrVtjj|dt|dƒ|d}ntjjt|dƒ|d}|ddkr°tjd	|d
d|d|d
|d
d||dd}n.tjd	|d
d|d|d
|d
d|d}||_|d|_	dS)NZvault_s3_max_pool_connectionsZs3_signatureÚdefaultZs3_read_timeout)Zsignature_versionÚread_timeoutÚmax_pool_connections)rr
Zs3_ssl_certÚrZ
os_optionsÚregion_nameÚuserÚkeyZobject_storage_url)rÚaws_access_key_idÚaws_secret_access_keyÚendpoint_urlÚconfigZverify)rrrrrZbucket)
ÚoptionsÚgetÚintÚDEFAULT_MAX_POOL_SIZEÚbotocoreZclientZConfigÚboto3Ú_S3Backend__clientÚ_S3Backend__bucket_name)ÚselfrZ
config_objectZ	s3_clientZ
MAX_POOL_SIZErrrÚ__init__6s4





zS3Backend.__init__cCsúyæ|jj|jdy^|jj|jd}|drH|dddkrHtd|ƒ‚|drn|dddkrntd|ƒ‚Wn,tk
rœ}z|drŒ‚WYdd}~XnX|dsätjjdd	d
ddd
dƒ}|jj	|j|dd|jj
|j|dWn‚YnXdS)ah Validates the S3 credentials / permission on the provided bucket.
            It also validates against s3 object lock configuration and if the s3 supports
            more than 255 object name length

        Args:
            self : S3 Backend object
        Returns:
            Does not return anything, But raises exception if validation fails.

        )ÚBucketÚbucket_object_lockZObjectLockConfigurationZObjectLockEnabledZEnabledzZConfigration says object lock enabled on the bucket, but s3 API does not agree with it. %sNztvault_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 r")rZhead_bucketrZget_object_lock_configurationZExceptonÚ	ExceptionÚosÚpathÚjoinÚ
put_objectÚ
delete_object)rrZobj_lock_cfgZexZlong_keyrrrÚvalidate_s3_clienths:
zS3Backend.validate_s3_clientcCsÌy°xªt|ƒdkr¬g}|dt…}x0|D](}|jdƒr@|dd…}|jd|iƒq&Wy|jj|jd|idWn0x"|D]}|jj|j|ddqzWYnX|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ú/rr"ÚObjects)r ÚDelete)r r")	ÚlenÚMAX_S3_PAGE_SIZEÚ
startswithÚappendrÚdelete_objectsrr)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ÚKeyCountrr"N)	rÚ
get_paginatorÚpaginaterrr.r1Ú_S3Backend__delete_object_listr)rÚobject_treer3Úlist_paginatorÚ
page_iteratorÚobjectsr4rrrZ__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)r;)rr3rrrrÚdelete_object_listÉszS3Backend.delete_object_listcCs¬y|s
dSdj|ƒ}|jdƒr*|dd…}d|krF|jj|j|dnH|jdƒd}|j|dd}|rxt|dd	d
}n|}|jj|j|dWntk
r¦‚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 r"z	.manifestT)Ústrict_path_filter)Úreverser)	r'r0rr)rÚstripr5Úsortedr)rÚargsrÚobject_nameÚmanifest_prefixÚ	manifestsÚ
manifest_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 r"NÚResponseMetadataÚHTTPStatusCodei”)	ÚmaxÚrangerÚhead_objectrrÚresponseÚtimeÚsleep)rrFÚretriesÚretryÚerrorrrrZ__wait_for_objectös


zS3Backend.__wait_for_objectcCsœy|jdƒd}|jdr0|jj|j|d}n|jj|j|d}|rÖ|}|jdgƒp`|jdgƒ}|jdrÊx\|D]T}|jj|j|d|jdd	ƒd
}|ddjd
dƒdkrrtj	|dj
|dƒƒSqrW|dd}|sâtdƒ‚|jj|j|d}tj	|dj
|dƒƒStk
r–}zn|j
dddkr6‚nPy6|j|dƒ|jj|j|d}tj	|dj
|dƒƒStk
r„‚YnXWYdd}~XnXdS)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	.manifestr!)r r6ÚVersionsr7r"Ú	VersionIdr)r r"rVrJÚHTTPHeadersz$x-amz-meta-stamp-trilio-authenticityÚFalseÚTruer#Ú
ContentLengthrzOManifest object with 'x-amz-meta-stamp-trilio-authenticity' attribute not found)r r"rKiӎ
Néÿÿÿÿ)rCrrÚlist_object_versionsrr5rZ
get_objectÚjsonÚloadsÚreadr$rrOÚ_S3Backend__wait_for_object)rrFrGrHrIÚmanifestÚresprTrrrÚget_object_manifestsH	





zS3Backend.get_object_manifestcCsà|jdƒd}|jdr,|jj|j|d}n|jj|j|d}|rÐ|jdgƒpX|jdgƒ}g}x|D]}|jd|diƒqdW|rÜy|jj|jd|id	WqÜx"|D]}|jj	|j|dd
qªWYqÜXnt
d|ƒ‚d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	.manifestr!)r r6rUr7r"r,)r r-)r r"zManifest for %s is not foundN)rCrrr]rr5rr1r2r)r$)rrFrGrcrHÚobjs_to_deleteÚmanr4rrrÚdelete_object_manifestJs,	





z S3Backend.delete_object_manifestcCshy8dj|ƒ}i}|jr d|ji}|jj|j||j|ƒWn*tk
rN‚Yntk
rb‚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+rVN)r'Z
version_idrZ
download_filerZout_filerr$)rrErrFZ
extra_argsrrrÚdownload_objectms

zS3Backend.download_objectNFcCsŽtƒ}|jdƒ}y^t}|dk	r,|tkr,|}|jjdƒ}|j|j|dd|id}x|D]}d|krè|jdt|dƒƒdkrèxh|dD]\}	|dk	r¨t|ƒ|kr¨t	|ƒS|	d	j
dƒ}
|rÆ|j|
ƒqˆd
|
krˆ|j|
jd
dƒdƒqˆWd|krXxt|dD]h}|dk	rt|ƒ|krt	|ƒS|d
j
tƒsú|jdƒrN|j|d
jdƒƒqú|j|d
jdƒƒqúWqXWt	|ƒStk
rˆ‚YnXdS)ae 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 prefix

        Args:
            prefix (string): prefix of the object path. If the prefix is terminated 
                by "/", then it lists the contents in the "subdir". If the prefix
                is not terminated by "/", then it lists the contents in the current
                directory that matches the prefix
                Ex:
                    case 1:
                    =======
                    prefix - /a/b/c
                    object store has objects - /a/b/c, /a/b/c1, /a/b/d
                    return values - /a/b/c and /a/b/c1

                    case 2:
                    =======
                    prefix - /a/b/c/
                    object store has objects - /a/b/c/d, /a/b/c1, /a/b/c/e
                    return values - /a/b/c/d and /a/b/c/e
            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+Nr5ZPageSize)r r6Z	DelimiterZPaginationConfigr7r8rr"z	.manifestrZCommonPrefixesr6)ÚsetÚlstripr/rr9r:rrr.ÚlistÚrstripÚaddÚsplitr0Ú_SEGMENT_PREFIXÚendswithrCr)rÚprefixZ	max_itemsrAZ
object_setZ	page_sizer=r>r?ÚitemrFZ
object_prefixrrrr5…s@#
 zS3Backend.list_objectscCsHy,g}tjjdj|ƒ|jƒ}|j|dd}|Stk
rB‚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.
        r+T)rAN)r%r&r'rqr5r)rrErZsegment_listZ
segments_pathr3rrrÚ
list_segmentsØs

zS3Backend.list_segmentsc
/Csjtd|ƒ}y@x8td|ƒD](}y|jj|j|d}|Stk
rD}zì|jdddkr2y|jj|j|dd}|Stk
r0}z”|jdddkrd|kryü|jdƒd	}|jd
rà|jj	|j|d}n|jj
|j|d}|rŒ|}|jdgƒp|jd
gƒ}t|dd„d}|jd
r€xL|D]D}	|jj|j|	d|	jddƒd}|ddjddƒdkr8|Sq8W|dd}|sšt
dƒ‚|jj|j|d}|Stk
r}z6|jdddkrð|d|krðtjdƒw‚WYdd}~XnX|d|krtjdƒw‚WYdd}~XnX‚WYdd}~XqXqWWntk
rd‚YnXdS)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 r"rJrKi”r+z	-segmentsz	.manifestr!)r r6rUr7cSs|dS)NÚLastModifiedr)ÚkrrrÚ<lambda>sz0S3Backend.__get_object_headers.<locals>.<lambda>)rr"rVr)r r"rVrWz$x-amz-meta-stamp-trilio-authenticityrXrYzOManifest object with 'x-amz-meta-stamp-trilio-authenticity' attribute not foundNr\)rLrMrrNrrrOrCrr]r5rrDr$rPrQ)
rrFrRrSÚobj_headersrTrGrHrIrbrrrZ__get_object_headersísr











zS3Backend.__get_object_headerscCsldddddœ}i|d<i|dd<dj|ƒ}y |sJttjjƒƒ|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<nDt|ddjddƒƒdkr0|ddjddƒ|d<n|d
|d<|d|d<|SWntk
rf‚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+rxrtÚContentTypez
text/plainzapplication/x-directoryrZTr{z
x-object-metazx-object-meta-segment-countzx-object-meta-total-sizeryz
segment-countz
total-sizezx-account-bytes-usedN)	r'r	rZnowÚ_S3Backend__get_object_headersrÚitemsrr)rrErZ	stat_datarFZ
obj_headerrÚvaluerrrÚstat_object<s<


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)rrErZ
new_folderrrrÚmkdir_objectms
zS3Backend.mkdir_objectc
CsVdj|ƒd}|jdƒr$|dd…}|j|ƒy|jj|j|dWnYnXdS)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")r'r0Ú_S3Backend__delete_object_treerr)r)rrErr<rrrÚrmdir_objectxs


zS3Backend.rmdir_objectc
CsHy(|jdƒd}|j|dd}|rRtt|dddjdƒdd	ƒ}d
|d}nd
d}x*|D]"}|jdƒ|d<|jd
dƒ|d<q`Wtj|ƒ}|d|}	|jj	|j
|	||dd|r(g}
x|D]}|
jd|iƒqÄWy|jj|j
d|
idWn2x$|
D]}|jj
|j
|ddqWYnXWntk
rB‚YnXdS)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+z	.manifestT)rA)rBrÚ.réz%08xr&ÚnamerzÚhashz
text/plain)r r"r|r#r}r"r,)r r-)r r"Nr\)rCr5rrDrnÚpopr^Údumpsrr(rr1r2r)r)
rrFZput_headersZ
manifest_datarGrHÚsuffixZsegment_datarbrIrerfr4rrrÚupload_object_manifestŒs> 






z S3Backend.upload_object_manifestc
Cs¦yŠ|jdƒd}|j|dd}|rLtt|dddjdƒdd	ƒ}d
|}nd
d}|d|}tjj|j|ƒ}|j	j
|j|||ddWntk
r ‚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+z	.manifestT)rA)rBrr†rr‡z%08xZREPLACE)r r"Z
CopySourcer|ZMetadataDirectiveNr\)rCr5rrDrnr%r&r'rrZcopy_objectr)rrFZ
attributesrGrHrŒrIZcopy_srcrrrÚupdate_object_attributes·s" 

z"S3Backend.update_object_attributescCsDy(|jdƒ}|jj|j|d|dœdWntk
r>‚YnXdS)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+Ú
GOVERNANCE)ÚModeÚRetainUntilDate)r r"Ú	RetentionN)rCrÚput_object_retentionrr)rrFÚretainuntilrrrÚput_object_segment_retentionÔs
z&S3Backend.put_object_segment_retentioncCs˜y||jdƒd}|j|dd}|rLtt|dddjdƒdd	ƒ}d
|}nd
d}|d|}|jj|j|d|dœd
Wntk
r’‚YnXdS)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+z	.manifestT)rA)rBrr†rr‡z%08xr)rr‘)r r"r’Nr\)	rCr5rrDrnrr“rr)rrFr”rGrHrŒrIrrrÚput_manifest_retentionès 
z S3Backend.put_manifest_retentionc)Cs*y|jj|j|dWntk
r$}zî|jdddkr|jdƒ}d}xÄ|D]¼}|dkrbP||d}y|jj|j|dWqTtk
r}zl|jdddkrüy|jj|j|ddd	Wn6tk
rú}z|jddd
krê‚WYdd}~XnXwTWYdd}~XqTXqTWWYdd}~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 r"rJrKi”r+rzTrilioVault directory objectzapplication/x-directory)r r"r#r}i™N)rrNrrrOrnr()rZfolder_namerrTÚ
path_partsÚnew_pathÚpartrrrZ__create_folders0


zS3Backend.__create_foldercCsÊ|dd…}y¢|jdkr<|jtjj|dd|dƒ|ƒ|jdk	r¬t|ddƒR}|jj||j	|dd|ddd	id
|jj
|j	|dd|dd}|SQRXWntk
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+rFÚrbr}zapplication/octet-stream)r r"Z	ExtraArgs)r r")Z
path_validr‚r%r&ÚdirnamerFÚopenrZupload_fileobjrrNr)rrErÚfilesÚdatarwrrrÚ
upload_object.s"




zS3Backend.upload_object)r)NF)r)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rr*r;r„r@r)rardrgrhr5rsr~rrƒr…rrŽr•r–r‚rŸrrrrr
/s.2-
#
5#
S
O1+*r
)r£rrPr^r%rrZbotocore.exceptionsrZBASENAMEr/rorr	Úobjectr
rrrrÚ<module>s