add command cli: get_token

This commit is contained in:
Cayo Puigdefabregas 2022-07-22 17:49:51 +02:00
parent a74e242e20
commit 429c9a1b15
3 changed files with 24 additions and 1 deletions

View File

@ -1,6 +1,5 @@
import csv
# import click
# import click_spinner
# import ereuse_utils.cli
from io import StringIO
@ -8,6 +7,8 @@ from io import StringIO
from ereuse_devicehub.resources.action import models as evs
from ereuse_devicehub.resources.documents.device_row import InternalStatsRow
# import click
class Report:

View File

@ -0,0 +1,20 @@
import click
from ereuse_devicehub import auth
from ereuse_devicehub.resources.user.models import User
class GetToken:
def __init__(self, app) -> None:
super().__init__()
self.app = app
self.app.cli.command('get_token', short_help='show the user token.')(
self.run
)
@click.argument('email')
def run(self, email):
user = User.query.filter_by(email=email, active=True, phantom=False).one_or_none()
if user:
print(auth.Auth.encode(user.token))

View File

@ -16,6 +16,7 @@ from teal.teal import Teal
from ereuse_devicehub.auth import Auth
from ereuse_devicehub.client import Client, UserClient
from ereuse_devicehub.commands.reports import Report
from ereuse_devicehub.commands.users import GetToken
from ereuse_devicehub.config import DevicehubConfig
from ereuse_devicehub.db import db
from ereuse_devicehub.dummy.dummy import Dummy
@ -70,6 +71,7 @@ class Devicehub(Teal):
"""The Inventory ID of this instance. In Teal is the app.schema."""
self.dummy = Dummy(self)
self.report = Report(self)
self.get_token = GetToken(self)
@self.cli.group(
short_help='Inventory management.',