argus-api-client 0.8.0__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {argus_api_client-0.8.0/src/argus_api_client.egg-info → argus_api_client-0.9.0}/PKG-INFO +90 -6
- argus_api_client-0.8.0/PKG-INFO → argus_api_client-0.9.0/README.md +83 -21
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/pyproject.toml +19 -4
- argus_api_client-0.8.0/README.md → argus_api_client-0.9.0/src/argus_api_client.egg-info/PKG-INFO +105 -2
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/pyargus/__init__.py +1 -1
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/pyargus/api.py +48 -5
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/pyargus/async_api.py +20 -5
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/pyargus/async_client.py +68 -10
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/pyargus/client.py +66 -10
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/pyargus/models.py +27 -4
- argus_api_client-0.9.0/tests/test_async_client.py +235 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/tests/test_client.py +110 -1
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/tests/test_models.py +58 -1
- argus_api_client-0.8.0/tests/test_async_client.py +0 -110
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/LICENSE +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/setup.cfg +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/argus_api_client.egg-info/SOURCES.txt +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/argus_api_client.egg-info/dependency_links.txt +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/argus_api_client.egg-info/requires.txt +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/argus_api_client.egg-info/top_level.txt +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/pyargus/multivaluedict.py +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/src/pyargus/time.py +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/tests/test_api.py +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/tests/test_async_api.py +0 -0
- {argus_api_client-0.8.0 → argus_api_client-0.9.0}/tests/test_multivaluedict.py +0 -0
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: argus-api-client
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: A Python API client library for the Argus alert aggregator server
|
|
5
5
|
Author-email: Sikt - Kunnskapssektorens Tjenesteleverandør <kontakt@sikt.no>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: GitHub, https://github.com/Uninett/pyargus
|
|
8
|
+
Project-URL: Changelog, https://github.com/Uninett/pyargus/blob/master/CHANGELOG.md
|
|
9
|
+
Project-URL: Argus, https://network.geant.org/argus/
|
|
7
10
|
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
10
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
11
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
12
13
|
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
-
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Requires-Python: >=3.11
|
|
14
17
|
Description-Content-Type: text/markdown
|
|
15
18
|
License-File: LICENSE
|
|
16
19
|
Requires-Dist: simple_rest_client
|
|
@@ -215,13 +218,69 @@ If your argus server is running version 1.29.0 or newer you can request to get
|
|
|
215
218
|
a new token (with a new expiration date) via API version 2. The token you are
|
|
216
219
|
using to access the server with must still be valid.
|
|
217
220
|
|
|
221
|
+
There are two methods:
|
|
222
|
+
|
|
223
|
+
#### Use an existing, still valid token
|
|
224
|
+
|
|
225
|
+
You need to already have a token and client.
|
|
226
|
+
|
|
218
227
|
```python
|
|
219
228
|
tokenobj = c.refresh_token()
|
|
229
|
+
# stash away token...
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`c` will be using the freshly fetched token after this.
|
|
233
|
+
|
|
234
|
+
#### Use a username/password
|
|
235
|
+
|
|
236
|
+
To get the token and expiry for stashing away:
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from pyargus.client import login
|
|
240
|
+
|
|
241
|
+
tokenobj = login(
|
|
242
|
+
api_root_url="https://argus.example.org/api/v2",
|
|
243
|
+
username=username,
|
|
244
|
+
password=password,
|
|
245
|
+
)
|
|
246
|
+
# stash away token, then...
|
|
220
247
|
c = Client(api_root_url="https://argus.example.org/api/v2", token=tokenobj.token)
|
|
221
|
-
# save the contents of tokenobj in an environment variable, config file or
|
|
222
|
-
# secrets file so that it is not lost on program exit
|
|
223
248
|
```
|
|
224
249
|
|
|
250
|
+
To get a client directly, without opportunity to save the token:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from pyargus.client import Client
|
|
254
|
+
|
|
255
|
+
c = Client.login(
|
|
256
|
+
api_root_url="https://argus.example.org/api/v2",
|
|
257
|
+
username=username,
|
|
258
|
+
password=password,
|
|
259
|
+
)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Note that `login` is a class method here.
|
|
263
|
+
|
|
264
|
+
### Set a new token in an existing client
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from pyargus.client import Client
|
|
268
|
+
# get a client that works with public endpoints
|
|
269
|
+
c = Client(api_root_url="https://argus.example.org/api/v2")
|
|
270
|
+
|
|
271
|
+
# get a token as a string from somewhere;
|
|
272
|
+
# * environment variable
|
|
273
|
+
# * secrets file
|
|
274
|
+
# * config file
|
|
275
|
+
# * command line argument
|
|
276
|
+
token = get_token_my_way()
|
|
277
|
+
|
|
278
|
+
# set it, replacing an existing one
|
|
279
|
+
c.set_token(token)
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
`c` will be using the given token after this.
|
|
283
|
+
|
|
225
284
|
### Send a heartbeat
|
|
226
285
|
|
|
227
286
|
A source system with no incidents to report looks exactly like one that has
|
|
@@ -266,6 +325,31 @@ while running:
|
|
|
266
325
|
sleep(interval)
|
|
267
326
|
```
|
|
268
327
|
|
|
328
|
+
### Getting metadata about the server
|
|
329
|
+
|
|
330
|
+
This endpoint is public so it can be fetched without a token.
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
from pprint import pprint
|
|
334
|
+
|
|
335
|
+
from pyargus.client import Client
|
|
336
|
+
|
|
337
|
+
c = Client(api_root_url="https://argus.example.org/api/v2")
|
|
338
|
+
metadata = c.get_server_metadata()
|
|
339
|
+
pprint(vars(metadata))
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
… which yields a structure looking like this (actual versions may differ):
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
{'available_api_versions': {'v3', 'v2'},
|
|
346
|
+
'jsonapi_schema': {'stable': '/api/schema/',
|
|
347
|
+
'v2': '/api/v2/schema/',
|
|
348
|
+
'v3': '/api/v3/schema/'},
|
|
349
|
+
'server_version': '2.10.2',
|
|
350
|
+
'stable_api_version': 'v2'}
|
|
351
|
+
```
|
|
352
|
+
|
|
269
353
|
## Async usage
|
|
270
354
|
|
|
271
355
|
An `AsyncClient` is available for use in asyncio-based applications. It mirrors
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: argus-api-client
|
|
3
|
-
Version: 0.8.0
|
|
4
|
-
Summary: A Python API client library for the Argus alert aggregator server
|
|
5
|
-
Author-email: Sikt - Kunnskapssektorens Tjenesteleverandør <kontakt@sikt.no>
|
|
6
|
-
License-Expression: Apache-2.0
|
|
7
|
-
Classifier: Programming Language :: Python :: 3
|
|
8
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
9
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
10
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
-
Requires-Python: >=3.9
|
|
14
|
-
Description-Content-Type: text/markdown
|
|
15
|
-
License-File: LICENSE
|
|
16
|
-
Requires-Dist: simple_rest_client
|
|
17
|
-
Requires-Dist: iso8601
|
|
18
|
-
Dynamic: license-file
|
|
19
|
-
|
|
20
1
|
# Argus API Client
|
|
21
2
|
[](https://github.com/Uninett/pyargus/actions)
|
|
22
3
|
[](https://github.com/astral-sh/ruff)
|
|
@@ -215,13 +196,69 @@ If your argus server is running version 1.29.0 or newer you can request to get
|
|
|
215
196
|
a new token (with a new expiration date) via API version 2. The token you are
|
|
216
197
|
using to access the server with must still be valid.
|
|
217
198
|
|
|
199
|
+
There are two methods:
|
|
200
|
+
|
|
201
|
+
#### Use an existing, still valid token
|
|
202
|
+
|
|
203
|
+
You need to already have a token and client.
|
|
204
|
+
|
|
218
205
|
```python
|
|
219
206
|
tokenobj = c.refresh_token()
|
|
207
|
+
# stash away token...
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`c` will be using the freshly fetched token after this.
|
|
211
|
+
|
|
212
|
+
#### Use a username/password
|
|
213
|
+
|
|
214
|
+
To get the token and expiry for stashing away:
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
from pyargus.client import login
|
|
218
|
+
|
|
219
|
+
tokenobj = login(
|
|
220
|
+
api_root_url="https://argus.example.org/api/v2",
|
|
221
|
+
username=username,
|
|
222
|
+
password=password,
|
|
223
|
+
)
|
|
224
|
+
# stash away token, then...
|
|
220
225
|
c = Client(api_root_url="https://argus.example.org/api/v2", token=tokenobj.token)
|
|
221
|
-
# save the contents of tokenobj in an environment variable, config file or
|
|
222
|
-
# secrets file so that it is not lost on program exit
|
|
223
226
|
```
|
|
224
227
|
|
|
228
|
+
To get a client directly, without opportunity to save the token:
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from pyargus.client import Client
|
|
232
|
+
|
|
233
|
+
c = Client.login(
|
|
234
|
+
api_root_url="https://argus.example.org/api/v2",
|
|
235
|
+
username=username,
|
|
236
|
+
password=password,
|
|
237
|
+
)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Note that `login` is a class method here.
|
|
241
|
+
|
|
242
|
+
### Set a new token in an existing client
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
from pyargus.client import Client
|
|
246
|
+
# get a client that works with public endpoints
|
|
247
|
+
c = Client(api_root_url="https://argus.example.org/api/v2")
|
|
248
|
+
|
|
249
|
+
# get a token as a string from somewhere;
|
|
250
|
+
# * environment variable
|
|
251
|
+
# * secrets file
|
|
252
|
+
# * config file
|
|
253
|
+
# * command line argument
|
|
254
|
+
token = get_token_my_way()
|
|
255
|
+
|
|
256
|
+
# set it, replacing an existing one
|
|
257
|
+
c.set_token(token)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
`c` will be using the given token after this.
|
|
261
|
+
|
|
225
262
|
### Send a heartbeat
|
|
226
263
|
|
|
227
264
|
A source system with no incidents to report looks exactly like one that has
|
|
@@ -266,6 +303,31 @@ while running:
|
|
|
266
303
|
sleep(interval)
|
|
267
304
|
```
|
|
268
305
|
|
|
306
|
+
### Getting metadata about the server
|
|
307
|
+
|
|
308
|
+
This endpoint is public so it can be fetched without a token.
|
|
309
|
+
|
|
310
|
+
```python
|
|
311
|
+
from pprint import pprint
|
|
312
|
+
|
|
313
|
+
from pyargus.client import Client
|
|
314
|
+
|
|
315
|
+
c = Client(api_root_url="https://argus.example.org/api/v2")
|
|
316
|
+
metadata = c.get_server_metadata()
|
|
317
|
+
pprint(vars(metadata))
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
… which yields a structure looking like this (actual versions may differ):
|
|
321
|
+
|
|
322
|
+
```python
|
|
323
|
+
{'available_api_versions': {'v3', 'v2'},
|
|
324
|
+
'jsonapi_schema': {'stable': '/api/schema/',
|
|
325
|
+
'v2': '/api/v2/schema/',
|
|
326
|
+
'v3': '/api/v3/schema/'},
|
|
327
|
+
'server_version': '2.10.2',
|
|
328
|
+
'stable_api_version': 'v2'}
|
|
329
|
+
```
|
|
330
|
+
|
|
269
331
|
## Async usage
|
|
270
332
|
|
|
271
333
|
An `AsyncClient` is available for use in asyncio-based applications. It mirrors
|
|
@@ -8,28 +8,33 @@ dynamic = ["version"]
|
|
|
8
8
|
description = "A Python API client library for the Argus alert aggregator server"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [{name="Sikt - Kunnskapssektorens Tjenesteleverandør", email="kontakt@sikt.no"}]
|
|
11
|
-
requires-python = ">=3.
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
12
|
license = "Apache-2.0"
|
|
13
13
|
license-files = ["LICENSE"]
|
|
14
14
|
classifiers = [
|
|
15
15
|
"Programming Language :: Python :: 3",
|
|
16
|
-
"Programming Language :: Python :: 3.9",
|
|
17
|
-
"Programming Language :: Python :: 3.10",
|
|
18
16
|
"Programming Language :: Python :: 3.11",
|
|
19
17
|
"Programming Language :: Python :: 3.12",
|
|
20
18
|
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Programming Language :: Python :: 3.15",
|
|
21
21
|
]
|
|
22
22
|
dependencies = [
|
|
23
23
|
"simple_rest_client",
|
|
24
24
|
"iso8601",
|
|
25
25
|
]
|
|
26
26
|
|
|
27
|
+
[project.urls]
|
|
28
|
+
GitHub = "https://github.com/Uninett/pyargus"
|
|
29
|
+
Changelog = "https://github.com/Uninett/pyargus/blob/master/CHANGELOG.md"
|
|
30
|
+
Argus = "https://network.geant.org/argus/"
|
|
31
|
+
|
|
27
32
|
[dependency-groups]
|
|
28
33
|
test = [
|
|
29
34
|
"pytest",
|
|
30
35
|
"pytest-asyncio",
|
|
31
36
|
"pytest-cov",
|
|
32
|
-
"pytest-argus-server>=0.
|
|
37
|
+
"pytest-argus-server>=0.4.0",
|
|
33
38
|
]
|
|
34
39
|
dev = [
|
|
35
40
|
"build",
|
|
@@ -49,6 +54,16 @@ version = {attr = "pyargus.VERSION"}
|
|
|
49
54
|
where = ["src"]
|
|
50
55
|
exclude = ["tests*"]
|
|
51
56
|
|
|
57
|
+
[tool.pytest.ini_options]
|
|
58
|
+
# Pin the Argus server image used by the integration tests: argus:latest (and
|
|
59
|
+
# the identical 2.10.0 tag, rebuilt 2026-08-31) dies at Django setup with
|
|
60
|
+
# "ModuleNotFoundError: No module named 'django_tasks'", since Argus lists
|
|
61
|
+
# django_tasks in INSTALLED_APPS while django-tasks-db 0.13.0 demoted
|
|
62
|
+
# django-tasks to an optional "compat" extra. 2.9.1 still bundles it.
|
|
63
|
+
# TODO: Drop this pin once a fixed Argus image is published
|
|
64
|
+
addopts = "--argus-version 2.9.1"
|
|
65
|
+
filterwarnings = ["error::RuntimeWarning", "error::pytest.PytestUnraisableExceptionWarning"]
|
|
66
|
+
|
|
52
67
|
[tool.ruff]
|
|
53
68
|
line-length = 88
|
|
54
69
|
extend-exclude = [
|
argus_api_client-0.8.0/README.md → argus_api_client-0.9.0/src/argus_api_client.egg-info/PKG-INFO
RENAMED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: argus-api-client
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: A Python API client library for the Argus alert aggregator server
|
|
5
|
+
Author-email: Sikt - Kunnskapssektorens Tjenesteleverandør <kontakt@sikt.no>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: GitHub, https://github.com/Uninett/pyargus
|
|
8
|
+
Project-URL: Changelog, https://github.com/Uninett/pyargus/blob/master/CHANGELOG.md
|
|
9
|
+
Project-URL: Argus, https://network.geant.org/argus/
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: simple_rest_client
|
|
20
|
+
Requires-Dist: iso8601
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
1
23
|
# Argus API Client
|
|
2
24
|
[](https://github.com/Uninett/pyargus/actions)
|
|
3
25
|
[](https://github.com/astral-sh/ruff)
|
|
@@ -196,13 +218,69 @@ If your argus server is running version 1.29.0 or newer you can request to get
|
|
|
196
218
|
a new token (with a new expiration date) via API version 2. The token you are
|
|
197
219
|
using to access the server with must still be valid.
|
|
198
220
|
|
|
221
|
+
There are two methods:
|
|
222
|
+
|
|
223
|
+
#### Use an existing, still valid token
|
|
224
|
+
|
|
225
|
+
You need to already have a token and client.
|
|
226
|
+
|
|
199
227
|
```python
|
|
200
228
|
tokenobj = c.refresh_token()
|
|
229
|
+
# stash away token...
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
`c` will be using the freshly fetched token after this.
|
|
233
|
+
|
|
234
|
+
#### Use a username/password
|
|
235
|
+
|
|
236
|
+
To get the token and expiry for stashing away:
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from pyargus.client import login
|
|
240
|
+
|
|
241
|
+
tokenobj = login(
|
|
242
|
+
api_root_url="https://argus.example.org/api/v2",
|
|
243
|
+
username=username,
|
|
244
|
+
password=password,
|
|
245
|
+
)
|
|
246
|
+
# stash away token, then...
|
|
201
247
|
c = Client(api_root_url="https://argus.example.org/api/v2", token=tokenobj.token)
|
|
202
|
-
# save the contents of tokenobj in an environment variable, config file or
|
|
203
|
-
# secrets file so that it is not lost on program exit
|
|
204
248
|
```
|
|
205
249
|
|
|
250
|
+
To get a client directly, without opportunity to save the token:
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from pyargus.client import Client
|
|
254
|
+
|
|
255
|
+
c = Client.login(
|
|
256
|
+
api_root_url="https://argus.example.org/api/v2",
|
|
257
|
+
username=username,
|
|
258
|
+
password=password,
|
|
259
|
+
)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Note that `login` is a class method here.
|
|
263
|
+
|
|
264
|
+
### Set a new token in an existing client
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from pyargus.client import Client
|
|
268
|
+
# get a client that works with public endpoints
|
|
269
|
+
c = Client(api_root_url="https://argus.example.org/api/v2")
|
|
270
|
+
|
|
271
|
+
# get a token as a string from somewhere;
|
|
272
|
+
# * environment variable
|
|
273
|
+
# * secrets file
|
|
274
|
+
# * config file
|
|
275
|
+
# * command line argument
|
|
276
|
+
token = get_token_my_way()
|
|
277
|
+
|
|
278
|
+
# set it, replacing an existing one
|
|
279
|
+
c.set_token(token)
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
`c` will be using the given token after this.
|
|
283
|
+
|
|
206
284
|
### Send a heartbeat
|
|
207
285
|
|
|
208
286
|
A source system with no incidents to report looks exactly like one that has
|
|
@@ -247,6 +325,31 @@ while running:
|
|
|
247
325
|
sleep(interval)
|
|
248
326
|
```
|
|
249
327
|
|
|
328
|
+
### Getting metadata about the server
|
|
329
|
+
|
|
330
|
+
This endpoint is public so it can be fetched without a token.
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
from pprint import pprint
|
|
334
|
+
|
|
335
|
+
from pyargus.client import Client
|
|
336
|
+
|
|
337
|
+
c = Client(api_root_url="https://argus.example.org/api/v2")
|
|
338
|
+
metadata = c.get_server_metadata()
|
|
339
|
+
pprint(vars(metadata))
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
… which yields a structure looking like this (actual versions may differ):
|
|
343
|
+
|
|
344
|
+
```python
|
|
345
|
+
{'available_api_versions': {'v3', 'v2'},
|
|
346
|
+
'jsonapi_schema': {'stable': '/api/schema/',
|
|
347
|
+
'v2': '/api/v2/schema/',
|
|
348
|
+
'v3': '/api/v3/schema/'},
|
|
349
|
+
'server_version': '2.10.2',
|
|
350
|
+
'stable_api_version': 'v2'}
|
|
351
|
+
```
|
|
352
|
+
|
|
250
353
|
## Async usage
|
|
251
354
|
|
|
252
355
|
An `AsyncClient` is available for use in asyncio-based applications. It mirrors
|
|
@@ -1,21 +1,31 @@
|
|
|
1
1
|
"""Defines a low-level API interface for Argus using simple_rest_client"""
|
|
2
2
|
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from urllib.parse import urljoin
|
|
5
|
+
|
|
3
6
|
from simple_rest_client.api import API
|
|
4
7
|
from simple_rest_client.resource import Resource
|
|
5
8
|
|
|
9
|
+
DEFAULT_TIMEOUT = 2.0
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def server_root_url(api_root_url: str) -> str:
|
|
13
|
+
"""Returns the URL one level above the versioned API root"""
|
|
14
|
+
return urljoin(api_root_url.rstrip("/") + "/", "..")
|
|
15
|
+
|
|
6
16
|
|
|
7
|
-
def connect(
|
|
17
|
+
def connect(
|
|
18
|
+
api_root_url: str, token: Optional[str] = None, timeout: float = DEFAULT_TIMEOUT
|
|
19
|
+
) -> API:
|
|
8
20
|
"""Connects to an Argus API instance.
|
|
9
21
|
|
|
10
22
|
:returns: A connected simple_rest_client API object
|
|
11
23
|
"""
|
|
12
|
-
headers = {"Authorization": "Token " + token}
|
|
13
|
-
argusapi =
|
|
24
|
+
headers = {"Authorization": "Token " + token} if token else None
|
|
25
|
+
argusapi = configure_api_object(
|
|
14
26
|
api_root_url=api_root_url,
|
|
15
27
|
headers=headers,
|
|
16
28
|
timeout=timeout,
|
|
17
|
-
json_encode_body=True,
|
|
18
|
-
append_slash=True,
|
|
19
29
|
)
|
|
20
30
|
argusapi.add_resource(resource_name="incidents", resource_class=IncidentResource)
|
|
21
31
|
argusapi.add_resource(resource_name="events", resource_class=IncidentEventResource)
|
|
@@ -24,9 +34,32 @@ def connect(api_root_url: str, token: str, timeout: float = 2.0) -> API:
|
|
|
24
34
|
)
|
|
25
35
|
argusapi.add_resource(resource_name="sources", resource_class=SourceSystemResource)
|
|
26
36
|
argusapi.add_resource(resource_name="tokens", resource_class=ExpiringTokenResource)
|
|
37
|
+
argusapi.add_resource(
|
|
38
|
+
resource_name="metadata",
|
|
39
|
+
resource_class=ServerMetadataResource,
|
|
40
|
+
api_root_url=server_root_url(api_root_url),
|
|
41
|
+
)
|
|
27
42
|
return argusapi
|
|
28
43
|
|
|
29
44
|
|
|
45
|
+
def configure_api_object(
|
|
46
|
+
api_root_url: str,
|
|
47
|
+
headers: dict | None = None,
|
|
48
|
+
timeout: float = DEFAULT_TIMEOUT,
|
|
49
|
+
json_encode_body: bool = True,
|
|
50
|
+
append_slash: bool = True,
|
|
51
|
+
):
|
|
52
|
+
if headers is None:
|
|
53
|
+
headers = {}
|
|
54
|
+
return API(
|
|
55
|
+
api_root_url=api_root_url,
|
|
56
|
+
headers=headers,
|
|
57
|
+
timeout=timeout,
|
|
58
|
+
json_encode_body=json_encode_body,
|
|
59
|
+
append_slash=append_slash,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
30
63
|
class IncidentResource(Resource):
|
|
31
64
|
actions = {
|
|
32
65
|
"list": {"method": "GET", "url": "incidents"},
|
|
@@ -70,5 +103,15 @@ class SourceSystemResource(Resource):
|
|
|
70
103
|
|
|
71
104
|
class ExpiringTokenResource(Resource):
|
|
72
105
|
actions = {
|
|
106
|
+
# When accessed with a token, takes an empty JSON body or nothing
|
|
73
107
|
"refresh": {"method": "POST", "url": "auth/token/login/"},
|
|
108
|
+
# When accessed without a token, takes a JSON body with username/password:
|
|
109
|
+
# { "username": "somestring", "password": "someothernonencryptedstring" }
|
|
110
|
+
"login": {"method": "POST", "url": "auth/token/login/"},
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class ServerMetadataResource(Resource):
|
|
115
|
+
actions = {
|
|
116
|
+
"metadata": {"method": "GET", "url": ""},
|
|
74
117
|
}
|
|
@@ -1,29 +1,35 @@
|
|
|
1
1
|
"""Defines an async low-level API interface for Argus using simple_rest_client"""
|
|
2
2
|
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
3
5
|
from simple_rest_client.api import API
|
|
4
6
|
from simple_rest_client.resource import AsyncResource
|
|
5
7
|
|
|
6
8
|
from .api import (
|
|
9
|
+
DEFAULT_TIMEOUT,
|
|
7
10
|
ExpiringTokenResource,
|
|
8
11
|
IncidentAcknowledgementResource,
|
|
9
12
|
IncidentEventResource,
|
|
10
13
|
IncidentResource,
|
|
14
|
+
ServerMetadataResource,
|
|
11
15
|
SourceSystemResource,
|
|
16
|
+
configure_api_object,
|
|
17
|
+
server_root_url,
|
|
12
18
|
)
|
|
13
19
|
|
|
14
20
|
|
|
15
|
-
def async_connect(
|
|
21
|
+
def async_connect(
|
|
22
|
+
api_root_url: str, token: Optional[str] = None, timeout: float = DEFAULT_TIMEOUT
|
|
23
|
+
) -> API:
|
|
16
24
|
"""Connects to an Argus API instance using async resources.
|
|
17
25
|
|
|
18
26
|
:returns: A connected simple_rest_client API object with async resources
|
|
19
27
|
"""
|
|
20
|
-
headers = {"Authorization": "Token " + token}
|
|
21
|
-
argusapi =
|
|
28
|
+
headers = {"Authorization": "Token " + token} if token else None
|
|
29
|
+
argusapi = configure_api_object(
|
|
22
30
|
api_root_url=api_root_url,
|
|
23
31
|
headers=headers,
|
|
24
32
|
timeout=timeout,
|
|
25
|
-
json_encode_body=True,
|
|
26
|
-
append_slash=True,
|
|
27
33
|
)
|
|
28
34
|
argusapi.add_resource(
|
|
29
35
|
resource_name="incidents", resource_class=AsyncIncidentResource
|
|
@@ -41,6 +47,11 @@ def async_connect(api_root_url: str, token: str, timeout: float = 2.0) -> API:
|
|
|
41
47
|
argusapi.add_resource(
|
|
42
48
|
resource_name="tokens", resource_class=AsyncExpiringTokenResource
|
|
43
49
|
)
|
|
50
|
+
argusapi.add_resource(
|
|
51
|
+
resource_name="metadata",
|
|
52
|
+
resource_class=AsyncServerMetadataResource,
|
|
53
|
+
api_root_url=server_root_url(api_root_url),
|
|
54
|
+
)
|
|
44
55
|
return argusapi
|
|
45
56
|
|
|
46
57
|
|
|
@@ -62,3 +73,7 @@ class AsyncSourceSystemResource(AsyncResource):
|
|
|
62
73
|
|
|
63
74
|
class AsyncExpiringTokenResource(AsyncResource):
|
|
64
75
|
actions = ExpiringTokenResource.actions
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class AsyncServerMetadataResource(AsyncResource):
|
|
79
|
+
actions = ServerMetadataResource.actions
|