TruStar (Main Class)¶
For each API endpoint, there is a method on this class for making calls to it. The instance can be configured with either a dictionary or config file. If using a config file, it should be an INI file with the extension .conf or .ini. The configuration file can use sections to hold different configurations within the same file. For instance, if a user has both a standard account and a demo account, they could use an configuration file like the one below:
[trustar]
auth_endpoint = https://api.trustar.co/oauth/token
api_endpoint = https://api.trustar.co/api/1.3
user_api_key = <api_key>
user_api_secret = <api_secret>
enclave_ids = <enclave1_id>,<enclave2_id>,...
[demo]
auth_endpoint = https://demo.trustar.co/oauth/token
api_endpoint = https://demo.trustar.co/api/1.3
user_api_key = <api_key>
user_api_secret = <api_secret>
enclave_ids = <demo_enclave1_id>,<demo_enclave2_id>,...
An instance could then be configured to use the API with the demo account as follows:
ts = TruStar(config_file="trustar.conf", config_role="demo")
-
class
trustar.trustar.TruStar(config_file=None, config_role=None, config=None)¶ -
__init__(config_file=None, config_role=None, config=None)¶ Constructs and configures the instance. Initially attempts to use
config; if it isNone, then attempts to useconfig_fileinstead.The only required config keys are
user_api_keyanduser_api_secret. To obtain these values, login to TruSTAR Station in your browser and visit the API tab under SETTINGS to generate an API key and secret.All available keys, and their defaults, are listed below:
key required default description user_api_keyYes TrueAPI key user_api_secretYes TrueAPI secret enclave_idsNo []a list (or comma-separated list) of enclave ids auth_endpointNo "https://api.trustar.co/oauth/token"the URL used to obtain OAuth2 tokens api_endpointNo "https://api.trustar.co/api/1.3"the base URL used for making API calls station_base_urlNo "https://station.trustar.co"the base URL for Station verifyNo Truewhether to use SSL verification retryNo Truewhether to wait and retry requests that fail with 429 max_wait_timeNo 60fail if 429 wait time is greater than this (seconds) client_typeNo "Python_SDK"the name of the client being used client_versionNo the version of the Python SDK in use the version of the client being used client_metatagNo(*) Noneany additional information (ex. email address of user) http_proxyNo Nonehttp proxy being used - http(s)://user:pwd@{ip}:{port} https_proxyNo Nonehttps proxy being used - http(s)://user:pwd@{ip}:{port} (*): It will become mandatory on future versions of trustar, please try and update your code accordingly
Parameters: - config_file (str) – Path to configuration file (conf, json, or yaml). If no value is passed, the environment variable TRUSTAR_PYTHON_CONFIG_FILE will be used. If that is not defined, defaults to “trustar.conf”.
- config_role (str) – The section in the configuration file to use. If no value is passed, the environment variable TRUSTAR_PYTHON_CONFIG_ROLE will be used. If that is not defined, defaults to “trustar”.
- config (dict) – A dictionary of configuration options. This will override the config file path passed in
the
config_fileparameter.
-