bluesky_queueserver_api.http.REManagerAPI.apikey_new

REManagerAPI.apikey_new(*, expires_in, scopes=None, note=None, principal_uid=None)

Generate a new API key for authorized user. The API request is authorized using the default security key (set using set_authorization_key() or as a result of login).

Users with administrative privileges can generate API keys for other users based on principal UID. Principal UID may be found using REManagerAPI.whoami() or REManagerAPI.principal_info().

Parameters:
expires_in: int

Duration of API lifetime in seconds. Lifetime must be positive non-zero integer.

scopes: list(str) or None, optional

Optional list of scopes, such as ["read:status", "read:queue", "user:apikeys"]. If the value is None (default), then the new API inherits the allowed scopes of the principal (if authorized with token) or the original API key (if authorized with API key). Default: None.

note: str or None, optional

Optional note. Default: None.

principal_uid: str or None, optional

Principal UID of a user. Including principal UID allows to create API keys for any user registered in the database (user who logged into the server at least once). This operation requires administrative privileges. The API fails if principal_uid is not None and authorization is performed with security key that does not have administrative privileges. Default: None.

Returns:
dict

The API key is returned as 'secret' key of the dictionary.

Raises:
RequestParameterError

Incorrect or insufficient parameters in the API call.

HTTPRequestError, HTTPClientError, HTTPServerError

Error while sending and processing HTTP request.

Examples

Log into the server and create an API key, which inherits the scopes from principal:

RM.login("bob", password="bob_password")
result = RM.apikey_new(expires_in=900)

# {'first_eight': '66ccb3ca',
#  'expiration_time': '2022-10-02T03:29:20',
#  'note': None,
#  'scopes': ['inherit'],
#  'latest_activity': None,
#  'secret': '66ccb3ca33ea091ab297331ba2589bdcf7ea9f5f168dbfd90c156652d1cedd9533c1bc59'}