Skip to content

Commit efde689

Browse files
authored
Merge pull request #14 from sabuhish/master
Added poetry and formatter to the OPA client
2 parents 1d3b5f9 + 9d79107 commit efde689

File tree

14 files changed

+986
-433
lines changed

14 files changed

+986
-433
lines changed

.flake8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
max_line_length = 100
3+
exclude = .venv,.mypy_cache,.pytest_cache
4+
ignore = PT013,PT018,W503

.github/workflows/poetry-publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Upload OPA-python-client
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-python@v1
13+
with:
14+
python-version: '3.8'
15+
architecture: x64
16+
- name: Install dependencies
17+
run: |
18+
python -m pip install --upgrade pip
19+
pip install poetry
20+
- name: Build and publish
21+
run: |
22+
poetry version $(git describe --tags --abbrev=0)
23+
poetry build
24+
poetry publish --username ${{ secrets.PYPI_USERNAME }} --password ${{ secrets.PYPI_PASSWORD }}

.github/workflows/test-package.yml

Whitespace-only changes.

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Contributing to OPA-python-client
2+
3+
We welcome contributions to [OPA-python-client](https://github.com/Turall/OPA-python-client)
4+
5+
## Issues
6+
7+
Feel free to submit issues and enhancement requests.
8+
9+
[OPA-python-client Issues](https://github.com/Turall/OPA-python-client/issues)
10+
11+
## Contributing
12+
13+
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.
14+
15+
1. **Fork** the repo on GitHub
16+
2. **Clone** the project to your own machine
17+
3. **Commit** changes to your own branch
18+
4. **Push** your work
19+
5. Submit a **Pull request** so that we can review your changes
20+
21+
22+
## Testing
23+
```sh
24+
$ docker run -it --rm -p 8181:8181 openpolicyagent/opa run --server --addr :8181
25+
$ pytest
26+
```
27+
28+
NOTE: Be sure to merge the latest from "upstream" before making a pull request!

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
lint:
2+
@echo
3+
isort --diff -c --skip-glob '*.venv' .
4+
@echo
5+
blue --check --diff --color .
6+
@echo
7+
flake8 .
8+
@echo
9+
mypy --ignore-missing-imports .
10+
11+
12+
format_code:
13+
isort .
14+
blue .

README.md

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
# Python Open Policy Agent (OPA) Client
22

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

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

712

813
### Installation ###
914

1015
```sh
11-
$ pip install OPA-python-client
16+
$ pip install OPA-python-client
1217
```
1318

19+
Alternatively, if you prefer to use `poetry` for package dependencies:
20+
21+
```bash
22+
$ poetry shell
23+
$ poetry add OPA-python-client
24+
```
1425

1526

1627

17-
## Usage Examples ##
28+
## Usage Examples
1829

1930
```python
2031
>>> from opa_client.opa import OpaClient
@@ -47,7 +58,7 @@ True
4758
```
4859

4960

50-
### Connection to OPA service ###
61+
### Connection to OPA service
5162

5263
```python
5364
from opa_client.opa import OpaClient
@@ -61,10 +72,9 @@ del client
6172
```
6273

6374

64-
### Connection to OPA service with SSL ###
75+
### Connection to OPA service with SSL
6576

6677
```python
67-
6878
from opa_client.opa import OpaClient
6979

7080

@@ -82,9 +92,7 @@ del client
8292
```
8393

8494

85-
86-
87-
### Update policy from rego file ###
95+
### Update policy from rego file
8896

8997
```python
9098
from opa_client.opa import OpaClient
@@ -99,10 +107,9 @@ del client
99107
```
100108

101109

102-
### Update policy from URL ###
110+
### Update policy from URL
103111

104112
```python
105-
106113
from opa_client.opa import OpaClient
107114

108115
client = OpaClient()
@@ -116,12 +123,10 @@ del client
116123
```
117124

118125

119-
### Delete policy ###
126+
### Delete policy
120127

121128

122129
```python
123-
124-
125130
from opa_client.opa import OpaClient
126131

127132
client = OpaClient()
@@ -133,12 +138,10 @@ client.get_policies_list() # response is []
133138
del client
134139
```
135140

136-
### Get raw data from OPA service ###
141+
### Get raw data from OPA service
137142

138143

139144
```python
140-
141-
142145
from opa_client.opa import OpaClient
143146

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

162-
### Save policy to file from OPA service ###
163-
164165

165-
```python
166+
### Save policy to file from OPA service
166167

167168

169+
```python
168170
from opa_client.opa import OpaClient
169171

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

177-
### Delete data from OPA service ###
178-
179179

180-
```python
180+
### Delete data from OPA service
181181

182182

183+
```python
183184
from opa_client.opa import OpaClient
184185

185186
client = OpaClient()
@@ -190,12 +191,10 @@ del client
190191
```
191192

192193

193-
### Information about policy path and rules ###
194+
### Information about policy path and rules
194195

195196

196197
```python
197-
198-
199198
from opa_client.opa import OpaClient
200199

201200
client = OpaClient()
@@ -208,12 +207,10 @@ del client
208207
```
209208

210209

211-
### Check permissions ###
210+
### Check permissions
212211

213212

214213
```python
215-
216-
217214
from opa_client.opa import OpaClient
218215

219216
client = OpaClient()
@@ -250,7 +247,6 @@ hello {
250247

251248
check_data = {"message": "world"}
252249
client.check_policy_rule(input_data=check_data, package_path="play", rule_name="hello") # response {'result': True}
253-
254250
```
255251

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

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

307301

308-
# Contributing #
302+
# Contributing
303+
304+
Fell free to open issue and send pull request.
309305

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

312-
### OPA-python-client supports Python >= 3.5
309+
Before you start please read [CONTRIBUTING](https://github.com/Turall/OPA-python-client/blob/master/CONTRIBUTING.md)

opa_client/OpaExceptions/__init__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

opa_client/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""Initialize the OpaClient package."""
22

33
from .opa import OpaClient
4-
from .OpaExceptions import *
54

65
__all__ = [
7-
"OpaClient",
6+
'OpaClient',
87
]

0 commit comments

Comments
 (0)