Optional: enable DEBUG log¶
Enable the DEBUG log to see the HTTP requests and responses.
In [ ]:
Copied!
import logging
logging.getLogger('requests.packages.urllib3').setLevel(logging.DEBUG)
import logging
logging.getLogger('requests.packages.urllib3').setLevel(logging.DEBUG)
Option 1: Get token by logging in¶
Create a file called ci_config.py
and add your username, password, client_id, and client_secret.
username = 'your_username'
password = 'your_password'
client_id = 'your_client_id'
client_secret = 'your_client_secret'
workspace_id = 'your_workspace_id' # optional
Then, create a SonyCi
instance with those credentials:
In [ ]:
Copied!
import ci_config
from sonyci import SonyCi
ci = SonyCi(
username=ci_config.username,
password=ci_config.password,
client_id=ci_config.client_id,
client_secret=ci_config.client_secret,
workspace_id=ci_config.workspace_id,
)
import ci_config
from sonyci import SonyCi
ci = SonyCi(
username=ci_config.username,
password=ci_config.password,
client_id=ci_config.client_id,
client_secret=ci_config.client_secret,
workspace_id=ci_config.workspace_id,
)
Now, you can use the API:
In [ ]:
Copied!
ci(f'workspaces/{ci.workspace_id}')
ci(f'workspaces/{ci.workspace_id}')
Option 2: Use an existing token from file¶
This example creates a new ApiClient
using the token from running $ ci login
In [ ]:
Copied!
from requests_oauth2client.tokens import BearerTokenSerializer
with open('../.token') as f:
token = BearerTokenSerializer().loads(f.read())
from requests_oauth2client.tokens import BearerTokenSerializer
with open('../.token') as f:
token = BearerTokenSerializer().loads(f.read())
In [ ]:
Copied!
from sonyci.sonyci import SonyCi
ci = SonyCi(t=token)
from sonyci.sonyci import SonyCi
ci = SonyCi(t=token)
In [ ]:
Copied!
ci('workspaces')
ci('workspaces')
Load from a toml file¶
Load the config from a toml file
In [ ]:
Copied!
ci = SonyCi.load_from_toml('../ci.toml')
ci('workspaces')
ci = SonyCi.load_from_toml('../ci.toml')
ci('workspaces')