Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max_line_length = 100
exclude = .venv,.mypy_cache,.pytest_cache
ignore = PT013,PT018,W503
24 changes: 24 additions & 0 deletions .github/workflows/poetry-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Upload OPA-python-client

on:
release:
types: [created]

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.8'
architecture: x64
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Build and publish
run: |
poetry version $(git describe --tags --abbrev=0)
poetry build
poetry publish --username ${{ secrets.PYPI_USERNAME }} --password ${{ secrets.PYPI_PASSWORD }}
Empty file.
28 changes: 28 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Contributing to OPA-python-client

We welcome contributions to [OPA-python-client](https://github.com/Turall/OPA-python-client)

## Issues

Feel free to submit issues and enhancement requests.

[OPA-python-client Issues](https://github.com/Turall/OPA-python-client/issues)

## Contributing

Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.

1. **Fork** the repo on GitHub
2. **Clone** the project to your own machine
3. **Commit** changes to your own branch
4. **Push** your work
5. Submit a **Pull request** so that we can review your changes


## Testing
```sh
$ docker run -it --rm -p 8181:8181 openpolicyagent/opa run --server --addr :8181
$ pytest
```

NOTE: Be sure to merge the latest from "upstream" before making a pull request!
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
lint:
@echo
isort --diff -c --skip-glob '*.venv' .
@echo
blue --check --diff --color .
@echo
flake8 .
@echo
mypy --ignore-missing-imports .


format_code:
isort .
blue .
65 changes: 31 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
# Python Open Policy Agent (OPA) Client

[![MIT licensed](https://img.shields.io/github/license/Turall/OPA-python-client)](https://raw.githubusercontent.com/Turall/OPA-python-client/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/Turall/OPA-python-client.svg)](https://github.com/Turall/OPA-python-client/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/Turall/OPA-python-client.svg)](https://github.com/Turall/OPA-python-client/network)
[![GitHub issues](https://img.shields.io/github/issues-raw/Turall/OPA-python-client)](https://github.com/Turall/OPA-python-client/issues)
[![Downloads](https://pepy.tech/badge/opa-python-client)](https://pepy.tech/project/opa-python-client)


See offical documentation page [Open Policy Agent](https://www.openpolicyagent.org/docs/latest/)


### Installation ###

```sh
$ pip install OPA-python-client
$ pip install OPA-python-client
```

Alternatively, if you prefer to use `poetry` for package dependencies:

```bash
$ poetry shell
$ poetry add OPA-python-client
```



## Usage Examples ##
## Usage Examples

```python
>>> from opa_client.opa import OpaClient
Expand Down Expand Up @@ -47,7 +58,7 @@ True
```


### Connection to OPA service ###
### Connection to OPA service

```python
from opa_client.opa import OpaClient
Expand All @@ -61,10 +72,9 @@ del client
```


### Connection to OPA service with SSL ###
### Connection to OPA service with SSL

```python

from opa_client.opa import OpaClient


Expand All @@ -82,9 +92,7 @@ del client
```




### Update policy from rego file ###
### Update policy from rego file

```python
from opa_client.opa import OpaClient
Expand All @@ -99,10 +107,9 @@ del client
```


### Update policy from URL ###
### Update policy from URL

```python

from opa_client.opa import OpaClient

client = OpaClient()
Expand All @@ -116,12 +123,10 @@ del client
```


### Delete policy ###
### Delete policy


```python


from opa_client.opa import OpaClient

client = OpaClient()
Expand All @@ -133,12 +138,10 @@ client.get_policies_list() # response is []
del client
```

### Get raw data from OPA service ###
### Get raw data from OPA service


```python


from opa_client.opa import OpaClient

client = OpaClient()
Expand All @@ -159,12 +162,11 @@ print(client.get_opa_raw_data("userinfo",query_params={"metrics": True}))
del client
```

### Save policy to file from OPA service ###


```python
### Save policy to file from OPA service


```python
from opa_client.opa import OpaClient

client = OpaClient()
Expand All @@ -174,12 +176,11 @@ client.opa_policy_to_file(policy_name="fromurl",path="/your/path",filename="exam
del client
```

### Delete data from OPA service ###


```python
### Delete data from OPA service


```python
from opa_client.opa import OpaClient

client = OpaClient()
Expand All @@ -190,12 +191,10 @@ del client
```


### Information about policy path and rules ###
### Information about policy path and rules


```python


from opa_client.opa import OpaClient

client = OpaClient()
Expand All @@ -208,12 +207,10 @@ del client
```


### Check permissions ###
### Check permissions


```python


from opa_client.opa import OpaClient

client = OpaClient()
Expand Down Expand Up @@ -250,7 +247,6 @@ hello {

check_data = {"message": "world"}
client.check_policy_rule(input_data=check_data, package_path="play", rule_name="hello") # response {'result': True}

```

### Execute an Ad-hoc Query
Expand Down Expand Up @@ -286,7 +282,6 @@ print(client.ad_hoc_query(query_params={"q": "data.userinfo.user_roles[name]"}))
#you can send body request
print(client.ad_hoc_query(body={"query": "data.userinfo.user_roles[name] "}))
# response is {'result': [{'name': 'eve'}, {'name': 'alice'}, {'name': 'bob'}]}

```

### Check OPA healthy. If you want check bundels or plugins, add query params for this.
Expand All @@ -301,12 +296,14 @@ print(client.check_health({"bundle": True})) # response is True or False
# If your diagnostic url different than default url, you can provide it.
print(client.check_health(diagnostic_url="http://localhost:8282/health")) # response is True or False
print(client.check_health(query={"bundle": True}, diagnostic_url="http://localhost:8282/health")) # response is True or False

```


# Contributing #
# Contributing

Fell free to open issue and send pull request.

#### Free to open issue and send PR ####
Thanks To [Contributors](https://github.com/Turall/OPA-python-client/graphs/contributors).
Contributions of any kind are welcome!

### OPA-python-client supports Python >= 3.5
Before you start please read [CONTRIBUTING](https://github.com/Turall/OPA-python-client/blob/master/CONTRIBUTING.md)
6 changes: 0 additions & 6 deletions opa_client/OpaExceptions/__init__.py

This file was deleted.

3 changes: 1 addition & 2 deletions opa_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Initialize the OpaClient package."""

from .opa import OpaClient
from .OpaExceptions import *

__all__ = [
"OpaClient",
'OpaClient',
]
Loading