mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-15 14:03:02 +00:00
allow pre-loading API tokens from config
This is the first small part of easing the pain of services, which is generating the API tokens, and used to require initializing the JupyterHub database.
This commit is contained in:
@@ -303,11 +303,19 @@ class User(Base):
|
||||
name=self.name,
|
||||
)
|
||||
|
||||
def new_api_token(self):
|
||||
"""Create a new API token"""
|
||||
def new_api_token(self, token=None):
|
||||
"""Create a new API token
|
||||
|
||||
If `token` is given, load that token.
|
||||
"""
|
||||
assert self.id is not None
|
||||
db = inspect(self).session
|
||||
token = new_token()
|
||||
if token is None:
|
||||
token = new_token()
|
||||
else:
|
||||
found = APIToken.find(db, token)
|
||||
if found:
|
||||
raise ValueError("Collision on token: %s..." % token[:4])
|
||||
orm_token = APIToken(user_id=self.id)
|
||||
orm_token.token = token
|
||||
db.add(orm_token)
|
||||
|
Reference in New Issue
Block a user