-
Notifications
You must be signed in to change notification settings - Fork 151
Expand file tree
/
Copy pathreport_user_by_email.py
More file actions
executable file
·46 lines (34 loc) · 1.29 KB
/
report_user_by_email.py
File metadata and controls
executable file
·46 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
""" Script to illustrate how to retrieve a user from the Duo Admin API using the associated email address"""
from __future__ import absolute_import, print_function
import sys
import getpass
import duo_client
from six.moves import input
argv_iter = iter(sys.argv[1:])
def get_next_arg(prompt, secure=False):
"""Read information from STDIN, using getpass when sensitive information should not be echoed to tty"""
try:
return next(argv_iter)
except StopIteration:
if secure is True:
return getpass.getpass(prompt)
else:
return input(prompt)
def main():
""" Primary script execution code """
# Configuration and information about objects to create.
admin_api = duo_client.Admin(
ikey=get_next_arg('Admin API integration key ("DI..."): '),
skey=get_next_arg('integration secret key: ', secure=True),
host=get_next_arg('API hostname ("api-....duosecurity.com"): '),
)
# Retrieve user info from API:
email_address = get_next_arg('E-mail address of user to retrieve: ')
user = admin_api.get_user_by_email(email_address)
if user:
print(user)
else:
print(f"User with email [{email_address}] could not be found.")
if __name__ == '__main__':
main()