http://hg.code.sf.net:8000/p/roundup/code/atom-log/tip/roundup/backends/sessions_sqlite.py Mercurial Repository: p/roundup/code: roundup/backends/sessions_sqlite.py history 2022-09-08T01:12:12-04:00 Set all sqlite db's to WAL mode on creation http://hg.code.sf.net:8000/p/roundup/code/#changeset-a96a239db0d9cfc7b55e4eccd13ef30a720417d9 John Rouillard rouilj@ieee.org 2022-09-08T01:12:12-04:00 2022-09-08T01:12:12-04:00
changeset a96a239db0d9
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Set all sqlite db's to WAL mode on creation

Complete work done on 6917:fba76e0bba98.

WAL journaling mode now enabled on primary db as well as session db's
when using sqlite for session databases.

Made change to WAL mode more robust for testing by bracketing
`pragma journal_mode=wal` with commit() calls. Normally the conversion
would occur when a new session was opened, but this commits the changes
explicitly to make all the tests stable.

Also added doc on this.
files
Refactor session db logging and key generation for sessions/otks http://hg.code.sf.net:8000/p/roundup/code/#changeset-fe0091279f507de2e77032a13ac13d031832c36c John Rouillard rouilj@ieee.org 2022-08-07T01:51:11-04:00 2022-08-07T01:51:11-04:00
changeset fe0091279f50
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Refactor session db logging and key generation for sessions/otks

While I was working on the redis sessiondb stuff, I noticed that
log_wanrning, get_logger ... was duplicated. Also there was code to
generate a unique key for otks that was duplicated.

Changes:

creating new sessions_common.py and SessionsCommon class to provide
methods:

log_warning, log_info, log_debug, get_logger, getUniqueKey

getUniqueKey method is closer to the method used to make
session keys in client.py.

sessions_common.py now report when random_.py chooses a weak
random number generator. Removed same from rest.py.

get_logger reconciles all logging under

roundup.hyperdb.backends.<name of BasicDatabase class>

some backends used to log to root logger.


have BasicDatabase in other sessions_*.py modules inherit from
SessionCommon.

change logging to use log_* methods.


In addition:

remove unused imports reported by flake8 and other formatting
changes

modify actions.py, rest.py, templating.py to use getUniqueKey
method.

add tests for new methods

test_redis_session.py
swap out ModuleNotFoundError for ImportError to prevent crash in
python2 when redis is not present.

allow injection of username:password or just password into redis
connection URL. set pytest_redis_pw envirnment variable to password
or user:password when running test.
files
Add tests to BasicDatabase and merge implementations http://hg.code.sf.net:8000/p/roundup/code/#changeset-375d40a9e730ee2cfbb5f3fa5760dce93bdad63c John Rouillard rouilj@ieee.org 2022-07-25T21:21:26-04:00 2022-07-25T21:21:26-04:00
changeset 375d40a9e730
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description Add tests to BasicDatabase and merge implementations

test/session_common.py:

add new tests:

* test set with bad __timestamps
* test get on missing item with no default
* test clear() method
* test new lifetime() method

everything below here was needed to get the tests to work across all
db's.

roundup/backends/sessions_dbm.py:

make set() validate __timestamp as float. If invalid and item is new,
set it to time.time(). If invalid and item exists keep original
timestamp.

add lifetime(key_lifetime) method. Given key_lifetime in seconds,
generate a __timestamp that will be deleted after that many seconds.

roundup/backends/sessions_rdbms.py:

make set() behave the same as session_dbm.

add lifetime method as above.

roundup/backends/sessions_sqlite.py:

import session_rdbms::BasicDatabase and override __init__.
rather than cloning all the code. Kept a few logging and sql methods.

roundup/test/memorydb.py:

make get() on a missing key return KeyError
make set() conform to dbm/rdbms implementations.
files
issue2551224 - Replace dbm db for sessions/otks when using sqlite http://hg.code.sf.net:8000/p/roundup/code/#changeset-25d08e15e3b4ea98a13540cf2388e33a9b227105 John Rouillard rouilj@ieee.org 2022-07-25T15:30:36-04:00 2022-07-25T15:30:36-04:00
changeset 25d08e15e3b4
branch
bookmark
tag
user John Rouillard <rouilj@ieee.org>
description issue2551224 - Replace dbm db for sessions/otks when using sqlite

Generate new sqlite db's for storing one time keys and session and
other ephemeral data.
files