Coverage for python/lsst/ctrl/bps/panda/panda_auth_drivers.py: 39%
21 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-24 02:07 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-24 02:07 -0700
1# This file is part of ctrl_bps_panda.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Driver functions for each panda_auth subcommand.
24Driver functions ensure that ensure all setup work is done before running
25the subcommand method.
26"""
29__all__ = [
30 "panda_auth_clean_driver",
31 "panda_auth_reset_driver",
32 "panda_auth_status_driver",
33]
36import logging
37from datetime import datetime
39from .panda_auth_utils import panda_auth_clean, panda_auth_status, panda_auth_update
41_LOG = logging.getLogger(__name__)
44def panda_auth_clean_driver():
45 """Clean up token and token cache files."""
46 panda_auth_clean()
49def panda_auth_reset_driver():
50 """Get new auth token."""
51 panda_auth_update(None, True)
54def panda_auth_status_driver():
55 """Gather information about a token if it exists."""
56 status = panda_auth_status()
57 if status:
58 print(f"{'Filename:':15} {status['filename']}")
59 print(f"{'Valid starting:':15} {datetime.fromtimestamp(status['iat'])}")
60 print(f"{'Expires:':15} {datetime.fromtimestamp(status['exp'])}")
61 print(f"{'Name:':15} {status['name']}")
62 print(f"{'Email:':15} {status['email']}")
63 print(f"{'Groups:':15} {','.join(status['groups'])}")
64 print(f"{'Organization:':15} {status['organisation_name']}")
65 else:
66 print("No token found")