Skip to content

New "get_users" function and corresponding example/automation #39

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

Merged
merged 2 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions examples/list_users.py
Original file line number Diff line number Diff line change
@@ -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 <sysdig-token>' % 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)
12 changes: 12 additions & 0 deletions sdcclient/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down