Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Commit

Permalink
Fix token operations for elasticsearch (#449)
Browse files Browse the repository at this point in the history
* fix update token for elasticsearch

* fix delete token for elasticsearch
  • Loading branch information
ckrez authored and wesyoung committed Mar 27, 2019
1 parent f5c2b88 commit dfc9cba
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cif/store/zelasticsearch/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def delete(self, data):
if not (data.get('token') or data.get('username')):
return 'username or token required'

rv = self.search(data, raw=True)
rv = list(self.search(data, raw=True))

if not rv:
return 0
Expand All @@ -94,18 +94,28 @@ def delete(self, data):
t.delete()

connections.get_connection().indices.flush(index='tokens')
return len(list(rv))
return len(rv)

def edit(self, data):
if not data.get('token'):
return 'token required for updating'

d = list(self.search({'token': data['token']}))
d = list(self.search({'token': data['token']}, raw=True))
if not d:
return 'token not found'

d.update(fields=data)
d = Token.get(d[0]['_id'])

try:
d.update(groups=data['groups'])

except Exception as e:
import traceback
logger.error(traceback.print_exc())
return False

connections.get_connection().indices.flush(index='tokens')
return True

def update_last_activity_at(self, token, timestamp):
if isinstance(timestamp, str):
Expand Down

0 comments on commit dfc9cba

Please sign in to comment.