Chef auth support for Python-Requests
import requests
import requests_chef
auth = requests_chef.ChefAuth('chef-user', '~/chef-user.pem')
response = requests.get('https://api.chef.io/users/chef-user',
headers={'X-Chef-Version': '12.0.2'},
auth=auth)
response.json()
...
{'display_name': 'chef-user',
'email': 'chef-user@example.com',
'first_name': 'Chef',
'last_name': 'User',
'middle_name': '',
'public_key': '-----BEGIN PUBLIC KEY-----\nMIIBIj...IDAQAB\n-----END PUBLIC KEY-----\n',
'username': 'chef-user'}
See samstav/okchef first, since thats generally more useful. okchef
uses requests-chef
to sign and authenticate requests.
This project currently requires a fork of pyca/cryptography due to the following related issues:
- #1648: decouple hashing process from signature generation / verification
- #1579: Support asymmetric signing with pre-computed digest
First, install this fork of cryptography directly from github.
$ pip install git+https://github.com/samstav/cryptography.git@rsa-bypass-hash-on-signer
If you don't do this first, you'd have to use the (deprecated, scheduled for removal) --process-dependency-links
option through pip, since pip no longer respects dependency links by default (as of pip 1.5).
$ pip install --process-dependency-links requests-chef