edgegrid-python-1.1.1/0000755005015000011300000000000013323171757015353 5ustar jlandisstaff00000000000000edgegrid-python-1.1.1/requirements.txt0000644005015000011300000000007112542400703020621 0ustar jlandisstaff00000000000000requests>=2.3.0 pyopenssl ndg-httpsclient pyasn1 urllib3 edgegrid-python-1.1.1/PKG-INFO0000644005015000011300000000047013323171757016451 0ustar jlandisstaff00000000000000Metadata-Version: 1.0 Name: edgegrid-python Version: 1.1.1 Summary: {OPEN} client authentication protocol for python-requests Home-page: https://github.com/akamai-open/AkamaiOPEN-edgegrid-python Author: Jonathan Landis Author-email: jlandis@akamai.com License: LICENSE.txt Description: UNKNOWN Platform: UNKNOWN edgegrid-python-1.1.1/LICENSE0000644005015000011300000002404112474375022016356 0ustar jlandisstaff00000000000000Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. edgegrid-python-1.1.1/setup.py0000644005015000011300000000112113323171511017044 0ustar jlandisstaff00000000000000from setuptools import setup, find_packages setup( name='edgegrid-python', version='1.1.1', description='{OPEN} client authentication protocol for python-requests', author='Jonathan Landis', author_email='jlandis@akamai.com', url='https://github.com/akamai-open/AkamaiOPEN-edgegrid-python', namespace_packages=['akamai'], packages=find_packages(), python_requires=">=2.7.10", install_requires = [ 'requests>=2.3.0', 'pyOpenSSL >= 0.13', 'ndg-httpsclient', 'pyasn1', 'urllib3' ], license='LICENSE.txt' ) edgegrid-python-1.1.1/README.rst0000644005015000011300000000652513323171365017045 0ustar jlandisstaff00000000000000EdgeGrid for Python =================== This library implements an Authentication handler for `requests`_ that provides the `Akamai {OPEN} Edgegrid Authentication`_ scheme. For more information visit the `Akamai {OPEN} Developer Community`_. .. code-block:: pycon >>> import requests >>> from akamai.edgegrid import EdgeGridAuth >>> from urlparse import urljoin >>> baseurl = 'https://akaa-WWWWWWWWWWWW.luna.akamaiapis.net/' >>> s = requests.Session() >>> s.auth = EdgeGridAuth( client_token='ccccccccccccccccc', client_secret='ssssssssssssssssss', access_token='aaaaaaaaaaaaaaaaaaaaa' ) >>> result = s.get(urljoin(baseurl, '/diagnostic-tools/v2/ghost-locations/available')) >>> result.status_code 200 >>> result.json()['locations'][0]['value'] Oakbrook, IL, United States ... Alternatively, your program can read the credentials from an .edgerc file. .. code-block:: pycon >>> import requests >>> from akamai.edgegrid import EdgeGridAuth, EdgeRc >>> from urlparse import urljoin >>> edgerc = EdgeRc('~/.edgerc') >>> section = 'default' >>> baseurl = 'https://%s' % edgerc.get(section, 'host') >>> s = requests.Session() >>> s.auth = EdgeGridAuth.from_edgerc(edgerc, section) >>> result = s.get(urljoin(baseurl, '/diagnostic-tools/v2/ghost-locations/available')) >>> result.status_code 200 >>> result.json()['locations'][0]['value'] Oakbrook, IL, United States ... .. _`requests`: http://docs.python-requests.org .. _`Akamai {OPEN} Edgegrid authentication`: https://developer.akamai.com/introduction/Client_Auth.html .. _`Akamai {OPEN} Developer Community`: https://developer.akamai.com Installation ------------ Pre-requisite ------------- If you are installing on a Linux based distribution, you will need to instal the developer libraries for python, ssl and a ffi. On Ubuntu based systems, you will need to do the following: .. code-block:: bash $ sudo apt-get install ibssl-dev libffi-dev python-dev To install from pip: .. code-block:: bash $ pip install edgegrid-python To install from sources: .. code-block:: bash $ python setup.py install To run tests: .. code-block:: bash $ virtualenv -p python2.7 venv $ . venv/bin/activate $ pip install -r requirements.txt $ python -m unittest discover Contribute ---------- #. Fork `the repository`_ to start making your changes to the **master** branch #. Write a test which shows that the bug was fixed or that the feature works as expected. #. Send a pull request and bug the maintainer until it gets merged and published. :) .. _`the repository`: https://github.com/akamai-open/AkamaiOPEN-edgegrid-python Author ------ Jonathan Landis License ------- Copyright 2015 Akamai Technologies, Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. edgegrid-python-1.1.1/edgegrid_python.egg-info/0000755005015000011300000000000013323171757022220 5ustar jlandisstaff00000000000000edgegrid-python-1.1.1/edgegrid_python.egg-info/PKG-INFO0000644005015000011300000000047013323171757023316 0ustar jlandisstaff00000000000000Metadata-Version: 1.0 Name: edgegrid-python Version: 1.1.1 Summary: {OPEN} client authentication protocol for python-requests Home-page: https://github.com/akamai-open/AkamaiOPEN-edgegrid-python Author: Jonathan Landis Author-email: jlandis@akamai.com License: LICENSE.txt Description: UNKNOWN Platform: UNKNOWN edgegrid-python-1.1.1/edgegrid_python.egg-info/top_level.txt0000644005015000011300000000000713323171757024747 0ustar jlandisstaff00000000000000akamai edgegrid-python-1.1.1/edgegrid_python.egg-info/requires.txt0000644005015000011300000000010113323171757024610 0ustar jlandisstaff00000000000000requests>=2.3.0 pyOpenSSL >= 0.13 ndg-httpsclient pyasn1 urllib3 edgegrid-python-1.1.1/edgegrid_python.egg-info/SOURCES.txt0000644005015000011300000000077113323171757024111 0ustar jlandisstaff00000000000000LICENSE MANIFEST.in README.rst requirements.txt setup.py akamai/__init__.py akamai/edgegrid/__init__.py akamai/edgegrid/edgegrid.py akamai/edgegrid/edgerc.py akamai/edgegrid/test/__init__.py akamai/edgegrid/test/test_edgegrid.py akamai/edgegrid/test/testdata.json edgegrid_python.egg-info/PKG-INFO edgegrid_python.egg-info/SOURCES.txt edgegrid_python.egg-info/dependency_links.txt edgegrid_python.egg-info/namespace_packages.txt edgegrid_python.egg-info/requires.txt edgegrid_python.egg-info/top_level.txtedgegrid-python-1.1.1/edgegrid_python.egg-info/dependency_links.txt0000644005015000011300000000000113323171757026266 0ustar jlandisstaff00000000000000 edgegrid-python-1.1.1/edgegrid_python.egg-info/namespace_packages.txt0000644005015000011300000000000713323171757026550 0ustar jlandisstaff00000000000000akamai edgegrid-python-1.1.1/akamai/0000755005015000011300000000000013323171757016576 5ustar jlandisstaff00000000000000edgegrid-python-1.1.1/akamai/edgegrid/0000755005015000011300000000000013323171757020350 5ustar jlandisstaff00000000000000edgegrid-python-1.1.1/akamai/edgegrid/test/0000755005015000011300000000000013323171757021327 5ustar jlandisstaff00000000000000edgegrid-python-1.1.1/akamai/edgegrid/test/testdata.json0000644005015000011300000003105013155560410024021 0ustar jlandisstaff00000000000000{ "base_url": "https://akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net/", "access_token": "akab-access-token-xxx-xxxxxxxxxxxxxxxx", "client_token":"akab-client-token-xxx-xxxxxxxxxxxxxxxx", "client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=", "max_body": 2048, "headers_to_sign": [ "X-Test1", "X-Test2", "X-Test3" ], "nonce": "nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "timestamp": "20140321T19:34:21+0000", "jsontest_hash": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=nONuDe50qGrPius4Rg4D2jfi/2zDZWAYRUG6RudJLNM=", "tests": [ { "testName": "simple GET", "request": { "method": "GET", "path": "/", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=tL+y4hxyHxgWVD30X3pWnGKHcPzmrIF+LThiAOhMxYU=" }, { "testName": "GET with querystring", "request": { "method": "GET", "path": "/testapi/v1/t1?p1=1&p2=2", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=hKDH1UlnQySSHjvIcZpDMbQHihTQ0XyVAKZaApabdeA=" }, { "testName": "POST inside limit", "request": { "method": "POST", "path": "/testapi/v1/t3", "data": "datadatadatadatadatadatadatadata", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=hXm4iCxtpN22m4cbZb4lVLW5rhX8Ca82vCFqXzSTPe4=" }, { "testName": "POST too large", "request": { "method": "POST", "path": "/testapi/v1/t3", "data": "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=6Q6PiTipLae6n4GsSIDTCJ54bEbHUBp+4MUXrbQCBoY=" }, { "testName": "POST length equals max_body", "request": { "method": "POST", "path": "/testapi/v1/t3", "data": "dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=6Q6PiTipLae6n4GsSIDTCJ54bEbHUBp+4MUXrbQCBoY=" }, { "testName": "POST empty body", "request": { "method": "POST", "path": "/testapi/v1/t6", "data": "", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=1gEDxeQGD5GovIkJJGcBaKnZ+VaPtrc4qBUHixjsPCQ=" }, { "testName": "Simple header signing with GET", "request": { "method": "GET", "path": "/testapi/v1/t4", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"}, {"X-Test1": "test-simple-header"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=8F9AybcRw+PLxnvT+H0JRkjROrrUgsxJTnRXMzqvcwY=" }, { "testName": "Header containing spaces", "request": { "method": "GET", "path": "/testapi/v1/t4", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"}, {"X-Test1": "\" test-header-with-spaces \""} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=ucq2AbjCNtobHfCTuS38fdkl5UDdWHZhQX46fYR8CqI=" }, { "testName": "Header with leading and interior spaces", "request": { "method": "GET", "path": "/testapi/v1/t4", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"}, {"X-Test1": " first-thing second-thing"} ] }, "failsWithMessage": "Invalid return character or leading space in header: X-Test1", "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=WtnneL539UadAAOJwnsXvPqT4Kt6z7HMgBEwAFpt3+c=" }, { "testName": "Headers out of order", "request": { "method": "GET", "path": "/testapi/v1/t4", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"}, {"X-Test2": "t2"}, {"X-Test1": "t1"}, {"X-Test3": "t3"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=Wus73Nx8jOYM+kkBFF2q8D1EATRIMr0WLWwpLBgkBqY=" }, { "testName": "Extra header", "request": { "method": "GET", "path": "/testapi/v1/t5", "headers": [ {"Host": "akaa-baseurl-xxxxxxxxxxx-xxxxxxxxxxxxx.luna.akamaiapis.net"}, {"X-Test2": "t2"}, {"X-Test1": "t1"}, {"X-Test3": "t3"}, {"X-Extra": "this won't be included"} ] }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=Knd/jc0A5Ghhizjayr0AUUvl2MZjBpS3FDSzvtq4Ixc=" }, { "testName": "PUT test", "request": { "method": "PUT", "path": "/testapi/v1/t6", "data": "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP" }, "expectedAuthorization": "EG1-HMAC-SHA256 client_token=akab-client-token-xxx-xxxxxxxxxxxxxxxx;access_token=akab-access-token-xxx-xxxxxxxxxxxxxxxx;timestamp=20140321T19:34:21+0000;nonce=nonce-xx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;signature=GNBWEYSEWOLtu+7dD52da2C39aX/Jchpon3K/AmBqBU=" } ] } edgegrid-python-1.1.1/akamai/edgegrid/test/test_edgegrid.py0000644005015000011300000001707113155560410024507 0ustar jlandisstaff00000000000000# # unit tests for edgegrid. runs tests from testdata.json # # Original author: Jonathan Landis # # For more information visit https://developer.akamai.com # Copyright 2014 Akamai Technologies, Inc. All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import json import logging import os import re import requests import sys import traceback import unittest PY_VER = sys.version_info[0] if sys.version_info[0] == 3: # python3 from urllib.parse import urljoin else: # python2.7 from urlparse import urljoin from akamai.edgegrid import EdgeGridAuth, EdgeRc import akamai.edgegrid.edgegrid as eg mydir=os.path.abspath(os.path.dirname(__file__)) logger = logging.getLogger(__name__) class EdgeGridTest(unittest.TestCase): def __init__(self, testdata=None, testcase=None): super(EdgeGridTest, self).__init__() self.testdata = testdata self.testcase = testcase self.maxDiff = None def runTest(self): auth = EdgeGridAuth( client_token=self.testdata['client_token'], client_secret=self.testdata['client_secret'], access_token=self.testdata['access_token'], headers_to_sign=self.testdata['headers_to_sign'], max_body=self.testdata['max_body'] ) headers = { } if 'headers' in self.testcase['request']: for h in self.testcase['request']['headers']: for k,v in h.items(): headers[k] = v request = requests.Request( method=self.testcase['request']['method'], url=urljoin(self.testdata['base_url'],self.testcase['request']['path']), headers=headers, data=self.testcase['request'].get('data') if self.testcase['request'].get('data') \ else None ) try: auth_header = auth.make_auth_header( request.prepare(), self.testdata['timestamp'], self.testdata['nonce'] ) except Exception as e: logger.debug('Got exception from make_auth_header', exc_info=True) self.assertEqual(str(e), self.testcase['failsWithMessage']) return self.assertEqual(auth_header, self.testcase['expectedAuthorization']) class EGSimpleTest(unittest.TestCase): def test_nonce(self): count = 100 nonces = set() while count > 0: n = eg.new_nonce() self.assertNotIn(n, nonces) count -= 1 def test_timestamp(self): valid_timestamp = re.compile(r""" ^ \d{4} # year [0-1][0-9] # month [0-3][0-9] # day T [0-2][0-9] # hour : [0-5][0-9] # minute : [0-5][0-9] # second \+0000 # timezone $ """, re.VERBOSE) if PY_VER >= 3: self.assertRegex(eg.eg_timestamp(), valid_timestamp) else: self.assertRegexpMatches(eg.eg_timestamp(), valid_timestamp) def test_defaults(self): auth = EdgeGridAuth( client_token='xxx', client_secret='xxx', access_token='xxx' ) self.assertEqual(auth.max_body, 131072) self.assertEqual(auth.headers_to_sign, []) def test_edgerc_default(self): auth = EdgeGridAuth.from_edgerc(os.path.join(mydir, 'sample_edgerc')) self.assertEqual(auth.client_token, 'xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx') self.assertEqual(auth.client_secret, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=') self.assertEqual(auth.access_token, 'xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx') self.assertEqual(auth.max_body, 131072) self.assertEqual(auth.headers_to_sign, []) def test_edgerc_broken(self): auth = EdgeGridAuth.from_edgerc(os.path.join(mydir, 'sample_edgerc'), 'broken') self.assertEqual(auth.client_secret, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=') self.assertEqual(auth.access_token, 'xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx') self.assertEqual(auth.max_body, 128*1024) self.assertEqual(auth.headers_to_sign, []) def test_edgerc_unparseable(self): try: auth = EdgeGridAuth.from_edgerc(os.path.join(mydir, 'edgerc_that_doesnt_parse')) self.fail("should have thrown an exception") except: pass def test_edgerc_headers(self): auth = EdgeGridAuth.from_edgerc(os.path.join(mydir, 'sample_edgerc'), 'headers') self.assertEqual(auth.headers_to_sign, ['x-mything1', 'x-mything2']) def test_edgerc_from_object(self): auth = EdgeGridAuth.from_edgerc(EdgeRc(os.path.join(mydir, 'sample_edgerc'))) self.assertEqual(auth.client_token, 'xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx') self.assertEqual(auth.client_secret, 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=') self.assertEqual(auth.access_token, 'xxxx-xxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx') self.assertEqual(auth.max_body, 131072) self.assertEqual(auth.headers_to_sign, []) def test_edgerc_dashes(self): auth = EdgeGridAuth.from_edgerc(os.path.join(mydir, 'sample_edgerc'), 'dashes') self.assertEqual(auth.max_body, 128*1024) class JsonTest(unittest.TestCase): def __init__(self, testdata=None, testcase=None): super(JsonTest, self).__init__() self.testdata = testdata self.testcase = testcase self.maxDiff = None def runTest(self): auth = EdgeGridAuth( client_token=self.testdata['client_token'], client_secret=self.testdata['client_secret'], access_token=self.testdata['access_token'], ) params = { 'extended': 'true', } data = { 'key':'value', } request = requests.Request( method='POST', url=urljoin(self.testdata['base_url'],'/testapi/v1/t3'), params=params, json=data, ) auth_header = auth.make_auth_header( request.prepare(), self.testdata['timestamp'], self.testdata['nonce'] ) self.assertEqual(auth_header, self.testdata['jsontest_hash']) def suite(): suite = unittest.TestSuite() with open("%s/testdata.json" % mydir) as testdata: testdata = json.load(testdata) tests = testdata['tests'] del testdata['tests'] for test in tests: suite.addTest(EdgeGridTest(testdata, test)) suite.addTest(JsonTest(testdata)) suite.addTest(EGSimpleTest('test_nonce')) suite.addTest(EGSimpleTest('test_timestamp')) suite.addTest(EGSimpleTest('test_defaults')) suite.addTest(EGSimpleTest('test_edgerc_default')) suite.addTest(EGSimpleTest('test_edgerc_broken')) suite.addTest(EGSimpleTest('test_edgerc_unparseable')) suite.addTest(EGSimpleTest('test_edgerc_headers')) suite.addTest(EGSimpleTest('test_edgerc_from_object')) return suite def load_tests(loader=None, tests=None, pattern=None): return suite() if __name__ == '__main__': runner = unittest.TextTestRunner().run(suite()) edgegrid-python-1.1.1/akamai/edgegrid/test/__init__.py0000644005015000011300000000000012474375022023423 0ustar jlandisstaff00000000000000edgegrid-python-1.1.1/akamai/edgegrid/edgegrid.py0000755005015000011300000001722613155560410022476 0ustar jlandisstaff00000000000000#!/usr/bin/env python # # EdgeGrid requests Auth handler # # Original author: Jonathan Landis # # For more information visit https://developer.akamai.com # Copyright 2014 Akamai Technologies, Inc. All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import requests import logging import uuid import hashlib import hmac import base64 import re import sys from requests.auth import AuthBase from time import gmtime, strftime if sys.version_info[0] >= 3: # python3 from urllib.parse import urlparse, parse_qsl, urlunparse else: # python2.7 from urlparse import urlparse, parse_qsl, urlunparse import urllib3.contrib.pyopenssl urllib3.contrib.pyopenssl.inject_into_urllib3() logger = logging.getLogger(__name__) __all__=['EdgeGridAuth'] def eg_timestamp(): return strftime('%Y%m%dT%H:%M:%S+0000', gmtime()) def new_nonce(): return uuid.uuid4() def base64_hmac_sha256(data, key): return base64.b64encode( hmac.new(key.encode('utf8'), data.encode('utf8'), hashlib.sha256).digest() ).decode('utf8') def base64_sha256(data): if isinstance(data, str): data = data.encode('utf8') return base64.b64encode(hashlib.sha256(data).digest()).decode('utf8') class EdgeGridAuth(AuthBase): """A Requests authentication handler that provides Akamai {OPEN} EdgeGrid support. Basic Usage:: >>> import requests >>> from akamai.edgegrid import EdgeGridAuth >>> s = requests.Session() >>> s.auth = EdgeGridAuth( client_token='cccccccccccccccccc', client_secret='sssssssssssssssss', access_token='aaaaaaaaaaaaaaaaa' ) """ def __init__(self, client_token, client_secret, access_token, headers_to_sign=None, max_body=131072): """Initialize authentication using the given parameters from the Luna Manage APIs Interface: :param client_token: Client token provided by "Credentials" ui :param client_secret: Client secret provided by "Credentials" ui :param access_token: Access token provided by "Authorizations" ui :param headers_to_sign: An ordered list header names that will be included in the signature. This will be provided by specific APIs. (default []) :param max_body: Maximum content body size for POST requests. This will be provided by specific APIs. (default 131072) """ self.client_token = client_token self.client_secret = client_secret self.access_token = access_token if headers_to_sign: self.headers_to_sign = [ h.lower() for h in headers_to_sign ] else: self.headers_to_sign = [] self.max_body = max_body self.redirect_location = None @staticmethod def from_edgerc(rcinput, section='default'): """Returns an EdgeGridAuth object from the configuration from the given section of the given edgerc file. :param filename: path to the edgerc file :param section: the section to use (this is the [bracketed] part of the edgerc, default is 'default') """ from .edgerc import EdgeRc if isinstance(rcinput, EdgeRc): rc = rcinput else: rc = EdgeRc(rcinput) return EdgeGridAuth( client_token=rc.get(section, 'client_token'), client_secret=rc.get(section, 'client_secret'), access_token=rc.get(section, 'access_token'), headers_to_sign=rc.getlist(section, 'headers_to_sign'), max_body=rc.getint(section, 'max_body') ) def make_signing_key(self, timestamp): signing_key = base64_hmac_sha256(timestamp, self.client_secret) logger.debug('signing key: %s', signing_key) return signing_key def canonicalize_headers(self, r): spaces_re = re.compile('\\s+') # note: r.headers is a case-insensitive dict and self.headers_to_sign # should already be lowercased at this point return '\t'.join([ "%s:%s" % (h, spaces_re.sub(' ', r.headers[h].strip())) for h in self.headers_to_sign if h in r.headers ]) def make_content_hash(self, r): content_hash = "" prepared_body = (r.body or '') logger.debug("body is '%s'", prepared_body) if r.method == 'POST' and len(prepared_body) > 0: logger.debug("signing content: %s", prepared_body) if len(prepared_body) > self.max_body: logger.debug( "data length %d is larger than maximum %d", len(prepared_body), self.max_body ) prepared_body = prepared_body[0:self.max_body] logger.debug("data truncated to %d for computing the hash", len(prepared_body)) content_hash = base64_sha256(prepared_body) logger.debug("content hash is '%s'", content_hash) return content_hash def make_data_to_sign(self, r, auth_header): parsed_url = urlparse(r.url) if (r.headers.get('Host', False)): netloc = r.headers['Host'] else: netloc = parsed_url.netloc data_to_sign = '\t'.join([ r.method, parsed_url.scheme, netloc, # Note: relative URL constraints are handled by requests when it sets up 'r' parsed_url.path + ('?' + parsed_url.query if parsed_url.query else ""), self.canonicalize_headers(r), self.make_content_hash(r), auth_header ]) logger.debug('data to sign: %s', '\\t'.join(data_to_sign.split('\t'))) return data_to_sign def sign_request(self, r, timestamp, auth_header): return base64_hmac_sha256( self.make_data_to_sign(r, auth_header), self.make_signing_key(timestamp) ) def make_auth_header(self, r, timestamp, nonce): kvps = [ ('client_token', self.client_token), ('access_token', self.access_token), ('timestamp', timestamp), ('nonce', nonce), ] auth_header = "EG1-HMAC-SHA256 " + ';'.join([ "%s=%s" % kvp for kvp in kvps ]) + ';' logger.debug('unsigned authorization header: %s', auth_header) signed_auth_header = auth_header + \ 'signature=' + self.sign_request(r, timestamp, auth_header) logger.debug('signed authorization header: %s', signed_auth_header) return signed_auth_header def handle_redirect(self, res, **kwargs): if res.is_redirect: redirect_location = res.headers['location'] logger.debug("signing the redirected url: %s", redirect_location) request_to_sign = res.request.copy() request_to_sign.url = redirect_location res.request.headers['Authorization'] = self.make_auth_header( request_to_sign, eg_timestamp(), new_nonce() ) def __call__(self, r): timestamp = eg_timestamp() nonce = new_nonce() r.headers['Authorization'] = self.make_auth_header(r, timestamp, nonce) r.register_hook('response', self.handle_redirect) return r edgegrid-python-1.1.1/akamai/edgegrid/edgerc.py0000644005015000011300000000321613323171365022150 0ustar jlandisstaff00000000000000#!/usr/bin/env python # # support for .edgerc file format # # Copyright 2014 Akamai Technologies, Inc. All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import logging import sys if sys.version_info[0] >= 3: # python3 from configparser import ConfigParser else: # python2.7 from ConfigParser import ConfigParser logger = logging.getLogger(__name__) class EdgeRc(ConfigParser): def __init__(self, filename): ConfigParser.__init__(self, {'client_token': '', 'client_secret':'', 'host':'', 'access_token':'','max_body': '131072', 'headers_to_sign': 'None'}) logger.debug("loading edgerc from %s", filename) self.read(filename) logger.debug("successfully loaded edgerc") def optionxform(self, optionstr): """support both max_body and max-body style keys""" return optionstr.replace('-', '_') def getlist(self, section, option): """ returns the named option as a list, splitting the original value by ',' """ value = self.get(section, option) if value: return value.split(',') else: return None edgegrid-python-1.1.1/akamai/edgegrid/__init__.py0000644005015000011300000000352313155561650022462 0ustar jlandisstaff00000000000000""" akamai.edgegrid ~~~~~~~~~~~~~~~ This library provides an authentication handler for Requests that implements the Akamai {OPEN} EdgeGrid client authentication protocol as specified by https://developer.akamai.com/introduction/Client_Auth.html. For more information visit https://developer.akamai.com. usage: >>> import requests >>> from akamai.edgegrid import EdgeGridAuth >>> from urlparse import urljoin >>> baseurl = 'https://akaa-WWWWWWWWWWWW.luna.akamaiapis.net/' >>> s = requests.Session() >>> s.auth = EdgeGridAuth( client_token='akab-XXXXXXXXXXXXXXXXXXXXXXX', client_secret='YYYYYYYYYYYYYYYYYYYYYYYYYY', access_token='akab-ZZZZZZZZZZZZZZZZZZZZZZZZZZZ' ) ... now you have a requests session object that can be used to make {OPEN} requests >>> result = s.get(urljoin(baseurl, '/diagnostic-tools/v1/locations')) >>> result.status_code 200 >>> result.json()['locations'][0] Hongkong, Hong Kong """ from .edgegrid import EdgeGridAuth from .edgerc import EdgeRc __all__=['EdgeGridAuth', 'EdgeRc'] __title__ = 'edgegrid-python' __version__ = '1.1' __author__ = 'Jonathan Landis ' __license__ = 'Apache 2.0' __copyright__ = 'Copyright 2014 Akamai Technologies' # Copyright 2014 Akamai Technologies, Inc. All Rights Reserved # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. edgegrid-python-1.1.1/akamai/__init__.py0000644005015000011300000000007012474375022020701 0ustar jlandisstaff00000000000000__import__('pkg_resources').declare_namespace(__name__) edgegrid-python-1.1.1/MANIFEST.in0000644005015000011300000000011712474375022017105 0ustar jlandisstaff00000000000000include README.rst LICENSE requirements.txt akamai/edgegrid/test/testdata.json edgegrid-python-1.1.1/setup.cfg0000644005015000011300000000007313323171757017174 0ustar jlandisstaff00000000000000[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0