31 lines
1.1 KiB
Python
Executable File
31 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Print the current TOTP code of a user of a Linux Manager VM: lm-dev-otp-code.py.
|
|
|
|
The code is the one of the key <vm>-<user> in the TOTP engine of the Vault of the project --project
|
|
(LXD_PROJECT, lm-dev by default), for --user (admin by default) of the VM --vm (lm-dev), which
|
|
lm-dev-otp-register.py or lm-dev-vm.py create enrolled.
|
|
"""
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
|
|
from lm_dev import PROJECT, VaultError, otp_code
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
parser.add_argument('--project', default=os.environ.get('LXD_PROJECT', PROJECT),
|
|
help=f'the project of the VM (LXD_PROJECT, default {PROJECT})')
|
|
parser.add_argument('--vm', default='lm-dev', help='the name of the VM (default lm-dev)')
|
|
parser.add_argument('--user', default='admin', help='the user (default admin)')
|
|
args = parser.parse_args()
|
|
try:
|
|
print(otp_code(args.project, args.vm, args.user))
|
|
except VaultError as error:
|
|
sys.exit(f'no code: {error}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|