MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / user_info_server

Function user_info_server

web/pgadmin/setup/user_info.py:34–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32
33
34def user_info_server():
35 print("NOTE: Configuring authentication for SERVER mode.\n")
36
37 if all(value in os.environ for value in
38 ['PGADMIN_SETUP_EMAIL', 'PGADMIN_SETUP_PASSWORD']):
39 email = ''
40 p1 = ''
41 if os.environ['PGADMIN_SETUP_EMAIL'] \
42 and os.environ['PGADMIN_SETUP_PASSWORD']:
43 email = os.environ['PGADMIN_SETUP_EMAIL']
44 p1 = os.environ['PGADMIN_SETUP_PASSWORD']
45 else:
46 # Prompt the user for their default username and password.
47 print(
48 "Enter the email address and password to use for the initial "
49 "pgAdmin user account:\n"
50 )
51
52 # Bound the retry loop so a non-interactive caller (mocked
53 # input(), closed stdin, or a typo'd PGADMIN_SETUP_EMAIL='' that
54 # never gets corrected) cannot spin forever printing
55 # "Invalid email address.".
56 MAX_PROMPT_ATTEMPTS = 5
57 email = input(ENTER_EMAIL_ADDRESS)
58 attempts = 1
59 while not validate_email(email):
60 if attempts >= MAX_PROMPT_ATTEMPTS:
61 raise RuntimeError(
62 "Failed to obtain a valid email after {} attempts. "
63 "Set PGADMIN_SETUP_EMAIL/PASSWORD env vars when "
64 "running non-interactively.".format(
65 MAX_PROMPT_ATTEMPTS))
66 print('Invalid email address. Please try again.')
67 email = input(ENTER_EMAIL_ADDRESS)
68 attempts += 1
69
70 p1, p2 = pprompt()
71 attempts = 1
72 while p1 != p2 or len(p1) < config.PASSWORD_LENGTH_MIN:
73 if attempts >= MAX_PROMPT_ATTEMPTS:
74 raise RuntimeError(
75 "Failed to obtain a valid password after {} attempts. "
76 "Set PGADMIN_SETUP_EMAIL/PASSWORD env vars when "
77 "running non-interactively.".format(
78 MAX_PROMPT_ATTEMPTS))
79 if p1 != p2:
80 print('Passwords do not match. Please try again.')
81 else:
82 print(
83 'Password must be at least {} characters. '
84 'Please try again.'.format(config.PASSWORD_LENGTH_MIN)
85 )
86 p1, p2 = pprompt()
87 attempts += 1
88
89 return email, p1
90
91

Callers 1

user_infoFunction · 0.85

Calls 2

validate_emailFunction · 0.90
ppromptFunction · 0.85

Tested by

no test coverage detected