Skip to content

Commit

Permalink
Migrate to CKAN 2.9.4 & python 3.7 #2 : no more model.new_revision(),…
Browse files Browse the repository at this point in the history
… bytes to str encoding
  • Loading branch information
mdutoo committed Dec 9, 2021
1 parent 640b879 commit 339ed8a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ckanext/ozwillo_organization_api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def wrapper(context, data):
if signature_header_name in request.headers:
if request.headers[signature_header_name].startswith('sha1='):
algo, received_hmac = request.headers[signature_header_name].rsplit('=')
computed_hmac = hmac.new(api_secret, request.get_data(), sha1).hexdigest()
# since python 3, bytes are not directly str so key must be encoded : https://stackoverflow.com/a/43882903/2862821
# else ERROR [ckan.views.api] key: expected bytes or bytearray, but got 'str'
computed_hmac = hmac.new(bytes(api_secret, 'utf-8'), request.get_data(), sha1).hexdigest()
if received_hmac.lower() != computed_hmac:
log.info('Invalid HMAC')
raise toolkit.NotAuthorized(_('Invalid HMAC'))
Expand Down Expand Up @@ -112,7 +114,7 @@ def create_organization(context, data_dict):
group.state = 'active'
group.image_url = default_icon_url
group.save()
model.repo.new_revision()
# no model.repo.new_revision() in 2.9 like in 2.8.2, see ckan/action/create.py diff & https://pythonrepo.com/repo/ckan-ckan-python-science
model.GroupExtra(group_id=group.id, key='client_id',
value=client_id).save()
model.GroupExtra(group_id=group.id, key='client_secret',
Expand Down

0 comments on commit 339ed8a

Please sign in to comment.