Welcome to OrcaStorm’s documentation!¶
Apart from providing the module itself, this project comes with a test web server that you can try. The test web server is a well documented single file, and you can get the know-how from there. Please note that the test server is not included in the pypi package (e.g. it cannot be installed using pip or easy_install), but you can download the whole project repository from here: https://bitbucket.org/nagylzs/orcastorm/downloads or you can clone the project. For details, see https://bitbucket.org/nagylzs/orcastorm
Asynchronous client for SAASPASS and Tornado.
-
class
orcastorm.
AsyncBus
¶ Asynchronous notification bus.
This is a helper class that is used for asynchronous notifications between http requests. You can await for notifications on a set of keys, and you can send notifications for waiters of a given key. This is similar to a Condition object, with the following differences:
- AsyncBus.waitfor does have a timeout parameter (Condition does not)
- AsyncBus can automatically route notifications to multiple waiters using message identifiers (keys).
-
notify
(key, message)¶ Notify a single waiter.
Parameters: - key – Key value that identifies the waiter. Should be immutable.
- message – The message to be delivered to the waiter.
Returns: True if the waiter was notified, False otherwise.
-
notifyall
(key, message)¶ Notify all waiters. Return the number of waiters notified.
Parameters: - key – Key value that identifies the waiters. Should be immutable.
- message – The message to be delivered to the waiters.
Returns: The number of waiters notified
Type: int
-
waitforkey
(key, timeout=None)¶ Wait for notification on a single key.
Parameters: - key – An key to be listened to. Key should be immutable.
- timeout – If there is no notification coming in for the given timeout, then raise a BusTimeoutError.
Returns: A message that was sent by a notify() or notifyall() call.
-
waitforkeys
(keys, timeout=None)¶ Wait for notification.
Parameters: - keys – An iterable that contains keys to be listened to. Keys should be immutable.
- timeout – If there is no notification coming in for the given timeout, then raise a BusTimeoutError.
Returns: A tuple of (key, message) that was sent by a notify() or notifyall() call.
-
exception
orcastorm.
BusTimeoutError
¶ Raised when the waiter has been waiting for too long.
-
class
orcastorm.
OrcaStorm
(api_key, api_password, logger=None)¶ Asynchronous SaasPass authentication client that works with tornado.
-
get
(rel_url)¶ Send asnyc GET request to saaspass.com.
Parameters: rel_url – URL to get, relative to https://www.saaspass.com (including the starting /) Returns: a Future that has the future value of tornado.httpclient.HTTPResponse object.
-
get_and_parse
(rel_url)¶ Send asnyc GET request to saaspass.com and parse the response body as JSON data.
Parameters: rel_url – URL to get, relative to https://www.saaspass.com (including the starting /) Returns: a data structure loaded with json.loads on the response body.
-
get_barcode
(typ, sid)¶ Request, fetch barcode image.
Parameters: - typ – Type of the barcode. Can be: “IL”, “IRIL” etc. Look at the saaspass API documentation.
- sid – Session identifier. This identifies the user session and will be stored in the generated barcode.
Returns: base64 encoded barcode PNG image data
Return type: str
-
get_token
()¶ Get a valid token from SaasPass.
The token is fetched from saaspass.com and cached for token_ttl seconds.
-
notify_login
(sid, username)¶ Notify client(s) that a user has been logged in.
Parameters: - sid – The session id of the client who has just logged in with saaspass.
- username – The name of the user that has been logged in.
Returns: Number of clients notified.
-
token_ttl
= 3000.0¶
-
user_agent
= 'OrcaStorm 0.1.2'¶
-
validate_cert
= True¶
-
verify_otp
(username, otp)¶ Verify otp code for a user.
Parameters: - username – Name of the user (as assigned to the application account at www.saaspass.com)
- otp – One time password, provided by the SaasPass app.
Returns: The response object returned from the verification GET request. If the verification fails, then this method will raise tornado.httpclient.HTTPError
-
verify_tracker
(tracker_id, username)¶ Verify a tracker id.
Parameters: - tracker_id – The tracker id, as passed in the headers of the login POST callback.
- username – The username to be verified.
Returns: If the verification is successful then it returns True. Otherwise it raises a TrackerValidationError exception. If the GET request to saaspass fails then it raises tornado.httpclient.HTTPError.
-
wait_for_login
(sid, timeout)¶ Wait until a user is logged in.
Parameters: - sid – The session id of the client who is waiting for a login callback from saaspass.
- timeout – A datetime.timedelta instance.After the given timeout, a BusTimeoutError will be raised.
Returns: The name of the user that was logged in.(Saaspass returns a username that depends on the saaspass registration profile. It can be an email address or a phone number etc.)
Return type: str
-
-
exception
orcastorm.
TrackerValidationError
¶ Raised by OrcaStorm.verify_tracker when verification fails.