apicrud.grants

grants.py

Grants

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.

created 27-may-2019 by richb@instantlinux.net

Classes

Grants([db_session, ttl])

Account usage limits

class apicrud.grants.Grants(db_session=None, ttl=None)

Account usage limits

db_session

existing db session

Type

obj

ttl

how long to cache a grant in memory

Type

int

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.

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 Note that if any grant assigned to a uid expires before others, the earliest expiration applies to all the uid’s grants

Parameters
  • name (str) – name of a grant, as defined in service config

  • uid (str) – user ID

Returns

granted limit

Return type

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