Get started with the SDK
Python
Add the following dependency to your project:
pip install "git+ssh://git@github.com/graalsystems/sdk#subdirectory=python&egg=graalsystems"
Example:
from oauthlib.oauth2 import LegacyApplicationClient
from requests_oauthlib import OAuth2Session
import graalsystems
from graalsystems.api import project_api, tenant_api
tenant = "YOUR TENANT"
username = "YOUR USERNAME"
password = "YOUR PASSWORD"
api_url = "https://api.graal.systems/api/v1"
auth_url = "https://identity.graal.systems/auth"
#--- Get tenant info and realm, then prepare token
configuration = graalsystems.Configuration(
host = api_url,
discard_unknown_keys = True
)
with graalsystems.ApiClient(configuration) as api_client:
tenant_client = tenant_api.TenantApi(api_client)
try:
tenant_info = tenant_client.find_realm_by_tenant_id(tenant)
auth_url += "/realms/" + tenant_info.realm + "/protocol/openid-connect/token"
except graalsystems.ApiException as e:
print("Can not get tenant: %s\n" % e)
raise e
oauth = OAuth2Session(client=LegacyApplicationClient(client_id="graal-ui"))
token = oauth.fetch_token(token_url=auth_url, username=username,
password=password, include_client_id=True)
configuration.access_token = token['access_token']
#---
with graalsystems.ApiClient(configuration) as api_client:
project_client = project_api.ProjectApi(api_client)
try:
# Execute an action
projects = project_client.find_projects(tenant)
for p in projects:
print("- " + p.name)
except graalsystems.ApiException as e:
print("Can not list projects: %s\n" % e)