Skip to content

Instantly share code, notes, and snippets.

@hynek

hynek/v2.py Secret

Created October 27, 2015 19:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hynek/cfe2cc32f337e2676466 to your computer and use it in GitHub Desktop.
Save hynek/cfe2cc32f337e2676466 to your computer and use it in GitHub Desktop.
async def verify(self, token):
"""
Return token data for *token*.
"""
cc = await self.pool.cursor()
try:
c = cc.__enter__()
await c.execute(
"SELECT user_id, created, purpose FROM tokens "
"WHERE token=%s AND system=%s AND valid=true",
(token, self.system,)
)
rv = await c.fetchone()
except Exception as e:
await self.pool.clear()
raise StorageError(e)
finally:
cc.__exit__()
if rv is None:
raise InvalidToken
return TokenData(
token=token,
system=self.system,
user_id=rv[0],
created=rv[1],
purpose=rv[2],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment