back to catalog
PythonAPI Tools
works in free trial | Built on 8.1.0.cl

User Tools Get code

Code by ThoughtSpot

ThoughtSpot user tools are a collection of tools for managing users and groups in ThoughtSpot as well as working with the ThoughtSpot Web APIs that manage users and groups.

The tools can be split into two broad categories. The first category contains the scripts that you can run to directly do things. The second category are the ThoughtSpot Web API Python wrappers. These are all contained in the tsut package and categorized into modules based on functionality, such as writing sync applications, modeling users and groups and calling the APIs from Python scripts.

Rate this code

Thank you for rating this code!

Installation instructions

Setup

User Tools is installed with the same process as other TS Python tools.

You can install using pip install --upgrade git+https://github.com/thoughtspot/user_tools

See the general documentation on setting up your environment and installing using pip.

Running the pre-built tools

All of the pre-built tools are run using the general format:

python -m user_tools.<tool-name>

Note there is no .py at the end and you must use python -m. So for example to run get_users and see the options, you would enter python -m user_tools.get_users --help Try it now and verify your environment is all set.

The user tools currently consist of four scripts:

  • delete_ugs, which deletes users and groups from a ThoughtSpot cluster.
  • get_users that can get users and groups from a ThoughtSpot cluster in multiple formats.
  • syncfromexcel that syncs ThoughtSpot from a properly formatted Excel document. The format for the Excel document is the same as the one created by get_users.
  • transfer_ownership that transfers all of the objects owned by one one user to another. Partial transfer of ownership is not currently supported.

You might also notice a validate_json file that is a simple, command line validator or JSON. Use if you like.

delete_ugs

Deletes users and/or groups specified in either the flags or a file from a ThoughtSpot cluster.

`usage: deleteugs [-h] [--tsurl TSURL] [--username USERNAME] [--password PASSWORD] [--disablessl] [--users USERS] [--groups GROUPS] [--userfile USER_FILE] [--groupfile GROUP_FILE]

optional arguments: -h, --help show this help message and exit --tsurl TSURL URL to ThoughtSpot, e.g. https://myserver --username USERNAME Name of the user to log in as. --password PASSWORD Password for login of the user to log in as. --disablessl Will ignore SSL errors. --users USERS List of user ids to delete. --groups GROUPS List of group ids to delete. --userfile USERFILE File with list of user ids to delete. --groupfile GROUPFILE File with list of group ids to delete. getusers Retrieves all of the users and groups from a ThoughtSpot cluster and writes them to the output, a JSON file or Excel.

usage: get_users.py [-h] [--tsurl TSURL] [--username USERNAME] [--password PASSWORD] [--disable_ssl] [--group_privileges] [--outputtype OUTPUTTYPE] [--filename FILENAME]

optional arguments: -h, --help show this help message and exit --tsurl TSURL URL to ThoughtSpot, e.g. https://myserver --username USERNAME Name of the user to log in as. --password PASSWORD Password for login of the user to log in as. --disablessl Will ignore SSL errors. --groupprivileges Will also retrieve the group privileges for all groups. This could be slow. --outputtype OUTPUTTYPE One of stdout, csv, xls, excel, or json. --filename FILENAME Name of file to write to if not stdout. Required for CSV, Excel and JSON. `

syncfromexcel

Synchronized users and groups from an Excel document in the format created by getusers to a ThoughtSpot cluster. ` usage: syncfromexcel.py [-h] [--filename FILENAME] [--tsurl TSURL] [--username USERNAME] [--password PASSWORD] [--disable_ssl] [--removedeleted] [--applychanges] [--batchsize BATCH_SIZE] [--creategroups] [--mergegroups]

optional arguments: -h, --help show this help message and exit --filename FILENAME Name of file to read from. --tsurl TSURL URL to ThoughtSpot, e.g. https://myserver --username USERNAME Name of the user to log in as. --password PASSWORD Password for login of the user to log in as. --disablessl Will ignore SSL errors. --removedeleted Will remove users not in the synced list. Cannot be used with batchsize. --applychanges Will apply changes when syncing users and groups. Default is False for testing. --batchsize BATCHSIZE Loads the users in batches of the given size to avoid timeouts. --creategroups Creates user groups if they don't exist and are not specified. --mergegroups Merge user groups with ones they are already in instead of replacing. `

transfer_ownership

Transfers the ownership of all objects from one user to another in a ThoughtSpot cluster. ` usage: transferownership [-h] [--tsurl TSURL] [--username USERNAME] [--password PASSWORD] [--disablessl] [--fromuser FROM_USER] [--touser TO_USER]

optional arguments: -h, --help show this help message and exit --tsurl TSURL URL to ThoughtSpot, e.g. https://myserver --username USERNAME Name of the user to log in as. --password PASSWORD Password for login of the user to log in as. --disablessl Will ignore SSL errors. --fromuser FROMUSER User to transfer ownership from. --touser TO_USER User to transfer ownership to. `

Writing Custom Scripts

While the pre-defined tools are convenient, they don't cover all possible scenarios. See the custom folder for details on how to write your own sync script.

Get code