2
0
mirror of https://github.com/openkmip/pykmip synced 2025-12-18 09:13:46 +00:00

Add server support for customizing the backend storage file

This change updates the server, adding in support for customizing
the backend storage file used to store all server data. The server
currently uses a simple SQLite database for storage. Prior versions
of the server kept this database file in /tmp, to emphasize the
testing focus of the server. This change loosens that restriction,
now allowing users to customize where the database file lives. A
new configuration option, 'database_path', has been added that will
override the default /tmp location for the database file. This
value can also be passed in if invoking the server via script using
the '-d' flag.
This commit is contained in:
Peter Hamilton
2018-04-16 11:03:32 -04:00
parent f1ccdf9c5a
commit 2e6384a067
5 changed files with 119 additions and 9 deletions

View File

@@ -74,7 +74,7 @@ class KmipEngine(object):
* Cryptographic usage mask enforcement per object type
"""
def __init__(self, policies=None):
def __init__(self, policies=None, database_path=None):
"""
Create a KmipEngine.
@@ -82,13 +82,20 @@ class KmipEngine(object):
policy_path (string): The path to the filesystem directory
containing PyKMIP server operation policy JSON files.
Optional, defaults to None.
database_path (string): The path to the SQLite database file
used to store all server data. Optional, defaults to None.
If none, database path defaults to '/tmp/pykmip.database'.
"""
self._logger = logging.getLogger('kmip.server.engine')
self._cryptography_engine = engine.CryptographyEngine()
self.database_path = 'sqlite:///{}'.format(database_path)
if not database_path:
self.database_path = 'sqlite:////tmp/pykmip.database'
self._data_store = sqlalchemy.create_engine(
'sqlite:////tmp/pykmip.database',
self.database_path,
echo=False,
connect_args={'check_same_thread': False}
)