@@ -13,13 +13,19 @@ See offical documentation page [Open Policy Agent](https://www.openpolicyagent.o
13
13
### Installation ###
14
14
15
15
``` sh
16
- $ pip install OPA-python-client
16
+ $ pip install OPA-python-client
17
17
```
18
18
19
+ Alternatively, if you prefer to use ` poetry ` for package dependencies:
20
+
21
+ ``` bash
22
+ $ poetry shell
23
+ $ poetry add OPA-python-client
24
+ ```
19
25
20
26
21
27
22
- ## Usage Examples ##
28
+ ## Usage Examples
23
29
24
30
``` python
25
31
>> > from opa_client.opa import OpaClient
52
58
```
53
59
54
60
55
- ### Connection to OPA service ###
61
+ ### Connection to OPA service
56
62
57
63
``` python
58
64
from opa_client.opa import OpaClient
@@ -66,10 +72,9 @@ del client
66
72
```
67
73
68
74
69
- ### Connection to OPA service with SSL ###
75
+ ### Connection to OPA service with SSL
70
76
71
77
``` python
72
-
73
78
from opa_client.opa import OpaClient
74
79
75
80
@@ -87,9 +92,7 @@ del client
87
92
```
88
93
89
94
90
-
91
-
92
- ### Update policy from rego file ###
95
+ ### Update policy from rego file
93
96
94
97
``` python
95
98
from opa_client.opa import OpaClient
@@ -104,10 +107,9 @@ del client
104
107
```
105
108
106
109
107
- ### Update policy from URL ###
110
+ ### Update policy from URL
108
111
109
112
``` python
110
-
111
113
from opa_client.opa import OpaClient
112
114
113
115
client = OpaClient()
@@ -121,12 +123,10 @@ del client
121
123
```
122
124
123
125
124
- ### Delete policy ###
126
+ ### Delete policy
125
127
126
128
127
129
``` python
128
-
129
-
130
130
from opa_client.opa import OpaClient
131
131
132
132
client = OpaClient()
@@ -138,12 +138,10 @@ client.get_policies_list() # response is []
138
138
del client
139
139
```
140
140
141
- ### Get raw data from OPA service ###
141
+ ### Get raw data from OPA service
142
142
143
143
144
144
``` python
145
-
146
-
147
145
from opa_client.opa import OpaClient
148
146
149
147
client = OpaClient()
@@ -164,12 +162,11 @@ print(client.get_opa_raw_data("userinfo",query_params={"metrics": True}))
164
162
del client
165
163
```
166
164
167
- ### Save policy to file from OPA service ###
168
-
169
165
170
- ``` python
166
+ ### Save policy to file from OPA service
171
167
172
168
169
+ ``` python
173
170
from opa_client.opa import OpaClient
174
171
175
172
client = OpaClient()
@@ -179,12 +176,11 @@ client.opa_policy_to_file(policy_name="fromurl",path="/your/path",filename="exam
179
176
del client
180
177
```
181
178
182
- ### Delete data from OPA service ###
183
-
184
179
185
- ``` python
180
+ ### Delete data from OPA service
186
181
187
182
183
+ ``` python
188
184
from opa_client.opa import OpaClient
189
185
190
186
client = OpaClient()
@@ -195,12 +191,10 @@ del client
195
191
```
196
192
197
193
198
- ### Information about policy path and rules ###
194
+ ### Information about policy path and rules
199
195
200
196
201
197
``` python
202
-
203
-
204
198
from opa_client.opa import OpaClient
205
199
206
200
client = OpaClient()
@@ -213,12 +207,10 @@ del client
213
207
```
214
208
215
209
216
- ### Check permissions ###
210
+ ### Check permissions
217
211
218
212
219
213
``` python
220
-
221
-
222
214
from opa_client.opa import OpaClient
223
215
224
216
client = OpaClient()
@@ -255,7 +247,6 @@ hello {
255
247
256
248
check_data = {" message" : " world" }
257
249
client.check_policy_rule(input_data = check_data, package_path = " play" , rule_name = " hello" ) # response {'result': True}
258
-
259
250
```
260
251
261
252
### Execute an Ad-hoc Query
@@ -291,7 +282,6 @@ print(client.ad_hoc_query(query_params={"q": "data.userinfo.user_roles[name]"}))
291
282
# you can send body request
292
283
print (client.ad_hoc_query(body = {" query" : " data.userinfo.user_roles[name] " }))
293
284
# response is {'result': [{'name': 'eve'}, {'name': 'alice'}, {'name': 'bob'}]}
294
-
295
285
```
296
286
297
287
### Check OPA healthy. If you want check bundels or plugins, add query params for this.
@@ -306,12 +296,14 @@ print(client.check_health({"bundle": True})) # response is True or False
306
296
# If your diagnostic url different than default url, you can provide it.
307
297
print (client.check_health(diagnostic_url = " http://localhost:8282/health" )) # response is True or False
308
298
print (client.check_health(query = {" bundle" : True }, diagnostic_url = " http://localhost:8282/health" )) # response is True or False
309
-
310
299
```
311
300
312
301
313
- # Contributing #
302
+ # Contributing
303
+
304
+ Fell free to open issue and send pull request.
314
305
315
- #### 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!
316
308
317
- ### 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 )
0 commit comments