Skip to content

Commit d906180

Browse files
authored
Merge pull request Clever#43 from Clever/remove-api-key
Remove references to API key
2 parents 990b12c + 150cb77 commit d906180

File tree

8 files changed

+47
-44
lines changed

8 files changed

+47
-44
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.0 (2017-01-19)
2+
* Added bindings for Contact resource. [#41](https://github.com/Clever/clever-python/pull/41)
3+
* Updated CLI [#43](https://github.com/Clever/clever-python/pull/43)
4+
15
## 2.2.0 (2016-02-03)
26
* Added bindings for DistrictAdmin and SchoolAdmin resources. [#37](https://github.com/Clever/clever-python/pull/37)
37

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ Get started by importing the `clever` module and setting your authentication met
3131
```python
3232
import clever
3333
clever.set_token('YOUR_OAUTH_TOKEN')
34-
# or if you're using API key auth
35-
# clever.set_api_key('YOUR_API_KEY')
3634
```
3735

3836
The `clever` module exposes classes corresponding to resources:
@@ -84,11 +82,11 @@ The `retrieve` class method takes in a Clever ID and returns a specific resource
8482
The library comes with a basic command-line interface:
8583

8684
```bash
87-
$ export CLEVER_API_KEY=DEMO_KEY
85+
$ export CLEVER_API_TOKEN=DEMO_TOKEN
8886
$ clever districts all
8987
Running the equivalent of:
9088
--
91-
curl https://api.clever.com/v1.1/districts -H "Authorization: Basic REVNT19LRVk="
89+
curl https://api.clever.com/v1.1/districts -H "Authorization: Bearer DEMO_TOKEN"
9290
--
9391
Starting new HTTPS connection (1): api.clever.com
9492
API request to https://api.clever.com/v1.1/districts returned (response code, response body) of (200, '{"data":[{"data":{"name":"Demo District","id":"4fd43cc56d11340000000005"},"uri":"/v1.1/districts/4fd43cc56d11340000000005"}],"links":[{"rel":"self","uri":"/v1.1/districts"}]}')
@@ -113,3 +111,7 @@ Questions, feature requests, or feedback of any kind is always welcome! We're av
113111
### Testing
114112

115113
python -m unittest discover test
114+
115+
## Publishing
116+
117+
Update VERSION and CHANGELOG.md and run `publish.sh` to publish a new version of the library.

bin/clever

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import os
55
import re
66
import subprocess
77
import sys
8-
import base64
98

109
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
1110
import clever
@@ -46,9 +45,9 @@ class APIResourceClient(object):
4645
term = ' \\'
4746
else:
4847
term = ''
49-
api_key = clever.get_api_key()
50-
curl = ['curl %s%s -H "Authorization: Basic %s"%s' %
51-
(clever.api_base, url, base64.b64encode(api_key), term)]
48+
api_token = clever.get_token()
49+
curl = ['curl %s%s -H "Authorization: Bearer %s"%s' %
50+
(clever.api_base, url, api_token, term)]
5251
if isinstance(ordered_params, list):
5352
for i, (k, v) in enumerate(ordered_params):
5453
if i == len(ordered_params) - 1:
@@ -124,6 +123,9 @@ class TeacherClient(ListableAPIResourceClient):
124123
class EventClient(ListableAPIResourceClient):
125124
client_for = clever.Event
126125

126+
class ContactClient(ListableAPIResourceClient):
127+
client_for = clever.Contact
128+
127129
def main():
128130
klasses = {
129131
'district' : DistrictClient,
@@ -134,6 +136,7 @@ def main():
134136
'student' : StudentClient,
135137
'teacher' : TeacherClient,
136138
'event' : EventClient,
139+
'contact': ContactClient,
137140
}
138141
klasses_plural = { '{0}s'.format(key) : value for key, value in klasses.iteritems() }
139142
klasses = dict(klasses.items() + klasses_plural.items())
@@ -170,11 +173,15 @@ teacher
170173
retrieve
171174
172175
event
176+
all
177+
retrieve
178+
179+
contact
173180
all
174181
retrieve""")
175182
parser.add_option('-v', '--verbosity', help='Verbosity of debugging output.',
176183
dest='verbosity', action='count', default=0)
177-
parser.add_option('-k', '--api-key', help="API key. Defaults to value of environment variable CLEVER_API_KEY", dest='api_key')
184+
parser.add_option('-t', '--api-token', help="API token. Defaults to value of environment variable CLEVER_API_TOKEN", dest='api_token')
178185
parser.add_option('-b', '--api-base', help='API base URL', dest='api_base')
179186
parser.add_option('-i', '--id', help="Object ID", dest='id')
180187
opts, args = parser.parse_args()
@@ -188,11 +195,11 @@ event
188195

189196
klass_name = args[0]
190197
method_name = args[1]
191-
api_key = opts.api_key or os.environ.get('CLEVER_API_KEY')
192-
if not api_key:
193-
parser.error('No API key provided (use -k option or set the CLEVER_API_KEY environment variable')
198+
api_token = opts.api_token or os.environ.get('CLEVER_API_TOKEN')
199+
if not api_token:
200+
parser.error('No API token provided (use -t option or set the CLEVER_API_TOKEN environment variable')
194201
return 1
195-
clever.set_api_key(api_key)
202+
clever.set_token(api_token)
196203

197204
if opts.api_base:
198205
clever.api_base = opts.api_base

clever/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.0
1+
2.3.0

clever/__init__.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,6 @@ def get_token():
100100
global global_auth
101101
return global_auth.get('token', None)
102102

103-
104-
def set_api_key(api_key):
105-
global global_auth
106-
global_auth = {'api_key': api_key}
107-
108-
109-
def get_api_key():
110-
global global_auth
111-
return global_auth.get('api_key', None)
112-
113103
# Exceptions
114104

115105

@@ -244,9 +234,9 @@ def request_raw(self, meth, url, params={}):
244234
my_auth = self._auth or global_auth
245235
if my_auth is None:
246236
raise AuthenticationError(
247-
'No authentication method provided. (HINT: "clever.api_key = <API-KEY>" is deprecated. Set your API key using "clever.set_api_key(<API-KEY>)" or "clever.set_token(<OAUTH-TOKEN>)". You can generate API keys from the Clever web interface. See https://clever.com/developers/docs for details, or email support@clever.com if you have any questions.')
248-
if my_auth.get('token') is None and my_auth.get('api_key') is None:
249-
raise AuthenticationError('Must provide either api_key or token auth. {}'.format(my_auth))
237+
'No authentication method provided. (HINT: "clever.api_key = <API-KEY>" is deprecated. Set your API token using "clever.set_token(<OAUTH-TOKEN>)". You can generate API tokens from the Clever web interface. See https://clever.com/developers/docs for details, or email support@clever.com if you have any questions.')
238+
if my_auth.get('token') is None:
239+
raise AuthenticationError('Must provide api token auth. {}'.format(my_auth))
250240

251241
abs_url = self.api_url(url)
252242
params = params.copy()

test/test_cert_pinning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class CleverTestCase(unittest.TestCase):
1111
def setUp(self):
1212
super(CleverTestCase, self).setUp()
13-
clever.set_api_key('DEMO_KEY')
13+
clever.set_token('DEMO_TOKEN')
1414

1515
class CertPinning(CleverTestCase):
1616
def test_prod_api(self):

test/test_clever.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CleverTestCase(unittest.TestCase):
3030
def setUp(self):
3131
super(CleverTestCase, self).setUp()
3232
clever.api_base = os.environ.get('CLEVER_API_BASE', 'https://api.clever.com')
33-
clever.set_api_key('DEMO_KEY')
33+
clever.set_token('DEMO_TOKEN')
3434

3535

3636
class FunctionalTests(CleverTestCase):
@@ -104,16 +104,16 @@ def test_empty_list_on_no_data(self):
104104
class AuthenticationErrorTest(CleverTestCase):
105105

106106
def test_invalid_credentials(self):
107-
key = clever.get_api_key()
107+
token = clever.get_token()
108108
try:
109-
clever.set_api_key('invalid')
109+
clever.set_token('invalid')
110110
clever.District.all()
111111
except clever.AuthenticationError, e:
112112
self.assertEqual(401, e.http_status)
113113
self.assertTrue(isinstance(e.http_body, str))
114114
self.assertTrue(isinstance(e.json_body, dict))
115115
finally:
116-
clever.set_api_key(key)
116+
clever.set_token(token)
117117

118118

119119
class InvalidRequestErrorTest(CleverTestCase):

test/test_cli_clever.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def run_clever(self, args='', env=None):
1515
process = subprocess.Popen(CLI_CLEVER + args, shell=True, env=env,
1616
stdout=subprocess.PIPE,
1717
stderr=subprocess.PIPE)
18-
18+
1919
out, err = process.communicate()
2020
code = process.returncode
2121
return out, err, code
@@ -28,14 +28,14 @@ def test_help(self):
2828
out, err, code = self.run_clever('-h')
2929
self.assertEqual(code, 0)
3030

31-
# def test_api_key(self):
32-
# # Check for error when key is not provided
33-
# out, err, code = self.run_clever('district all')
34-
# self.assertEqual(code, 2)
35-
# # Check for no error when key is provided via -k
36-
# out, err, code = self.run_clever('district all -k DEMO_KEY')
37-
# self.assertEqual(code, 0)
38-
# # Check for no error when key is provided via CLEVER_API_KEY
39-
# env = {'CLEVER_API_KEY':'DEMO_KEY'}
40-
# out, err, code = self.run_clever('district all', env)
41-
# self.assertEqual(code, 0)
31+
def test_api_token(self):
32+
# Check for error when key is not provided
33+
out, err, code = self.run_clever('district all')
34+
self.assertEqual(code, 2)
35+
# Check for no error when key is provided via -t
36+
out, err, code = self.run_clever('district all -t DEMO_TOKEN')
37+
self.assertEqual(code, 0)
38+
# Check for no error when key is provided via CLEVER_API_TOKEN
39+
env = {'CLEVER_API_TOKEN':'DEMO_TOKEN'}
40+
out, err, code = self.run_clever('district all', env)
41+
self.assertEqual(code, 0)

0 commit comments

Comments
 (0)