Client¶
There are two ways to instantiate a saltant client:
- Having it read settings from your environment
- Giving it settings directly
For (1), you need to have environment variables SALTANT_API_URL and
SALTANT_AUTH_TOKEN defined; once you do, you can instantiate a
client like so:
from saltant.client import from_env
my_client = from_env()
For (2), you supply the API URL and auth token directly:
from saltant.client import Client
my_client = Client(
base_api_url='https://shahlabjobs.ca/api/',
auth_token='p0gch4mp101fy451do9uod1s1x9i4a')
Client reference¶
-
class
saltant.client.Client(base_api_url, auth_token, default_timeout=90, test_if_authenticated=True)¶ API client for communicating with a saltant server.
Example
>>> from saltant.client import Client >>> client = Client( ... base_api_url='https://shahlabjobs.ca/api/', ... auth_token='p0gch4mp101fy451do9uod1s1x9i4a')
-
base_api_url¶ str – The URL of the saltant API.
-
session¶ requests.Session– A session object to make requests with.
-
container_task_instances¶ saltant.models.container_task_instance.ContainerTaskInstanceManager– A manager for performing actions related to container task instances.
-
container_task_types¶ saltant.models.container_task_type.ContainerTaskTypeManager– A manager for performing actions related to container task types.
-
executable_task_instances¶ saltant.models.executable_task_instance.ExecutableTaskInstanceManager– A manager for performing actions related to executable task instances.
-
executable_task_types¶ saltant.models.executable_task_type.ExecutableTaskTypeManager– A manager for performing actions related to executable task types.
-
task_queues¶ saltant.models.task_queues.TaskQueueManager– A manager for performing actions related to task queues.
-
task_whitelists¶ saltant.models.task_queues.TaskWhitelistManager– A manager for performing actions related to task whitelists.
-
users¶ saltant.models.user.UserManager– A manager for performing actions related to users.
-
classmethod
from_env(default_timeout=90)¶ Return a client configured from environment variables.
Essentially copying this: https://github.com/docker/docker-py/blob/master/docker/client.py#L43.
The environment variables looked for are the following:
-
SALTANT_API_URL¶ The URL of the saltant API. For example, https://shahlabjobs.ca/api/.
-
SALTANT_AUTH_TOKEN¶ The registered saltant user’s authentication token.
Example
>>> from saltant.client import from_env >>> client = from_env()
Parameters: default_timeout (int, optional) – The maximum number of seconds to wait for a request to complete. Defaults to 90 seconds. Returns: A saltant API client object. Return type: ClientRaises: saltant.exceptions.BadEnvironmentError– The user has an incorrectly configured environment.-
-
test_authentication()¶ Test that the client is authorized.
This currently assumes that read-only operations require authentication, which is the intended authentication protocol for saltant servers.
Raises: saltant.exceptions.AuthenticationError– The authentication provided was invalid.
-