Skip to content
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

Update bypass code endpoint with new parameter #274

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,16 +941,31 @@ def enroll_user(self, username, email, valid_secs=None):

return self.json_api_call('POST', path, params)

def add_user_bypass_codes(self, user_id, count=None, valid_secs=None, remaining_uses=None, codes=None, preserve_existing=None):
def add_user_bypass_codes(
self,
user_id,
count=None,
valid_secs=None,
remaining_uses=None,
codes=None,
preserve_existing=None,
endpoint_verification=None,
):
"""
Replace a user's bypass codes with new codes.

user_id - User ID
count - Number of new codes to randomly generate
valid_secs - Seconds before codes expire (if 0 they will never expire)
remaining_uses - The number of times this code can be used (0 is unlimited)
codes - Optionally provide custom codes, otherwise will be random
count and codes are mutually exclusive
Generate bypass codes for user.
Replaces a user's bypass codes with new codes unless
`preserve_existing=True` is passed.

user_id User ID
count Number of new codes to randomly generate
valid_secs Seconds before codes expire (if 0 they will never expire)
remaining_uses The number of times this code can be used (0 is unlimited)
codes Optionally provide custom codes, otherwise will be random
count and codes are mutually exclusive
preserve_existing whether to preserve existing codes when creating new ones,
default is to remove existing bypass codes
endpoint_verification New argument for unreleased feature. Will be ignored if used.
Client will be updated again in the future when feature is released.

Returns a list of newly created codes.

Expand All @@ -966,6 +981,9 @@ def add_user_bypass_codes(self, user_id, count=None, valid_secs=None, remaining_
if valid_secs is not None:
params['valid_secs'] = str(int(valid_secs))

if endpoint_verification is not None:
params["endpoint_verification"] = str(endpoint_verification).lower()

if remaining_uses is not None:
params['reuse_count'] = str(int(remaining_uses))

Expand Down
Loading