Skip to content

Commit 2a1aef4

Browse files
committed
make pykinit read password from command line if no password file is found
1 parent 448d15e commit 2a1aef4

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

dsutil/hadoop/kerberos.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@
2727
PID = os.getpid()
2828

2929

30-
class ExceptionNoPassword(Exception):
31-
"""Exception due to no password specified.
32-
"""
33-
def __init__(self) -> None:
34-
super().__init__()
35-
self.value = "No password is specified."
36-
37-
def __str__(self):
38-
return repr(self.value)
39-
40-
4130
def save_passwd(passwd: str) -> None:
4231
"""Encrypt and save the password into a profile that is readable/writable only by the user.
4332
@@ -55,11 +44,13 @@ def read_passwd() -> str:
5544
5645
:return: Password in the profile file or empty string if the file does not exist.
5746
"""
58-
os.chmod(PROFILE, 0o600)
59-
if not os.path.isfile(PROFILE):
60-
return ""
61-
with open(PROFILE, "r", encoding="utf-8") as fin:
62-
return base64.b64decode(fin.read()).decode()
47+
if os.path.isfile(PROFILE):
48+
os.chmod(PROFILE, 0o600)
49+
with open(PROFILE, "r", encoding="utf-8") as fin:
50+
return base64.b64decode(fin.read()).decode()
51+
passwd = input("Please enter password for kinit: ")
52+
save_passwd(passwd)
53+
return passwd
6354

6455

6556
def _warn_passwd_expiration(process, email: Dict[str, str]):
@@ -183,8 +174,6 @@ def main() -> None:
183174
if args.password:
184175
save_passwd(args.password)
185176
password = read_passwd()
186-
if not password:
187-
raise ExceptionNoPassword()
188177
config = _read_config(args.config)
189178
if args.minute:
190179
while True:

0 commit comments

Comments
 (0)