Skip to content

Commit 3f64fc9

Browse files
committed
add interactive username prompt
- in credential_loader/static Signed-off-by: Sepehr-A <[email protected]>
1 parent 07d7355 commit 3f64fc9

File tree

1 file changed

+10
-2
lines changed
  • suzieq/poller/controller/credential_loader

1 file changed

+10
-2
lines changed

suzieq/poller/controller/credential_loader/static.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
from suzieq.poller.controller.credential_loader.base_credential_loader import \
77
CredentialLoader, CredentialLoaderModel, check_credentials
8-
from suzieq.shared.utils import get_sensitive_data
98
from suzieq.shared.exceptions import SensitiveLoadError, InventorySourceError
9+
from suzieq.shared.utils import get_sensitive_data
1010

1111

1212
class StaticModel(CredentialLoaderModel):
@@ -18,7 +18,7 @@ class StaticModel(CredentialLoaderModel):
1818
keyfile: Optional[str]
1919
enable_password: Optional[str] = Field(alias='enable-password')
2020

21-
@validator('password', 'key_passphrase', 'enable_password')
21+
@validator('username', 'password', 'key_passphrase', 'enable_password')
2222
def validate_sens_field(cls, field):
2323
"""Validate if the sensitive var was passed correctly
2424
"""
@@ -57,6 +57,14 @@ def init(self, init_data: dict):
5757
init_data['key_passphrase'] = init_data.pop('key-passphrase', None)
5858
super().init(init_data)
5959

60+
if self._data.username == 'ask':
61+
try:
62+
self._data.username = get_sensitive_data(
63+
self._data.username,
64+
f'{self.name} Username to login to device: ')
65+
except SensitiveLoadError as e:
66+
raise InventorySourceError(f'{self.name} {e}')
67+
6068
if self._data.password == 'ask':
6169
try:
6270
self._data.password = get_sensitive_data(

0 commit comments

Comments
 (0)