mirror of
https://github.com/clearml/clearml-server
synced 2025-06-26 23:15:47 +00:00
Rename server to apiserver
This commit is contained in:
44
apiserver/tools.py
Normal file
44
apiserver/tools.py
Normal file
@@ -0,0 +1,44 @@
|
||||
""" Command line tools for the API server """
|
||||
from argparse import ArgumentParser
|
||||
|
||||
import dpath
|
||||
from humanfriendly import parse_timespan
|
||||
|
||||
|
||||
def setup():
|
||||
from database import initialize
|
||||
initialize()
|
||||
|
||||
|
||||
def gen_token(args):
|
||||
from bll.auth import AuthBLL
|
||||
resp = AuthBLL.get_token_for_user(args.user_id, args.company_id, parse_timespan(args.expiration))
|
||||
print('Token:\n%s' % resp.token)
|
||||
|
||||
|
||||
def safe_get(obj, glob, default=None, separator="/"):
|
||||
try:
|
||||
return dpath.get(obj, glob, separator=separator)
|
||||
except KeyError:
|
||||
return default
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
top_parser = ArgumentParser(__doc__)
|
||||
|
||||
subparsers = top_parser.add_subparsers(title='Sections')
|
||||
|
||||
token = subparsers.add_parser('token')
|
||||
token_commands = token.add_subparsers(title='Commands')
|
||||
token_create = token_commands.add_parser('generate', description='Generate a new token')
|
||||
token_create.add_argument('--user-id', '-u', help='User ID', required=True)
|
||||
token_create.add_argument('--company-id', '-c', help='Company ID', required=True)
|
||||
token_create.add_argument('--expiration', '-exp',
|
||||
help="Token expiration (time span, shorthand suffixes are supported, default 1m)",
|
||||
default=parse_timespan('1m'))
|
||||
token_create.set_defaults(_func=gen_token)
|
||||
|
||||
args = top_parser.parse_args()
|
||||
if args._func:
|
||||
setup()
|
||||
args._func(args)
|
||||
Reference in New Issue
Block a user