apicrud.Grants¶
-
class
apicrud.
Grants
(db_session=None, ttl=None)¶ Account usage limits
An account’s usage limits are specified here in the grants table; the free-service tier is defined and passed in via load_defaults(). Records in grants table are owned by administrator-level user. If a record matches a user uid, the default grant name=value is overridden.
-
db_session
¶ existing db session
- Type
obj
-
ttl
¶ how long to cache a grant in memory
- Type
int
-
__init__
(db_session=None, ttl=None)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([db_session, ttl])Initialize self.
crud_get
(crud_results, id)Process results from BasicCRUD.get() for grants endpoint.
find
(crud_results, **kwargs)Process results from BasicCRUD.find() for grants endpoint
get
(name[, uid])Get the cached value of a named grant, if it hasn’t expired
load_defaults
(defaults)Load default values from a dict of keyword: value pairs
uncache
(uid)Remove grants from cache, any time a user’s status changes
-
crud_get
(crud_results, id)¶ Process results from BasicCRUD.get() for grants endpoint. If the id is found in database, perform the standard CRUD get(). Otherwise, look for a hybrid id in form uid:grant and return the cached Grant value. Grant values are serialized as strings even if they are integers (decimal, octal, hex).
- Parameters
crud_results (tuple) – preliminary response
name (str) – name filter, if specified
-
find
(crud_results, **kwargs)¶ Process results from BasicCRUD.find() for grants endpoint
- Parameters
crud_results (tuple) – preliminary response
name (str) – name filter, if specified
-
get
(name, uid=None)¶ Get the cached value of a named grant, if it hasn’t expired
- Parameters
name (str) – name of a grant, as defined in service config
uid (str) – user ID
- Returns
granted limit or None if undefined
- Return type
int or str
-
load_defaults
(defaults)¶ Load default values from a dict of keyword: value pairs
- Parameters
defaults (dict) – new defaults
-
uncache
(uid)¶ Remove grants from cache, any time a user’s status changes
- Parameters
uid (str) – user ID
-