coderanger/pychef — pull request #32 by samstav (2014-07-16 01:33:00+00:00)
Title: verify rsa.Key object to prevent segfault

### Issue reported in https://github.com/coderanger/pychef/issues/28

```python
In [1]: from chef import api

In [2]: client = api.ChefAPI('https://api.opscode.com/organizations/myorg', None, 'user')

In [3]: client.api_request('GET', '/roles')
Segmentation fault (core dumped)
```

One option (implemented in this PR) would be to raise an exception when trying to instantiate `ChefAPI`:
```python

In [1]: from chef import api

In [2]: client = api.ChefAPI('https://api.opscode.com/organizations/myorg', None, 'user')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
----> 1 client = api.ChefAPI('https://api.opscode.com/organizations/myorg', None, 'user')

~/pychef/chef/api.py in __init__(self, url, key, client, version, headers)
77 key = Key(key)
78 if not key.key:
---> 79 raise TypeError("ChefAPI attribute 'key' was invalid.")
80 self.key = key
81 self.client = client

TypeError: ChefAPI attribute 'key' was invalid.

In [3]:
```