Skip to content

Commit 333c8fa

Browse files
philrzDavide Schiera
authored and
Davide Schiera
committed
New "get_users" function and corresponding example/automation (#39)
* Add function to get all users and an example that uses it. * Have the list_users example run via Travis automation
1 parent 9b835c3 commit 333c8fa

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ script:
2828
- examples/print_data_retention_info.py XXX
2929
- examples/print_explore_grouping.py XXX
3030
- examples/print_user_info.py XXX
31+
- examples/list_users.py XXX
3132
- examples/list_sysdig_captures.py XXX
3233
- examples/create_sysdig_capture.py XXX ip-10-0-1-115.ec2.internal apicapture 10
3334
- examples/notification_channels.py XXX

examples/list_users.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
#
3+
# List all the users in a Sysdig Monitor environment. The token you provide must
4+
# have Admin rights.
5+
#
6+
7+
import os
8+
import sys
9+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
10+
from sdcclient import SdcClient
11+
12+
#
13+
# Parse arguments
14+
#
15+
if len(sys.argv) != 2:
16+
print 'usage: %s <sysdig-token>' % sys.argv[0]
17+
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
18+
print 'For this script to work, the user for the token must have Admin rights'
19+
sys.exit(1)
20+
21+
sdc_token = sys.argv[1]
22+
23+
#
24+
# Instantiate the SDC client
25+
#
26+
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')
27+
28+
#
29+
# Get the configuration
30+
#
31+
res = sdclient.get_users()
32+
if res[0]:
33+
print 'Users\n====='
34+
for user in res[1]:
35+
print user['username']
36+
else:
37+
print res[1]
38+
sys.exit(1)

sdcclient/_client.py

+12
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,18 @@ def get_user(self, user_email):
14091409
return [True, u]
14101410
return [False, 'User not found']
14111411

1412+
def get_users(self):
1413+
'''**Description**
1414+
Return a list containing details about all users in the Sysdig Monitor environment. The API token must have Admin rights for this to succeed.
1415+
1416+
**Success Return Value**
1417+
A list user objects
1418+
'''
1419+
res = requests.get(self.url + '/api/users', headers=self.hdrs, verify=self.ssl_verify)
1420+
if not self.__checkResponse(res):
1421+
return [False, self.lasterr]
1422+
return [True, res.json()['users']]
1423+
14121424
def edit_user(self, user_email, firstName=None, lastName=None, roles=None, teams=None):
14131425
res = self.get_user(user_email)
14141426
if res[0] == False:

0 commit comments

Comments
 (0)