Skip to main content

Extensible and customizable policy definition and enforcement framework

Project description

Pylicy

An customizable and extensible policy creation and enforcement framework.

Installation

$ pip install pylicy

A Simple Example

Examples can be found in the examples/ directory.

import asyncio
import pylicy

@pylicy.policy_checker('token_age_policy')
async def my_policy(resource: pylicy.Resource, rule: pylicy.Rule) -> pylicy.PolicyDecision:
    if resource.data['token_age'] > 30:
        return pylicy.PolicyDecision(
            action=pylicy.PolicyDecisionAction.DENY,
            reason="expired",
            detail={'age': resource.data['token_age']}
        )
    elif resource.data['token_age'] > 20:
        return pylicy.PolicyDecision(action=pylicy.PolicyDecisionAction.WARN)
    else:
        return pylicy.PolicyDecision(action=pylicy.PolicyDecisionAction.ALLOW)

policies = pylicy.Pylicy.from_rules([
    pylicy.UserRule(
        name='token_age',
        resources=['*_token*'],
        policies=['token_*'],
    )
])

results = asyncio.run(policies.apply_all([
    pylicy.Resource(id='my_ok_token', data={'token_age': 10}),
    pylicy.Resource(id='my_old_token', data={'token_age': 21}),
    pylicy.Resource(id='my_expired_token', data={'token_age': 90})
]))

print(results)

License

This project is licensed under the terms of the MIT license.

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

pylicy-0.1.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

pylicy-0.1.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file pylicy-0.1.1.tar.gz.

File metadata

  • Download URL: pylicy-0.1.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.6 Linux/5.4.72-microsoft-standard-WSL2

File hashes

Hashes for pylicy-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d8c84a86936f3dba3ee535af3bc0ce9079dc43471ef454870e23ace89acfc7ef
MD5 44c0ace3eab58bc7ded10246c5de53cb
BLAKE2b-256 9aa5ee586cdc58036d8832902de1fab3eec98b5d1f2b5f81506da14bfd6f3e3c

See more details on using hashes here.

File details

Details for the file pylicy-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pylicy-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.6 Linux/5.4.72-microsoft-standard-WSL2

File hashes

Hashes for pylicy-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 908bc45fa1929b5e1e835f519a82041837f5e67721688658f2f58869f4c6575c
MD5 0812f6a66f9f97b06d976232fb3efe35
BLAKE2b-256 5559cc64c93675717c1902d968657f0070b7212606766084bdc44bbaa2952031

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