• File: aws_auth.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyc
  • Date Modified: 03/28/2024 3:28 PM
  • File size: 9.5 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

fc@sddlZddlZddlZddlZddlmZddlmZmZdZdZ	dZ
dejjfdYZ
dS(	iN(turlparse(tquotetunquotesUNSIGNED-PAYLOADcCs%tj||jdtjjS(sf
    Copied from https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
    sutf-8(thmactnewtencodethashlibtsha256tdigest(tkeytmsg((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pytsign)scCsMtd|jd|}t||}t||}t|d}|S(sf
    Copied from https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
    tAWS4sutf-8taws4_request(RR(R	t	dateStampt
regionNametserviceNametkDatetkRegiontkServicetkSigning((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pytgetSignatureKey0s
tAWSRequestsAuthcBs\eZdZdddddZdZdZdZedZ	edZ
RS(s
    Auth class that allows us to connect to AWS services
    via Amazon's signature version 4 signing process

    Adapted from https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
    c

CsU||_||_||_||_||_||_||_||_|	|_dS(s
        Example usage for talking to an AWS Elasticsearch Service:

        AWSRequestsAuth(aws_access_key='YOURKEY',
                        aws_secret_access_key='YOURSECRET',
                        aws_host='search-service-foobar.us-east-1.es.amazonaws.com',
                        aws_region='us-east-1',
                        aws_service='es',
                        aws_token='...')

        The aws_token is optional and is used only if you are using STS
        temporary credentials.
        N(	taws_access_keytaws_secret_access_keytaws_hostt
aws_regiontservicet	aws_tokentss_algorithmtencryption_keytencryption_key_md5(
tselfRRRRtaws_serviceRRRR((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyt__init__Cs								cCs#|j|}|jj||S(s
        Adds the authorization headers required by Amazon's signature
        version 4 signing process to the request.

        Adapted from https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
        (tget_aws_request_headers_handlertheaderstupdate(R trtaws_headers((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyt__call__dsc	Cs+|jd|d|jd|jd|jS(sN
        Override get_aws_request_headers_handler() if you have a
        subclass that needs to call get_aws_request_headers() with
        an arbitrary set of AWS credentials. The default implementation
        calls get_aws_request_headers() with self.aws_access_key,
        self.aws_secret_access_key, and self.aws_token
        R&RRR(tget_aws_request_headersRRR(R R&((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyR#os		cCs4tjj}|jd}|jd}tj|}tj|}	d|jdd|d}
|r|
d|d7}
n|jdkr|jr|
d|jd7}
n|jd	kr|jr|
d|jd7}
|
d
|jd7}
n|jdkrS|jrS|
d|jd7}
|
d|jd7}
|
d
|j	d7}
nd}|rl|d7}n|jdkr|jr|d7}n|jd	kr|jr|d7}n|jdkr|jr|d7}n|j
r|j
nt}y|jd}Wnt
tfk
r)|}nXt|trQtj|j}
nt}
|jd|d|	d|
d|d|
}d}|d|jd|jdd}|d|d|dtj|jdj}t|||j|j}|jd}tj||tjj}|dd|d|dd|dd|}i|d6|
d6|d6}|r||d<n|jdkr|jr|j|d <n|jd	kr|jr|j|d <|j|d!<n|jdkr0|jr0|j|d"<|j|d#<|j	|d$<n|S(%s
        Returns a dictionary containing the necessary headers for Amazon's
        signature version 4 signing process. An example return value might
        look like

            {
                'Authorization': 'AWS4-HMAC-SHA256 Credential=YOURKEY/20160618/us-east-1/es/aws4_request, '
                                 'SignedHeaders=host;x-amz-date, '
                                 'Signature=ca0a856286efce2a4bd96a978ca6c8966057e53184776c0685169d08abd74739',
                'x-amz-date': '20160618T220405Z',
            }
        s%Y%m%dT%H%M%SZs%Y%m%dshost:s
sx-amz-date:sx-amz-security-token:tAES256sx-amz-server-side-encryption:saws:kmss,x-amz-server-side-encryption-aws-kms-key-id:s0x-amz-server-side-encryption-customer-algorithm:s*x-amz-server-side-encryption-customer-key:s.x-amz-server-side-encryption-customer-key-MD5:shost;x-amz-dates;x-amz-security-tokens;x-amz-server-side-encryptionsI;x-amz-server-side-encryption;x-amz-server-side-encryption-aws-kms-key-ids;x-amz-server-side-encryption-customer-algorithm;x-amz-server-side-encryption-customer-key;x-amz-server-side-encryption-customer-key-MD5sutf-8sAWS4-HMAC-SHA256t/R
t sCredential=s, sSignedHeaders=s
Signature=t
Authorizationsx-amz-content-sha256s
x-amz-datesX-Amz-Security-Tokensx-amz-server-side-encryptions+x-amz-server-side-encryption-aws-kms-key-ids/x-amz-server-side-encryption-customer-algorithms)x-amz-server-side-encryption-customer-keys-x-amz-server-side-encryption-customer-key-MD5(tdatetimetutcnowtstrftimeRtget_canonical_pathtget_canonical_querystringRRRRtbodytbytesRtAttributeErrortUnicodeDecodeErrort
isinstanceRRt	hexdigesttUNSIGNED_PAYLOADtmethodRRRRR(R R&RRRtttamzdatet	datestampt
canonical_uritcanonical_querystringtcanonical_headerstsigned_headersR3tpayload_hashtcanonical_requestt	algorithmtcredential_scopetstring_to_signtsigning_keytstring_to_sign_utf8t	signaturetauthorization_headerR$((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyR)|s~




1$6	2




cCs7t|j}t|jr*t|jndddS(s
        Create canonical URI--the part of the URI from domain to query
        string (use '/' if no path)
        https://github.com/boto/boto/blob/d9e5cfe900e1a58717e393c76a6e3580305f217a/boto/auth.py#L574
        R+tsafes/-_.~(RturlRtpathR(tclsR&t	parsedurl((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyR1scCs6d}t|j}djt|jjd}x|jdD]}|jdd}t|d}|d|krt|dddn|d}t|dkrt|d}	|d|	krt|dddn|d}
nd}
|rF|r|d7}n|dj||
g7}qFqFW|S(	sf
        Create the canonical query string. According to AWS, by the
        end of this function our query string values must
        be URL-encoded (space=%20) and the parameters must be sorted
        by name.

        This method assumes that the query params in `r` are *already*
        url encoded.  If they are not url encoded by the time they make
        it to this function, AWS may complain that the signature for your
        request is incorrect.

        It appears elasticsearc-py url encodes query paramaters on its own:
            https://github.com/elastic/elasticsearch-py/blob/5dfd6985e5d32ea353d2b37d01c2521b2089ac2b/elasticsearch/connection/http_requests.py#L64

        If you are using a different client than elasticsearch-py, it
        will be your responsibility to urleconde your query params before
        this method is called.
        tt&t=iiRKs-_.~u=(	RRLtjointsortedtquerytsplitRRtlen(RNR&R?ROtquerystring_sortedtquery_paramt
key_val_splitt	unenc_keyR	t	unenc_valtval((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyR2s !03
 N(t__name__t
__module__t__doc__tNoneR"R(R#R)tclassmethodR1R2(((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyR;s		
	(R.RRtrequestsRturllibRRR9RRtauthtAuthBaseR(((sN/usr/lib/python2.7/site-packages/redhat_support_lib/infrastructure/aws_auth.pyt<module>s