datastore module¶
Sputnik Datastore Implementation
This module provides the Sputnik Datastore implementation. It implements a thin wrapper around Redis, which is required in order to persist data across Bouncer restarts or network disconnections. This functionality is required due to the ephemeral filesystems typical to most Platform-as-a-Service Providers (PaaS).
-
class
datastore.
Datastore
(hostname, port)[source]¶ Bases:
object
A singleton that provides a thin wrapper to Redis.
The Datastore is responsible for persisting networks and channels in the event of an unexpected crash by either the Bouncer or a connected network. It also holds persistent, shared variables, such as the Bouncer password.
-
database
¶ redis.Redis
A Redis database connection.
-
add_network
(network, hostname, port, nickname, username, realname, password=None, usermode=0)[source]¶ Adds a network to the Redis instance.
Parameters: - network (str) – The name of the IRC network to connect to.
- hostname (str) – The hostname of the IRC network to connect to.
- port (int) – The port to connect using.
- nickname (str) – The IRC nickname to use when connecting.
- username (str) – The IRC ident to use when connecting.
- realname (str) – The real name of the user.
- password (str, optional) – Bouncer password. Defaults to
None
. - usermode (int, optional) – The IRC usermode. Defaults to
0
.
-
check_password
(password_attempt)[source]¶ Checks a password attempt against the Bouncer password.
Parameters: password_attempt (str) – The password attempt. Returns: Whether the password matched. Return type: bool
-
get_channels
(network='')[source]¶ Retrieves all connected channels from Redis.
This gets credentials for all connected channels, where credentials are of the form { “<network/channel>” : “<password>” }. If the network argument is specified, then the output is filtered to only include channels from the indicated network.
Parameters: network (str, optional) – The name of a network. Defaults to ""
.Returns: A dictionary of channel credentials. Return type: dict
-
get_networks
()[source]¶ Retrieves all connected networks from Redis.
This gets credentials for all connected networks, where credentials contain all values necessary to reconstruct a network connection, where networks are of the form { “<network_name>” : “<credentials>” }.
Returns: A dictionary of network credentials. Return type: dict
-
get_password
()[source]¶ Retrieves the Bouncer password from Redis.
Returns: The encrypted Bouncer password. Return type: str
-