Use python to write your custom policy checks for Liquibase
Project description
liquibase-checks-python
Write your custom policy checks using Python! Secure your database and lock down your CI by running your own custom logic to evaluate the safety and security of each database change.
Requirements
- Python 3.10 or graalpy-24.0.0
- Liquibase 4.29.0
Getting Started
We recommend installing liquibase-checks-python
in a virtual environment.
Installation
Create your virtual environment
python -m venv <path/to/venv>
Install liquibase-checks-python
pip install liquibase-checks-python
You can validate the package has been successfully installed by running pip list
Writing your first custom policy check
Create a file custom.py
inside your liquibase working directory.
touch custom.py
Configure a new database scoped CustomCheckTemplate
with the name MyCustomCheck
with liquibase and set the SCRIPT_PATH
to custom.py
liquibase checks customize --check-name CustomCheckTemplate
Open your custom.py
in your text editor and add the following:
from liquibase_checks_python import liquibase_utilities as lb
import sys
obj = lb.get_database_object()
status = lb.get_status()
if lb.is_table(obj):
status.fired = True
status.message = "No tables allowed!"
sys.exit(1)
Run your new custom check
liquibase --script-python-executable-path <path/to/venv>/bin/python --checks checks run --check-name MyCustomCheck --checks-scope database --checks-scripts-enabled
If your database has any tables, you should see a warning like this:
DATABASE CHECKS
---------------
Validation of the database snapshot found the following issues:
Check Name: Custom Check Template (test)
Object Type: table
Object Name: my_table
Object Location: DEV.PUBLIC.my_table
Check Severity: BLOCKER (Return code: 4)
Message: No tables allowed!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file liquibase_checks_python-0.1.0.tar.gz
.
File metadata
- Download URL: liquibase_checks_python-0.1.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80f3539dd31400237efd1147504f6650833e6b88b4466daa9cc0c68a789fdd28 |
|
MD5 | 098076963bf50520a4899a96fe739acb |
|
BLAKE2b-256 | 1dba8bd0b1111af8f14fc1d6533dfb713412f768f2066f34b5f2628b6324c4ea |
File details
Details for the file liquibase_checks_python-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: liquibase_checks_python-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4540f5f0909e6931f7cc20ba274993c84728ea84f9b1721871922e837209a58 |
|
MD5 | a8e18276be7dae664ad7084690bf6d54 |
|
BLAKE2b-256 | f3dee4dc50995d4ca3197b9b07fab6fac694b6764b76bcef4592b6384289da1e |