Managing Connections
9 min
how it works all api calls that interface with a litmus edge instance need to have a specified connection instance litmus edge the sdk uses the oauth2 authentication framework for generating an oauth2 key for your litmus edge instance please see https //docs litmus io/litmusedge/product features/system/access control/tokens/create api token generating a oauth 2 litmus edge token navigate to system > access control > tokens in your litmus edge client press the plus icon next to api credentials and select "oauth 2 0 client" (if your instance only has api key than this version is unsupported for the sdk) grant your token admin permissions or equivalent (lesser permissions are supported but may limit functionality of the sdk) copy the client id and client secret configuration configuration for the litmus sdk uses dotenv variables to control settings this can be done with a env file in the root directory system variables using export {varaible name}={value} using the cli configure your instance by running the following in your shell export edge url={url} export edge api client id={client id} export edge api client secret={client secret} note this only creates local system variables and will only work for the current shell instance loading from env (this method requires python dotenv as an external dependency) install the python dotenv library eg pip install python dotenv create a env variable with the following parameters edge url={url} edge api client id={client id} edge api client secret={client secret} litmus edge manager litmus edge manager uses the lem bridge which only requires a normal api token generating an api token for the litmus edge manager bridge in the litmus edge manager admin console navigate to settings > tokens > new configure a token and enable the edge api bridge (this will allow the sdk to use the lem bridge to communicate with individual edge devices) under token scope select which projects the token will have access to create token and copy it configuration to configure authorization on for the sdk, do any of the following using the cli configure your instance by running the following in the cli export use lem bridge=true export edge manager url={url of edge manager} export edge manager project id={project id} export edge manager device id={device id} export edge api token={api token of lem} loading from env see loading from env under litmus edge configuration managing multiple connections alongside the default connection which is specified from environment variables you can manually create an le connection object for use with api calls this can be done with one of the following new le connection creates a direct le connection using oauth client new lem connection creates an le connection using the lem bridge both functions can be found in the litmussdk utils conn package all functions can take a direct le connection instance from litmussdk utils conn import new le connection from litmussdk devicehub import devices \# uses default connection (from env variables) devices list all devices() \# uses specified connection my connection = new le connection( edge url="127 0 0 1", edge client id=" ", edge client secret=" ", ) devices list devices(my connection) refreshing default connection the get default connection cache can be cleared using refresh default connection if environment variables are changed during runtime from litmussdk import config from litmussdk utils import conn config refresh default connection() license copyright (c) litmus automation inc