TransIP Token

The TransipToken class is a helper class that takes care of authentication. The general idea is that everything should go automatically: generate a token when needed, and make sure to request a new one before the old one is expired.

class transip_rest_client.transip_token.TransipToken(login: str, RSAprivate_key: str, global_key: bool = False, read_only: bool = False, label: str = '', auth_url: str = 'https://api.transip.nl/v6/auth')[source]

A class to manage the needed token for the TransIP REST API. as documented on https://api.transip.nl/rest/docs.html#header-authentication

The steps taken are:

  • create a request body (including a random ‘nonce’ field and label(s))
  • create a signature by encrypting this request body with the private key
  • send a request to the auth endpoint with the request body and signature (this proves that we have the private key since TransIP can decrypt it with the public key)
  • a token is sent back to us by TransIP that can be used until it expires

Parameters:
  • login (str) – a login name for an existing TransIP account
  • RSAprivate_key (str) – a RSA (!) private key for this TransIP account (see _fix_token for check)
  • global_key (bool) – setting for key (see TransIP documentation)
  • read_only (bool) – setting for key (see TransIP documentation)
  • label (str) – label(s) for key (see TransIP documentation), concatenate with comma’s (“label1,label2”)
  • auth_url (str) – TransIP URL to authenticate to

get_token()[source]

Return the current token; create one when there is none

invalidate()[source]

enable outside world to invalidate the token so a new one will be generated next time

set_label(label: str)[source]

Set label(s). This will invalidate the existing token, so a new one will have to be generated

Parameters:label (str) – a string with the label(s) (separated by comma’s: “label1,label2”)
exception transip_rest_client.transip_token.TransipTokenAuthorisationException[source]

Raised when authorisation at TransIP fails. Usually this means that there is something wrong with the used private key (is it converted to RSA?). Whitelisting problems raise another exception.

exception transip_rest_client.transip_token.TransipTokenGeneralException[source]

Raised when something is wrong during the request of a token. There should be more information in the content of the exception

exception transip_rest_client.transip_token.TransipTokenPrivateKeyFormatException[source]

Raised when the supplied private key does not look correct