Skip to main content

Module pdp implements a client for making authz requests to a Policy Decision Point (OPA)

Project description

opa-python-client

build-logo

Abstract

build.security provides simple development and management for your organization's authorization policy. opa-python-client is a Python 3 package that performs authorization requests against build.security PDPs (Policy Decision Point)/OPA.

Data Flow

drawing

Usage

Before you start we recommend completing the onboarding tutorial.


Important note

To simplify the setup process, the following example uses a local build.security PDP instance. If you are already familiar with how to run your PDP, You can also run a PDP on your environment (Dev/Prod, etc).

In that case, don't forget to change the hostname and port in your code.


Simple usage

Initialize the client, initialize some input for the PDP, and make a request:

from from opaclient import PolicyDecisionPointClient, PolicyDecisionPointInput, AuthzException

client = PolicyDecisionPointClient(hostname='http://some.host', port=8181,
             policy_path='mypolicy', read_timeout_milliseconds=100, connection_timeout_milliseconds=100,
             retry_max_attempts=5, retry_backoff_milliseconds=1000)

input = PolicyDecisionPointInput(schema='http', method='POST', more_authz_context=some_value,
             even_more_authz_context=some_other_value=some_other_value)

try:
    authz = client.authorize(input)
except AuthzException as e:
    raise

if authz:
    print('The request has been authorized!')

Mandatory configuration to initialize the client

  1. hostname - The hostname of the Policy Decision Point (PDP)
  2. port - The port at which the PDP service is serving authz decisions
  3. policy_path - Full path to the policy (including the rule) that decides whether requests should be authorized

How to get your pdp's hostname and port?

Optional configuration

  1. retry_max_attempts - the maximum number of retry attempts in case a failure occurs. Default is 2.
  2. read_timeout_milliseconds - Read timeout for requests in milliseconds. Default is 5000
  3. connection_timeout_milliseconds - Connection timeout in milliseconds. Default is 5000
  4. retry_backoff_milliseconds - The number of milliseconds to wait between two consecutive retry attempts. Default is 250

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

opaclient-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opaclient-0.1.0-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: opaclient-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for opaclient-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1f5ed38d54e35121922193d48763912dc15c1e0d6b86c22464883310d0c6ec6b
MD5 921123b5440d0b04b2b96f8b6078a1e5
BLAKE2b-256 44aca14e1a1ca7f224acf1bed1c20db22cf689bdab772b049481ba384d11b907

See more details on using hashes here.

File details

Details for the file opaclient-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: opaclient-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for opaclient-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5ea2a4bf8ea4e2d724992fe66fb54d187a61429b927d3f7b3164ff3238d74d0e
MD5 97b5ae3f0af212ed8fd1116da19303fc
BLAKE2b-256 1e6f67ad90f41d56ec85c6e10ed4f8c49280efb407588693582e4deb75b478a0

See more details on using hashes here.

Supported by

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