diff --git a/.travis.yml b/.travis.yml index 5741a6c1..89c559e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ script: - examples/print_data_retention_info.py XXX - examples/print_explore_grouping.py XXX - examples/print_user_info.py XXX +- examples/list_users.py XXX - examples/list_sysdig_captures.py XXX - examples/create_sysdig_capture.py XXX ip-10-0-1-115.ec2.internal apicapture 10 - examples/notification_channels.py XXX diff --git a/examples/list_users.py b/examples/list_users.py new file mode 100755 index 00000000..b0c72628 --- /dev/null +++ b/examples/list_users.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# +# List all the users in a Sysdig Monitor environment. The token you provide must +# have Admin rights. +# + +import os +import sys +sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..')) +from sdcclient import SdcClient + +# +# Parse arguments +# +if len(sys.argv) != 2: + print 'usage: %s ' % sys.argv[0] + print 'You can find your token at https://app.sysdigcloud.com/#/settings/user' + print 'For this script to work, the user for the token must have Admin rights' + sys.exit(1) + +sdc_token = sys.argv[1] + +# +# Instantiate the SDC client +# +sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com') + +# +# Get the configuration +# +res = sdclient.get_users() +if res[0]: + print 'Users\n=====' + for user in res[1]: + print user['username'] +else: + print res[1] + sys.exit(1) diff --git a/sdcclient/_client.py b/sdcclient/_client.py index b8490242..40787bdf 100644 --- a/sdcclient/_client.py +++ b/sdcclient/_client.py @@ -1409,6 +1409,18 @@ def get_user(self, user_email): return [True, u] return [False, 'User not found'] + def get_users(self): + '''**Description** + Return a list containing details about all users in the Sysdig Monitor environment. The API token must have Admin rights for this to succeed. + + **Success Return Value** + A list user objects + ''' + res = requests.get(self.url + '/api/users', headers=self.hdrs, verify=self.ssl_verify) + if not self.__checkResponse(res): + return [False, self.lasterr] + return [True, res.json()['users']] + def edit_user(self, user_email, firstName=None, lastName=None, roles=None, teams=None): res = self.get_user(user_email) if res[0] == False: