|
1 | 1 | #!/usr/bin/env python
|
2 | 2 | #
|
3 |
| -# This example shows the different aspects of user/team management |
| 3 | +# This example shows the different aspects of user/team management. |
4 | 4 | #
|
5 | 5 |
|
6 | 6 | import os
|
|
26 | 26 | team_name = sys.argv[2]
|
27 | 27 | user_name = sys.argv[3]
|
28 | 28 |
|
29 |
| -print 'Trying to invite a user ', user_name |
| 29 | +print 'Trying to invite a user:', user_name |
30 | 30 | res = sdclient.create_user_invite(user_name)
|
31 | 31 | if res[0] == False:
|
32 |
| - print 'User creation failed: ', res[1] |
| 32 | + if res[1] == 'user ' + user_name + ' already exists': |
| 33 | + print 'User creation failed because', user_name ,'already exists. Continuing.' |
| 34 | + else: |
| 35 | + print 'User creation failed:', res[1], '. Exiting.' |
| 36 | + sys.exit(1) |
33 | 37 | else:
|
34 | 38 | print 'User creation succeeded'
|
35 | 39 |
|
36 |
| -print 'Now trying to create a team with name ', team_name |
| 40 | +# Possible failures on Team creation might include having reached the |
| 41 | +# max limit on Teams for this customer account or if the Team by that |
| 42 | +# name already exists. Since a previous successful run of this test |
| 43 | +# would have deleted the Team by the same name, and we need to be able |
| 44 | +# to configure Teams for this test to pass, we'll treat both types of |
| 45 | +# error as a genuine fail of the test. |
| 46 | +print 'Now trying to create a team with name:', team_name |
37 | 47 | res = sdclient.create_team(team_name)
|
38 | 48 | if res[0] == False:
|
39 |
| - print 'Team creation failed: ', res[1] |
| 49 | + print 'Team creation failed:', res[1], '. Exiting.' |
| 50 | + sys.exit(1) |
40 | 51 | else:
|
41 | 52 | print 'Team creation succeeded.', res[1]
|
42 | 53 |
|
43 |
| -print 'Now trying to find team with name ', team_name |
| 54 | +print 'Now trying to find team with name:', team_name |
44 | 55 | res = sdclient.get_team(team_name)
|
45 | 56 | if res[0] == False:
|
46 |
| - print 'Could not get team info' |
| 57 | + print 'Could not get team info:', res[1], '. Exiting.' |
| 58 | + sys.exit(1) |
47 | 59 | else:
|
48 | 60 | print 'Team fetch succeeded'
|
49 | 61 |
|
50 |
| -print 'Now trying to edit team ', team_name |
| 62 | +print 'Now trying to edit team:', team_name |
51 | 63 | memberships = {
|
52 | 64 | 'admin@draios.com': 'ROLE_TEAM_MANAGER',
|
53 | 65 | 'john-doe@sysdig.com': 'ROLE_TEAM_READ'
|
54 | 66 | }
|
55 | 67 | res = sdclient.edit_team(team_name, description='Nextgen2', memberships=memberships)
|
56 | 68 | if res[0] == False:
|
57 |
| - print 'Could not edit team ', res[1] |
| 69 | + print 'Could not edit team:', res[1], '. Exiting.' |
| 70 | + sys.exit(1) |
58 | 71 | else:
|
59 | 72 | print 'Edited team to change description and add users'
|
60 | 73 |
|
61 |
| -print 'Now trying to edit user ', user_name |
| 74 | +print 'Now trying to edit user:', user_name |
62 | 75 | res = sdclient.edit_user(user_name, firstName='Just', lastName='Edited3', systemRole='ROLE_CUSTOMER')
|
63 | 76 | if res[0] == False:
|
64 |
| - print 'Could not edit user: ', res[1] |
| 77 | + print 'Could not edit user:', res[1], '. Exiting.' |
| 78 | + sys.exit(1) |
65 | 79 | else:
|
66 | 80 | print 'Edit user succeeded'
|
67 | 81 |
|
68 |
| -print 'Now trying to delete the team ', team_name |
| 82 | +print 'Now trying to delete the team:', team_name |
69 | 83 | res = sdclient.delete_team(team_name)
|
70 | 84 | if res[0] == False:
|
71 |
| - print 'Could not delete team: ', res[1] |
| 85 | + print 'Could not delete team:', res[1], '. Exiting.' |
| 86 | + sys.exit(1) |
72 | 87 | else:
|
73 | 88 | print 'Delete team succeeded'
|
74 | 89 |
|
|
0 commit comments