Skip to content

Commit

Permalink
DXE-1477 Merge pull request #65 from akamai/release/v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Slonimskaia authored Aug 29, 2022
2 parents 2701ad5 + 72f3bfb commit 9977c00
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 154 deletions.
10 changes: 10 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
History
-------

1.3.0 (2022-08-29)
++++++++++++++++++

* Improvements
- decouple from `requests` library
- add support for MultipartEncoder

* Bug fixes
- remove unnecessary shebangs and permissions

1.2.1 (2021-10-11)
++++++++++++++++++

Expand Down
148 changes: 148 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# EdgeGrid for Python

This library implements an authentication handler for HTTP [requests](https://requests.readthedocs.io/en/latest/) using the [EdgeGrid authentication](https://techdocs.akamai.com/developer/docs/authenticate-with-edgegrid) scheme.

## Prerequisites
Before you begin, you need to [Create authentication credentials](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials) in [Control Center](https://control.akamai.com/).

Download the Python release compatible with your operating system at [https://www.python.org/downloads/](https://www.python.org/downloads/).

> Python 2 is no longer supported by the [Python Software Foundation](https://www.python.org/doc/sunset-python-2/).
However, if you're still using it, you can follow the [Python 2 steps](#python-2-steps).

## Install

1. Install Python.
```
python setup.py install
```
1. Install the developer libraries for Python, SSL and FFI.
```
sudo apt-get install ibssl-dev libffi-dev python-dev
```
1. Install the `edgegrid-python` authentication handler.
```
pip install edgegrid-python
```
## Make an API call
To use Akamai APIs, you need the values for the tokens from your [.edgerc file](https://techdocs.akamai.com/developer/docs/set-up-authentication-credentials#add-credential-to-edgerc-file).
```pycon
>>> import requests
>>> from akamai.edgegrid import EdgeGridAuth
>>> from urllib.parse 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
...
```

This is an example of an API call to [List available edge server locations](https://techdocs.akamai.com/diagnostic-tools/reference/ghost-locationsavailable). Change the `baseurl` element to reference an endpoint in any of the [Akamai APIs](https://techdocs.akamai.com/home/page/products-tools-a-z?sort=api).

Alternatively, your program can read the credential values directly from the `.edgerc`.

```pycon
>>> import requests
>>> from akamai.edgegrid import EdgeGridAuth, EdgeRc
>>> from urllib.parse 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
...
```

> NOTE: If your `.edgerc` file contains more than one credential set, use the `section` argument to specify which section contains the credentials for your API request.
## Virtual environment

To test in a [virtual environment](https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments), run:

```
$ python3 -m venv venv
$ . venv/bin/activate
$ pip install -r requirements.txt
$ python -m unittest discover
```

### Python 2 steps

Python 2.7 is no longer supported by the [Python Software Foundation](https://www.python.org/doc/sunset-python-2/), but we recognize that some developers continue to use it. If you're using Python 2.7 with EdgeGrid, follow these steps.

1. To upgrade the cryptography package, first run:
```
pip install --upgrade 'cryptography<3.4'
```
1. To continue with the installation, run:
```
pip install edgegrid-python
```
or install from sources:
```
python setup.py install
```
1. To test, run:
```
$ virtualenv -p python2.7 venv
$ . venv/bin/activate
$ pip install 'cryptography<3.4' # just necessary for Python 2.7
$ pip install -r requirements.txt
$ python -m unittest discover
```
> If you intend to run the examples with Python 2.7, remember that `urljoin` is contained in a different package.
```
from urlparse import urljoin
```
## Contribute
1. Fork the [repository](https://github.com/akamai-open/AkamaiOPEN-edgegrid-python) to modify the **master** branch.
2. Write a test that demonstrates that the bug was fixed or the feature works as expected.
3. Send a pull request and nudge the maintainer until it gets merged and published. :)
## Author
Jonathan Landis
## License
> Copyright 2022 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.
151 changes: 0 additions & 151 deletions README.rst

This file was deleted.

2 changes: 1 addition & 1 deletion akamai/edgegrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
__all__ = ['EdgeGridAuth', 'EdgeRc']

__title__ = 'edgegrid-python'
__version__ = '1.2.1'
__version__ = '1.3.0'
__author__ = 'Jonathan Landis <[email protected]>'
__maintainer__ = 'Akamai Developer Experience team <[email protected]>'
__license__ = 'Apache 2.0'
Expand Down
2 changes: 1 addition & 1 deletion akamai/edgegrid/test/testdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
{"X-Test1": " first-thing second-thing"}
]
},
"failsWithMessage": "Invalid return character or leading space in header: X-Test1",
"failsWithMessage": "Invalid leading whitespace, reserved character(s), or returncharacter(s) in header value: ' first-thing second-thing'",
"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="
},
{
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
setup(
name='edgegrid-python',
version='1.2.1',
version='1.3.0',
description='{OPEN} client authentication protocol for python-requests',
author='Jonathan Landis',
author_email='[email protected]',
Expand Down

0 comments on commit 9977c00

Please sign in to comment.