parse password from env if available

This commit is contained in:
Jakob Ketterl 2021-02-18 01:32:27 +01:00
parent 2eec29db05
commit 0714ce5703
1 changed files with 11 additions and 6 deletions

View File

@ -4,6 +4,7 @@ from owrx.users import UserList, User, DefaultPasswordClass
import sys import sys
import random import random
import string import string
import os
class Command(ABC): class Command(ABC):
@ -15,12 +16,16 @@ class Command(ABC):
class UserCommand(Command, metaclass=ABCMeta): class UserCommand(Command, metaclass=ABCMeta):
def getPassword(self, args, username): def getPassword(self, args, username):
if args.noninteractive: if args.noninteractive:
print("Generating password for user {username}...".format(username=username)) if "OWRX_PASSWORD" in os.environ:
password = self.getRandomPassword() password = os.environ["OWRX_PASSWORD"]
generated = True generated = False
print('Password for {username} is "{password}".'.format(username=username, password=password)) else:
print('This password is suitable for initial setup only, you will be asked to reset it on initial use.') print("Generating password for user {username}...".format(username=username))
print('This password cannot be recovered from the system, please copy it now.') password = self.getRandomPassword()
generated = True
print('Password for {username} is "{password}".'.format(username=username, password=password))
print('This password is suitable for initial setup only, you will be asked to reset it on initial use.')
print('This password cannot be recovered from the system, please copy it now.')
else: else:
password = getpass("Please enter the new password for {username}: ".format(username=username)) password = getpass("Please enter the new password for {username}: ".format(username=username))
confirm = getpass("Please confirm the new password: ") confirm = getpass("Please confirm the new password: ")