hansken.connect
— Connecting to Hansken
The easiest way to run a script against the Hansken REST API is to use hansken.tool.run
,
a function designed to handle command line parsing and connecting the REST API.
When hansken.tool.run
is inconvenient, the connection functions in hansken.connect
provide ways to set up connections to the Hansken REST API.
Note
Other than hansken.tool.run
, the connection functions below do not
parse command line arguments;
set up and combine
logging
andlogbook
to log to either standard error or file;disable verbose SSL/TLS warnings when connecting to environments that use untrusted certificates.
- connect(endpoint, idp=None, username=None, password=None, auth=None, keystore=None, preference=None, verify=True, interactive=False, connection_pool_size=None, **kwargs)[source]
Connect to the Hansken REST API at endpoint.
Note
Only endpoint is a required argument here, but note that most Hansken environments will require some way of authentication. For environments configured with a single authentication option,
hansken.py
will automatically use the only option. When a choice is required, calls toconnect
will raise an error listing the options for the idp argument.Likewise, authentication methods requiring a username and password will produce an error when these are omitted and interactive is left
False
(setting this toTrue
will makehansken.py
prompt for required values that are missing).Manually passing a
HanskenAuthBase
object is supported through the auth argument, but not recommended.- Parameters:
endpoint – the URL of the Hansken REST API to connect to
idp – an identity provider id to authenticate to
username – a username to authenticate as
password – the password for username at idp
auth – a preconfigured authentication object (other authentication related arguments will be ignored)
keystore – the URL of the Hansken Keystore REST API
preference – the URL of the Hansken Preference REST API
verify –
how to check SSL/TLS certificates: -
True
: verify certificates (default); -False
: do not verify certificates; - path to a certificate file: verify certificates against a specificcertificate bundle.
interactive – whether to allow interactivity (like prompting for a password)
connection_pool_size – maximum size of HTTP(S) connection pool
kwargs – (ignored)
- Returns:
a
Connection
object connected to the Hansken REST API at endpoint
- connect_project(endpoint, project, idp=None, username=None, password=None, auth=None, keystore=None, preference=None, verify=True, interactive=False, connection_pool_size=None, **kwargs)[source]
Connect to the Hansken REST API at endpoint, using project as the project to attach to.
Note
Only endpoint and project are required arguments here, but note that most Hansken environments will require some way of authentication. For environments configured with a single authentication option, ``hansken.py`` will automatically use the only option. When a choice is required, calls to `.connect_project` will raise an error listing the options for the *idp argument.
Likewise, authentication methods requiring a username and password will produce an error when these are omitted and interactive is left
False
(setting this toTrue
will makehansken.py
prompt for required values that are missing).Manually passing a
HanskenAuthBase
object is supported through the auth argument, but not recommended.- Parameters:
endpoint – the URL of the Hansken REST API to connect to
project – the project id to attach to
idp – an identity provider id to authenticate to
username – a username to authenticate as
password – the password for username at idp
auth – a preconfigured authentication object (other authentication related arguments will be ignored)
keystore – the URL of the Hansken Keystore REST API
preference – the URL of the Hansken Preference REST API
verify –
how to check SSL/TLS certificates: -
True
: verify certificates (default); -False
: do not verify certificates; - path to a certificate file: verify certificates against a specificcertificate bundle.
interactive – whether to allow interactivity (like prompting for a password)
connection_pool_size – maximum size of HTTP(S) connection pool
kwargs – (ignored)
- Returns:
a
ProjectContext
object connected to the Hansken REST API at endpoint, attached to project project