-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: add report_user_by_email.py to examples #242
Closed
MarkTripod-Duo
wants to merge
1
commit into
duosecurity:master
from
MarkTripod-Duo:report_user_by_email
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/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 | ||
from pprint import pprint | ||
|
||
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: ') | ||
req_params = {"email": email_address} | ||
# There is no get_user_by_email in the duo_client_python library, so we use the generic api_call | ||
user = admin_api.json_api_call( | ||
method='GET', | ||
path='/admin/v1/users', | ||
params=req_params | ||
) | ||
|
||
if user: | ||
pprint(user, indent=2) | ||
else: | ||
print(f"User with email [{email_address}] could not be found.") | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add a function in there? I don't know if this a common thing that people might want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a new method to the library specifically for this use case should be rather trivial. I do not have any data on generalized API usage for user searches via email address to offer an opinion on whether a separate method is warranted. Perhaps adding a new optional parameter to the get_users() method to specify the email address could be an alternate possible update to the library. However, adding a get_user_by_email() method would maintain consistency with other methods available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote let's add a
get_user_by_email
method - I agree it's easy and consistent. Do you want to handle that Mark?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New PR submitted.