From 429c9a1b157e43a927f92d98c0d68627638cfff3 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 22 Jul 2022 17:49:51 +0200 Subject: [PATCH] add command cli: get_token --- ereuse_devicehub/commands/reports.py | 3 ++- ereuse_devicehub/commands/users.py | 20 ++++++++++++++++++++ ereuse_devicehub/devicehub.py | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ereuse_devicehub/commands/users.py diff --git a/ereuse_devicehub/commands/reports.py b/ereuse_devicehub/commands/reports.py index cdc05211..8d020e7d 100644 --- a/ereuse_devicehub/commands/reports.py +++ b/ereuse_devicehub/commands/reports.py @@ -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: diff --git a/ereuse_devicehub/commands/users.py b/ereuse_devicehub/commands/users.py new file mode 100644 index 00000000..0537944f --- /dev/null +++ b/ereuse_devicehub/commands/users.py @@ -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)) diff --git a/ereuse_devicehub/devicehub.py b/ereuse_devicehub/devicehub.py index 182c064e..5fec2cbe 100644 --- a/ereuse_devicehub/devicehub.py +++ b/ereuse_devicehub/devicehub.py @@ -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.',