Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liquibase_checks_python-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

liquibase_checks_python-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file liquibase_checks_python-0.1.0.tar.gz.

File metadata

File hashes

Hashes for liquibase_checks_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 80f3539dd31400237efd1147504f6650833e6b88b4466daa9cc0c68a789fdd28
MD5 098076963bf50520a4899a96fe739acb
BLAKE2b-256 1dba8bd0b1111af8f14fc1d6533dfb713412f768f2066f34b5f2628b6324c4ea

See more details on using hashes here.

File details

Details for the file liquibase_checks_python-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for liquibase_checks_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4540f5f0909e6931f7cc20ba274993c84728ea84f9b1721871922e837209a58
MD5 a8e18276be7dae664ad7084690bf6d54
BLAKE2b-256 f3dee4dc50995d4ca3197b9b07fab6fac694b6764b76bcef4592b6384289da1e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page