furemcape.hitdb package

Stores and queries log hits.

furemcape.hitdb.init(config_file='', url='', **params)

Initializes the hitdb.

Parameters
  • config_file (str) – Path to config file (defaults to default config file locations).

  • url (str) – DB connection URL (defaults to parameters specified in config file, or ‘postgresext://hitdb:hitdb@localhost:5432/hitdb’).

  • **params (dict) – Other kwargs are passed as connection parameters to DB.

furemcape.hitdb.migrate(migrate_dir='migrations')

Runs hitdb migrations.

Parameters

migrate_dir (str) – Path to migrations directory (defaults to ‘migrations’).

furemcape.hitdb.require(name)

Raises exception if hitdb migration not run.

Parameters

name (str) – Name of migration to check.

Raises

DoesNotExist – Migration not run. # noqa: DAR402

furemcape.hitdb.validate(migrate_dir='migrations')

Raises exception if not all hitdb migrations have been run.

Parameters

migrate_dir (str) – Path to migrations directory (defaults to ‘migrations’).

class furemcape.hitdb.Hit(*args, **kwargs)

Bases: furemcape.hitdb.db.BaseModel

Individual log entry.

id

Primary key.

Type

int

at

Entry timestamp.

Type

DateTime

system

System ID.

Type

str

session

Session token (eg ‘abc123==’ etc).

Type

str

ip

User IP address (eg ‘1.2.3.4’, ‘1234::abcd’, etc).

Type

str

user

User ID (eg ‘bob’, ‘bob@example.com’, etc).

Type

str

resource

Resource path/ID (eg ‘/documents/doc123.doc’ etc).

Type

str

action

Action ID (eg ‘GET’, ‘readDocument’, etc).

Type

str

error

Error ID (eg ‘404’, ‘Not Found’, etc).

Type

str

DoesNotExist

alias of HitDoesNotExist

action = <TextField: Hit.action>
at = <DateTimeTZField: Hit.at>
classmethod create_from_data(d, ignore_duplicate=False)

Creates a new hit entry and other related data within an transaction.

Parameters
  • d (dict) – Dict of field values.

  • ignore_duplicate (bool) – True to ignore duplicate key errors.

Returns

Newly saved hit entry.

Return type

Hit

Raises

e – IntegerityError when duplicate hit unless ignore_duplicate is true.

classmethod create_from_dict(d)

Creates a new hit entry from the specified dict of field values.

Parameters

d (dict) – Dict of field values.

Returns

Newly saved hit entry.

Return type

Hit

error = <TextField: Hit.error>
hitanalyzed_set
id = <BigAutoField: Hit.id>
ip = <InetField: Hit.ip>
static next_to_analyze(after='epoch')

Returns the next hit entry to analyze.

Parameters

after (DateTime) – Limit to hits after the specified datetime (defaults to the beginning of the epoch).

Returns

Next hit entry to analyze, or None.

Return type

Hit

resource = <TextField: Hit.resource>
session = <TextField: Hit.session>
system = <TextField: Hit.system>
to_dict()

Returns dict of field values.

Returns

Field values of this hit.

Return type

dict

user = <TextField: Hit.user>
class furemcape.hitdb.HitAnalyzed(*args, **kwargs)

Bases: furemcape.hitdb.db.BaseModel

Records whether an individual hit has been analyzed yet.

hit

Reference to hit entry (1:1 with hit table).

Type

Hit

at

Hit timestamp.

Type

DateTime

analyzed

True if analyzed.

Type

bool

unresolved

True if a hit field is pending resolution.

Type

bool

DoesNotExist

alias of HitAnalyzedDoesNotExist

analyzed = <BooleanField: HitAnalyzed.analyzed>
at = <DateTimeTZField: HitAnalyzed.at>
hit = <ForeignKeyField: HitAnalyzed.hit>
id = <ForeignKeyField: HitAnalyzed.hit>
classmethod next_to_analyze(after='epoch')

Returns the next hit_analyzed entry.

Parameters

after (DateTime) – Limit to hits after the specified datetime (defaults to the beginning of the epoch).

Returns

Next hit_analyzed entry, or None.

Return type

Hit

unresolved = <BooleanField: HitAnalyzed.unresolved>

Submodules

furemcape.hitdb.db module

Functions for setting up and accessing the hitdb.

class furemcape.hitdb.db.BaseModel(*args, **kwargs)

Bases: peewee.Model

Base model class for hitdb peewee models.

DoesNotExist

alias of BaseModelDoesNotExist

id = <AutoField: BaseModel.id>
furemcape.hitdb.db.db = <peewee.DatabaseProxy object>

Peewee Database object for hitdb.

furemcape.hitdb.db.init(config_file='', url='', **params)

Initializes the hitdb.

Parameters
  • config_file (str) – Path to config file (defaults to default config file locations).

  • url (str) – DB connection URL (defaults to parameters specified in config file, or ‘postgresext://hitdb:hitdb@localhost:5432/hitdb’).

  • **params (dict) – Other kwargs are passed as connection parameters to DB.

furemcape.hitdb.db.migrate(migrate_dir='migrations')

Runs hitdb migrations.

Parameters

migrate_dir (str) – Path to migrations directory (defaults to ‘migrations’).

furemcape.hitdb.db.require(name)

Raises exception if hitdb migration not run.

Parameters

name (str) – Name of migration to check.

Raises

DoesNotExist – Migration not run. # noqa: DAR402

furemcape.hitdb.db.validate(migrate_dir='migrations')

Raises exception if not all hitdb migrations have been run.

Parameters

migrate_dir (str) – Path to migrations directory (defaults to ‘migrations’).

furemcape.hitdb.hit module

Hitdb models.

class furemcape.hitdb.hit.Hit(*args, **kwargs)

Bases: furemcape.hitdb.db.BaseModel

Individual log entry.

id

Primary key.

Type

int

at

Entry timestamp.

Type

DateTime

system

System ID.

Type

str

session

Session token (eg ‘abc123==’ etc).

Type

str

ip

User IP address (eg ‘1.2.3.4’, ‘1234::abcd’, etc).

Type

str

user

User ID (eg ‘bob’, ‘bob@example.com’, etc).

Type

str

resource

Resource path/ID (eg ‘/documents/doc123.doc’ etc).

Type

str

action

Action ID (eg ‘GET’, ‘readDocument’, etc).

Type

str

error

Error ID (eg ‘404’, ‘Not Found’, etc).

Type

str

DoesNotExist

alias of HitDoesNotExist

action = <TextField: Hit.action>
at = <DateTimeTZField: Hit.at>
classmethod create_from_data(d, ignore_duplicate=False)

Creates a new hit entry and other related data within an transaction.

Parameters
  • d (dict) – Dict of field values.

  • ignore_duplicate (bool) – True to ignore duplicate key errors.

Returns

Newly saved hit entry.

Return type

Hit

Raises

e – IntegerityError when duplicate hit unless ignore_duplicate is true.

classmethod create_from_dict(d)

Creates a new hit entry from the specified dict of field values.

Parameters

d (dict) – Dict of field values.

Returns

Newly saved hit entry.

Return type

Hit

error = <TextField: Hit.error>
hitanalyzed_set
id = <BigAutoField: Hit.id>
ip = <InetField: Hit.ip>
static next_to_analyze(after='epoch')

Returns the next hit entry to analyze.

Parameters

after (DateTime) – Limit to hits after the specified datetime (defaults to the beginning of the epoch).

Returns

Next hit entry to analyze, or None.

Return type

Hit

resource = <TextField: Hit.resource>
session = <TextField: Hit.session>
system = <TextField: Hit.system>
to_dict()

Returns dict of field values.

Returns

Field values of this hit.

Return type

dict

user = <TextField: Hit.user>
class furemcape.hitdb.hit.HitAnalyzed(*args, **kwargs)

Bases: furemcape.hitdb.db.BaseModel

Records whether an individual hit has been analyzed yet.

hit

Reference to hit entry (1:1 with hit table).

Type

Hit

at

Hit timestamp.

Type

DateTime

analyzed

True if analyzed.

Type

bool

unresolved

True if a hit field is pending resolution.

Type

bool

DoesNotExist

alias of HitAnalyzedDoesNotExist

analyzed = <BooleanField: HitAnalyzed.analyzed>
at = <DateTimeTZField: HitAnalyzed.at>
hit = <ForeignKeyField: HitAnalyzed.hit>
id = <ForeignKeyField: HitAnalyzed.hit>
classmethod next_to_analyze(after='epoch')

Returns the next hit_analyzed entry.

Parameters

after (DateTime) – Limit to hits after the specified datetime (defaults to the beginning of the epoch).

Returns

Next hit_analyzed entry, or None.

Return type

Hit

unresolved = <BooleanField: HitAnalyzed.unresolved>