Skip to content
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
41 changes: 28 additions & 13 deletions examples/user_team_mgmt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# This example shows the different aspects of user/team management
# This example shows the different aspects of user/team management.
#

import os
Expand All @@ -26,49 +26,64 @@
team_name = sys.argv[2]
user_name = sys.argv[3]

print 'Trying to invite a user ', user_name
print 'Trying to invite a user:', user_name
res = sdclient.create_user_invite(user_name)
if res[0] == False:
print 'User creation failed: ', res[1]
if res[1] == 'user ' + user_name + ' already exists':
print 'User creation failed because', user_name ,'already exists. Continuing.'
else:
print 'User creation failed:', res[1], '. Exiting.'
sys.exit(1)
else:
print 'User creation succeeded'

print 'Now trying to create a team with name ', team_name
# Possible failures on Team creation might include having reached the
# max limit on Teams for this customer account or if the Team by that
# name already exists. Since a previous successful run of this test
# would have deleted the Team by the same name, and we need to be able
# to configure Teams for this test to pass, we'll treat both types of
# error as a genuine fail of the test.
print 'Now trying to create a team with name:', team_name
res = sdclient.create_team(team_name)
if res[0] == False:
print 'Team creation failed: ', res[1]
print 'Team creation failed:', res[1], '. Exiting.'
sys.exit(1)
else:
print 'Team creation succeeded.', res[1]

print 'Now trying to find team with name ', team_name
print 'Now trying to find team with name:', team_name
res = sdclient.get_team(team_name)
if res[0] == False:
print 'Could not get team info'
print 'Could not get team info:', res[1], '. Exiting.'
sys.exit(1)
else:
print 'Team fetch succeeded'

print 'Now trying to edit team ', team_name
print 'Now trying to edit team:', team_name
memberships = {
'admin@draios.com': 'ROLE_TEAM_MANAGER',
'john-doe@sysdig.com': 'ROLE_TEAM_READ'
}
res = sdclient.edit_team(team_name, description='Nextgen2', memberships=memberships)
if res[0] == False:
print 'Could not edit team ', res[1]
print 'Could not edit team:', res[1], '. Exiting.'
sys.exit(1)
else:
print 'Edited team to change description and add users'

print 'Now trying to edit user ', user_name
print 'Now trying to edit user:', user_name
res = sdclient.edit_user(user_name, firstName='Just', lastName='Edited3', systemRole='ROLE_CUSTOMER')
if res[0] == False:
print 'Could not edit user: ', res[1]
print 'Could not edit user:', res[1], '. Exiting.'
sys.exit(1)
else:
print 'Edit user succeeded'

print 'Now trying to delete the team ', team_name
print 'Now trying to delete the team:', team_name
res = sdclient.delete_team(team_name)
if res[0] == False:
print 'Could not delete team: ', res[1]
print 'Could not delete team:', res[1], '. Exiting.'
sys.exit(1)
else:
print 'Delete team succeeded'

Expand Down