pypuppetdb 3.1.0__tar.gz → 4.0.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.
- pypuppetdb-4.0.0/PKG-INFO +83 -0
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/README.md +11 -0
- pypuppetdb-4.0.0/pyproject.toml +58 -0
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/QueryBuilder.py +134 -94
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/__init__.py +27 -10
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/api/base.py +153 -112
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/api/command.py +39 -28
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/api/metadata.py +2 -5
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/api/metrics.py +16 -16
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/api/pql.py +29 -20
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/api/query.py +57 -39
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/api/status.py +1 -4
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/errors.py +4 -0
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/types.py +303 -228
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/utils.py +7 -9
- pypuppetdb-3.1.0/CHANGELOG.md +0 -359
- pypuppetdb-3.1.0/MANIFEST.in +0 -5
- pypuppetdb-3.1.0/PKG-INFO +0 -432
- pypuppetdb-3.1.0/pypuppetdb.egg-info/PKG-INFO +0 -432
- pypuppetdb-3.1.0/pypuppetdb.egg-info/SOURCES.txt +0 -27
- pypuppetdb-3.1.0/pypuppetdb.egg-info/dependency_links.txt +0 -1
- pypuppetdb-3.1.0/pypuppetdb.egg-info/requires.txt +0 -1
- pypuppetdb-3.1.0/pypuppetdb.egg-info/top_level.txt +0 -1
- pypuppetdb-3.1.0/requirements-test.txt +0 -20
- pypuppetdb-3.1.0/requirements.txt +0 -1
- pypuppetdb-3.1.0/setup.cfg +0 -16
- pypuppetdb-3.1.0/setup.py +0 -75
- pypuppetdb-3.1.0/version +0 -1
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/LICENSE +0 -0
- {pypuppetdb-3.1.0 → pypuppetdb-4.0.0}/pypuppetdb/api/__init__.py +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pypuppetdb
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: Library for working with the PuppetDB REST API.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: puppet,puppetdb
|
|
8
|
+
Author: Vox Pupuli
|
|
9
|
+
Author-email: voxpupuli@groups.io
|
|
10
|
+
Requires-Python: >=3.12,<4.0
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Operating System :: POSIX
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Requires-Dist: requests (>=2.28.1,<3.0.0)
|
|
22
|
+
Project-URL: Repository, https://github.com/voxpupuli/pypuppetdb
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# pypuppetdb
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/pypuppetdb/)
|
|
28
|
+
[](https://pypi.org/project/pypuppetdb/)
|
|
29
|
+
[](https://pypi.org/project/pypuppetdb/)
|
|
30
|
+
/badge.svg)
|
|
31
|
+
[](https://codecov.io/gh/voxpupuli/pypuppetdb)
|
|
32
|
+
[](https://pypuppetdb.readthedocs.io/en/latest/?badge=latest)
|
|
33
|
+
[](https://voxpupuli.org)
|
|
34
|
+
|
|
35
|
+
This library is a thin wrapper around the REST API providing some
|
|
36
|
+
convenience functions and objects to request and hold data from
|
|
37
|
+
PuppetDB.
|
|
38
|
+
|
|
39
|
+
## Requirements
|
|
40
|
+
|
|
41
|
+
* PuppetDB 5.2 or newer
|
|
42
|
+
* Python 3.7-3.11
|
|
43
|
+
|
|
44
|
+
(For support of the older PuppetDB or Python versions please check previous library version.)
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
You can install this package from PyPI with:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install pypuppetdb
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Documentation
|
|
55
|
+
|
|
56
|
+
The [user guide, API reference and a developer guide is available on Read the Docs](https://pypuppetdb.readthedocs.io/en/latest/).
|
|
57
|
+
|
|
58
|
+
## Getting Help
|
|
59
|
+
|
|
60
|
+
For bug reports you can file an
|
|
61
|
+
[issue](https://github.com/voxpupuli/pypuppetdb/issues). If you need
|
|
62
|
+
help with something feel free to pop by \#voxpupuli or the \#puppetboard on
|
|
63
|
+
[Freenode](https://freenode.net) or [Vox Pupuli on Slack](https://puppetcommunity.slack.com/messages/voxpupuli/).
|
|
64
|
+
|
|
65
|
+
## Contributing
|
|
66
|
+
|
|
67
|
+
Please see the [contribution guide here](https://github.com/voxpupuli/pypuppetdb/blob/master/CONTRIBUTING.md).
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
This project is licensed under the [Apache v2.0 License](https://github.com/voxpupuli/pypuppetdb/blob/master/LICENSE).
|
|
72
|
+
|
|
73
|
+
## Making a new release
|
|
74
|
+
|
|
75
|
+
* set a GitHub token as environment variable: `export CHANGELOG_GITHUB_TOKEN=github_pat_...`
|
|
76
|
+
* Install changelog generator dependencies: `bundle config set --local with release; bundle install; bundle update`
|
|
77
|
+
* Set a new version in `pyproject.toml`
|
|
78
|
+
* run `bundle exec rake changelog`
|
|
79
|
+
* Read the diff in CHANGELOG.md, maybe adjust the version and run the generator again, open a PR
|
|
80
|
+
* Get a review, merge it
|
|
81
|
+
* Create a matching tag for the new version, with a leading `v`, push the tag
|
|
82
|
+
* CI will publish to pypi and to Dockerhub
|
|
83
|
+
|
|
@@ -45,3 +45,14 @@ Please see the [contribution guide here](https://github.com/voxpupuli/pypuppetdb
|
|
|
45
45
|
## License
|
|
46
46
|
|
|
47
47
|
This project is licensed under the [Apache v2.0 License](https://github.com/voxpupuli/pypuppetdb/blob/master/LICENSE).
|
|
48
|
+
|
|
49
|
+
## Making a new release
|
|
50
|
+
|
|
51
|
+
* set a GitHub token as environment variable: `export CHANGELOG_GITHUB_TOKEN=github_pat_...`
|
|
52
|
+
* Install changelog generator dependencies: `bundle config set --local with release; bundle install; bundle update`
|
|
53
|
+
* Set a new version in `pyproject.toml`
|
|
54
|
+
* run `bundle exec rake changelog`
|
|
55
|
+
* Read the diff in CHANGELOG.md, maybe adjust the version and run the generator again, open a PR
|
|
56
|
+
* Get a review, merge it
|
|
57
|
+
* Create a matching tag for the new version, with a leading `v`, push the tag
|
|
58
|
+
* CI will publish to pypi and to Dockerhub
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "pypuppetdb"
|
|
3
|
+
version = "4.0.0"
|
|
4
|
+
description = "Library for working with the PuppetDB REST API."
|
|
5
|
+
authors = ["Vox Pupuli <voxpupuli@groups.io>"]
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "https://github.com/voxpupuli/pypuppetdb"
|
|
9
|
+
keywords = ["puppet", "puppetdb"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 5 - Production/Stable",
|
|
12
|
+
"Intended Audience :: Developers",
|
|
13
|
+
"Natural Language :: English",
|
|
14
|
+
"Operating System :: POSIX",
|
|
15
|
+
"Topic :: Software Development :: Libraries",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[tool.poetry.dependencies]
|
|
19
|
+
python = "^3.12"
|
|
20
|
+
requests = "^2.28.1"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
[tool.poetry.group.test.dependencies]
|
|
24
|
+
bandit = "^1.8.0"
|
|
25
|
+
coverage = "^7.6.9"
|
|
26
|
+
flake8 = "^7.1.1"
|
|
27
|
+
pytest = ">=8.3.4,<10.0.0"
|
|
28
|
+
pytest-cov = ">=6,<8"
|
|
29
|
+
pytest-flake8 = "^1.3.0"
|
|
30
|
+
pytest-mypy = ">=0.10.3,<1.2.0"
|
|
31
|
+
mypy = ">=1.13,<3.0"
|
|
32
|
+
cov-core = "^1.15.0"
|
|
33
|
+
httpretty = "^1.1.4"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
[tool.poetry.group.docs.dependencies]
|
|
37
|
+
alabaster = "^0.7"
|
|
38
|
+
babel = "^2.16.0"
|
|
39
|
+
certifi = ">=2024.8.30,<2027.0.0"
|
|
40
|
+
requests = "^2.32.3"
|
|
41
|
+
sphinx = ">=7,<10"
|
|
42
|
+
sphinx-rtd-theme = "^3.0.2"
|
|
43
|
+
sphinxcontrib-applehelp = "^2.0.0"
|
|
44
|
+
sphinxcontrib-devhelp = "^2.0.0"
|
|
45
|
+
sphinxcontrib-htmlhelp = "^2.1.0"
|
|
46
|
+
sphinxcontrib-jsmath = ">=1.0.1,<3.0.0"
|
|
47
|
+
sphinxcontrib-qthelp = "^2.0.0"
|
|
48
|
+
sphinxcontrib-serializinghtml = "^2.0.0"
|
|
49
|
+
pytz = ">=2024.2,<2027.0"
|
|
50
|
+
pyparsing = "^3.2.0"
|
|
51
|
+
pygments = "^2.18.0"
|
|
52
|
+
idna = "^3.10"
|
|
53
|
+
docutils = "^0.21.2"
|
|
54
|
+
snowballstemmer = ">=2.2,<4.0"
|
|
55
|
+
|
|
56
|
+
[build-system]
|
|
57
|
+
requires = ["poetry-core"]
|
|
58
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
from __future__ import absolute_import
|
|
2
|
-
from __future__ import unicode_literals
|
|
3
|
-
|
|
4
1
|
import datetime
|
|
5
2
|
import json
|
|
6
3
|
import logging
|
|
@@ -10,7 +7,7 @@ from pypuppetdb.errors import APIError
|
|
|
10
7
|
log = logging.getLogger(__name__)
|
|
11
8
|
|
|
12
9
|
|
|
13
|
-
class BinaryOperator
|
|
10
|
+
class BinaryOperator:
|
|
14
11
|
"""
|
|
15
12
|
This is a parent helper class used to create PuppetDB AST queries
|
|
16
13
|
for single key-value pairs for the available operators.
|
|
@@ -42,7 +39,7 @@ class BinaryOperator(object):
|
|
|
42
39
|
self.data = [operator, field, value]
|
|
43
40
|
|
|
44
41
|
def __repr__(self):
|
|
45
|
-
return
|
|
42
|
+
return f"Query: {self}"
|
|
46
43
|
|
|
47
44
|
def __str__(self):
|
|
48
45
|
return json.dumps(self.json_data())
|
|
@@ -51,7 +48,7 @@ class BinaryOperator(object):
|
|
|
51
48
|
return self.data
|
|
52
49
|
|
|
53
50
|
|
|
54
|
-
class BooleanOperator
|
|
51
|
+
class BooleanOperator:
|
|
55
52
|
"""
|
|
56
53
|
This is a parent helper class used to create PuppetDB AST queries
|
|
57
54
|
for available boolean queries.
|
|
@@ -74,20 +71,20 @@ class BooleanOperator(object):
|
|
|
74
71
|
self.operations = []
|
|
75
72
|
|
|
76
73
|
def add(self, query):
|
|
77
|
-
if
|
|
74
|
+
if isinstance(query, list):
|
|
78
75
|
for i in query:
|
|
79
76
|
self.add(i)
|
|
80
|
-
elif
|
|
77
|
+
elif isinstance(query, str):
|
|
81
78
|
self.operations.append(json.loads(query))
|
|
82
|
-
elif isinstance(query, (BinaryOperator, InOperator,
|
|
83
|
-
BooleanOperator)):
|
|
79
|
+
elif isinstance(query, (BinaryOperator, InOperator, BooleanOperator)):
|
|
84
80
|
self.operations.append(query.json_data())
|
|
85
81
|
else:
|
|
86
|
-
raise APIError(
|
|
87
|
-
|
|
82
|
+
raise APIError(
|
|
83
|
+
"Can only accept fixed-string queries, arrays " + "or operator objects"
|
|
84
|
+
)
|
|
88
85
|
|
|
89
86
|
def __repr__(self):
|
|
90
|
-
return
|
|
87
|
+
return f"Query: {self}"
|
|
91
88
|
|
|
92
89
|
def __str__(self):
|
|
93
90
|
return json.dumps(self.json_data())
|
|
@@ -98,7 +95,7 @@ class BooleanOperator(object):
|
|
|
98
95
|
return [self.operator] + self.operations
|
|
99
96
|
|
|
100
97
|
|
|
101
|
-
class ExtractOperator
|
|
98
|
+
class ExtractOperator:
|
|
102
99
|
"""
|
|
103
100
|
Queries that either do not or cannot require all the key-value pairs
|
|
104
101
|
from an endpoint can use the Extract Operator as described in
|
|
@@ -123,21 +120,23 @@ class ExtractOperator(object):
|
|
|
123
120
|
elif isinstance(field, FunctionOperator):
|
|
124
121
|
self.fields.append(field.json_data())
|
|
125
122
|
else:
|
|
126
|
-
raise APIError(
|
|
127
|
-
|
|
123
|
+
raise APIError(
|
|
124
|
+
"ExtractOperator.add_field only supports " "lists and strings"
|
|
125
|
+
)
|
|
128
126
|
|
|
129
127
|
def add_query(self, query):
|
|
130
128
|
if self.query is not None:
|
|
131
129
|
raise APIError("Only one query is supported by ExtractOperator")
|
|
132
130
|
elif isinstance(query, str):
|
|
133
131
|
self.query = json.loads(query)
|
|
134
|
-
elif isinstance(query, (BinaryOperator, SubqueryOperator,
|
|
135
|
-
BooleanOperator)):
|
|
132
|
+
elif isinstance(query, (BinaryOperator, SubqueryOperator, BooleanOperator)):
|
|
136
133
|
self.query = query.json_data()
|
|
137
134
|
else:
|
|
138
|
-
raise APIError(
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
raise APIError(
|
|
136
|
+
"ExtractOperator.add_query only supports "
|
|
137
|
+
"strings, BinaryOperator, BooleanOperator "
|
|
138
|
+
"and SubqueryOperator objects"
|
|
139
|
+
)
|
|
141
140
|
|
|
142
141
|
def add_group_by(self, field):
|
|
143
142
|
if isinstance(field, list):
|
|
@@ -145,18 +144,20 @@ class ExtractOperator(object):
|
|
|
145
144
|
self.add_group_by(i)
|
|
146
145
|
elif isinstance(field, str):
|
|
147
146
|
if len(self.group_by) == 0:
|
|
148
|
-
self.group_by.append(
|
|
147
|
+
self.group_by.append("group_by")
|
|
149
148
|
self.group_by.append(field)
|
|
150
149
|
elif isinstance(field, FunctionOperator):
|
|
151
150
|
if len(self.group_by) == 0:
|
|
152
|
-
self.group_by.append(
|
|
151
|
+
self.group_by.append("group_by")
|
|
153
152
|
self.group_by.append(field.json_data())
|
|
154
153
|
else:
|
|
155
|
-
raise APIError(
|
|
156
|
-
|
|
154
|
+
raise APIError(
|
|
155
|
+
"ExtractOperator.add_group_by only supports "
|
|
156
|
+
"lists, strings, and FunctionOperator objects"
|
|
157
|
+
)
|
|
157
158
|
|
|
158
159
|
def __repr__(self):
|
|
159
|
-
return
|
|
160
|
+
return f"Query: {self}"
|
|
160
161
|
|
|
161
162
|
def __str__(self):
|
|
162
163
|
return json.dumps(self.json_data())
|
|
@@ -165,7 +166,7 @@ class ExtractOperator(object):
|
|
|
165
166
|
if len(self.fields) == 0:
|
|
166
167
|
raise APIError("ExtractOperator needs at least one field")
|
|
167
168
|
|
|
168
|
-
arr = [
|
|
169
|
+
arr = ["extract", self.fields]
|
|
169
170
|
|
|
170
171
|
if self.query is not None:
|
|
171
172
|
arr.append(self.query)
|
|
@@ -175,7 +176,7 @@ class ExtractOperator(object):
|
|
|
175
176
|
return arr
|
|
176
177
|
|
|
177
178
|
|
|
178
|
-
class FunctionOperator
|
|
179
|
+
class FunctionOperator:
|
|
179
180
|
"""
|
|
180
181
|
Performs an aggregate function on the result of a subquery, full
|
|
181
182
|
documentation is available at
|
|
@@ -191,24 +192,23 @@ class FunctionOperator(object):
|
|
|
191
192
|
"""
|
|
192
193
|
|
|
193
194
|
def __init__(self, function, field=None, fmt=None):
|
|
194
|
-
if function not in [
|
|
195
|
-
raise APIError("Unsupport function: {
|
|
195
|
+
if function not in ["count", "avg", "sum", "min", "max", "to_string"]:
|
|
196
|
+
raise APIError(f"Unsupport function: {function}")
|
|
196
197
|
elif function != "count" and field is None:
|
|
197
|
-
raise APIError("Function {
|
|
198
|
-
|
|
199
|
-
elif function == 'to_string' and fmt is None:
|
|
198
|
+
raise APIError("Function {} requires a field value".format(function))
|
|
199
|
+
elif function == "to_string" and fmt is None:
|
|
200
200
|
raise APIError("Function {0} requires an extra 'fmt' parameter")
|
|
201
201
|
|
|
202
|
-
self.arr = [
|
|
202
|
+
self.arr = ["function", function]
|
|
203
203
|
|
|
204
204
|
if field is not None:
|
|
205
205
|
self.arr.append(field)
|
|
206
206
|
|
|
207
|
-
if function ==
|
|
207
|
+
if function == "to_string":
|
|
208
208
|
self.arr.append(fmt)
|
|
209
209
|
|
|
210
210
|
def __repr__(self):
|
|
211
|
-
return
|
|
211
|
+
return f"Query: {self}"
|
|
212
212
|
|
|
213
213
|
def __str__(self):
|
|
214
214
|
return json.dumps(self.json_data())
|
|
@@ -217,7 +217,7 @@ class FunctionOperator(object):
|
|
|
217
217
|
return self.arr
|
|
218
218
|
|
|
219
219
|
|
|
220
|
-
class SubqueryOperator
|
|
220
|
+
class SubqueryOperator:
|
|
221
221
|
"""
|
|
222
222
|
Performs a subquery to another puppetDB object, full
|
|
223
223
|
documentation is available at
|
|
@@ -230,13 +230,22 @@ class SubqueryOperator(object):
|
|
|
230
230
|
"""
|
|
231
231
|
|
|
232
232
|
def __init__(self, endpoint):
|
|
233
|
-
if endpoint not in [
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
233
|
+
if endpoint not in [
|
|
234
|
+
"catalogs",
|
|
235
|
+
"edges",
|
|
236
|
+
"environments",
|
|
237
|
+
"events",
|
|
238
|
+
"facts",
|
|
239
|
+
"fact_contents",
|
|
240
|
+
"fact_paths",
|
|
241
|
+
"nodes",
|
|
242
|
+
"reports",
|
|
243
|
+
"resources",
|
|
244
|
+
]:
|
|
245
|
+
raise APIError(f"Unsupported endpoint: {endpoint}")
|
|
237
246
|
|
|
238
247
|
self.query = None
|
|
239
|
-
self.arr = [
|
|
248
|
+
self.arr = [f"select_{endpoint}"]
|
|
240
249
|
|
|
241
250
|
def add_query(self, query):
|
|
242
251
|
if self.query is not None:
|
|
@@ -246,7 +255,7 @@ class SubqueryOperator(object):
|
|
|
246
255
|
self.arr.append(query.json_data())
|
|
247
256
|
|
|
248
257
|
def __repr__(self):
|
|
249
|
-
return
|
|
258
|
+
return f"Query: {self}"
|
|
250
259
|
|
|
251
260
|
def __str__(self):
|
|
252
261
|
return json.dumps(self.json_data())
|
|
@@ -255,7 +264,7 @@ class SubqueryOperator(object):
|
|
|
255
264
|
return self.arr
|
|
256
265
|
|
|
257
266
|
|
|
258
|
-
class InOperator
|
|
267
|
+
class InOperator:
|
|
259
268
|
"""
|
|
260
269
|
Performs boolean compare between a field a subquery result
|
|
261
270
|
https://puppet.com/docs/puppetdb/7/api/query/v4/ast.html#subquery-operators
|
|
@@ -268,7 +277,7 @@ class InOperator(object):
|
|
|
268
277
|
|
|
269
278
|
def __init__(self, field):
|
|
270
279
|
self.query = None
|
|
271
|
-
self.arr = [
|
|
280
|
+
self.arr = ["in", field]
|
|
272
281
|
|
|
273
282
|
def add_query(self, query):
|
|
274
283
|
if self.query is not None:
|
|
@@ -280,31 +289,39 @@ class InOperator(object):
|
|
|
280
289
|
self.query = True
|
|
281
290
|
self.arr.append(query.json_data())
|
|
282
291
|
else:
|
|
283
|
-
raise APIError(
|
|
284
|
-
|
|
285
|
-
|
|
292
|
+
raise APIError(
|
|
293
|
+
"InOperator.add_query only supports "
|
|
294
|
+
"strings, ExtractOperator, and"
|
|
295
|
+
"FromOperator objects"
|
|
296
|
+
)
|
|
286
297
|
|
|
287
298
|
def add_array(self, values):
|
|
288
299
|
if self.query is not None:
|
|
289
300
|
raise APIError("Only one array is supported by the InOperator")
|
|
290
301
|
elif isinstance(values, list):
|
|
302
|
+
|
|
291
303
|
def depth(a_list):
|
|
292
|
-
return (isinstance(a_list, list) and len(a_list) != 0)
|
|
293
|
-
|
|
304
|
+
return (isinstance(a_list, list) and len(a_list) != 0) and max(
|
|
305
|
+
map(depth, a_list)
|
|
306
|
+
) + 1
|
|
294
307
|
|
|
295
308
|
if depth(values) == 1:
|
|
296
309
|
self.query = True
|
|
297
|
-
self.arr.append([
|
|
310
|
+
self.arr.append(["array", values])
|
|
298
311
|
else:
|
|
299
|
-
raise APIError(
|
|
300
|
-
|
|
312
|
+
raise APIError(
|
|
313
|
+
"InOperator.add_array: cannot pass in "
|
|
314
|
+
"nested arrays (or empty arrays)"
|
|
315
|
+
)
|
|
301
316
|
else:
|
|
302
|
-
raise APIError(
|
|
303
|
-
|
|
304
|
-
|
|
317
|
+
raise APIError(
|
|
318
|
+
"InOperator.add_array: Ill-formatted array, "
|
|
319
|
+
"must be of the format: "
|
|
320
|
+
"['array', [<array values>]]"
|
|
321
|
+
)
|
|
305
322
|
|
|
306
323
|
def __repr__(self):
|
|
307
|
-
return
|
|
324
|
+
return f"Query: {self}"
|
|
308
325
|
|
|
309
326
|
def __str__(self):
|
|
310
327
|
return json.dumps(self.json_data())
|
|
@@ -313,7 +330,7 @@ class InOperator(object):
|
|
|
313
330
|
return self.arr
|
|
314
331
|
|
|
315
332
|
|
|
316
|
-
class FromOperator
|
|
333
|
+
class FromOperator:
|
|
317
334
|
"""
|
|
318
335
|
From contextual operator that allows for queries on the root endpoint
|
|
319
336
|
or subqueries into other entities:
|
|
@@ -329,17 +346,30 @@ class FromOperator(object):
|
|
|
329
346
|
"""
|
|
330
347
|
|
|
331
348
|
def __init__(self, endpoint):
|
|
332
|
-
valid_entities = [
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
349
|
+
valid_entities = [
|
|
350
|
+
"aggregate_event_counts",
|
|
351
|
+
"catalogs",
|
|
352
|
+
"edges",
|
|
353
|
+
"environments",
|
|
354
|
+
"event_counts",
|
|
355
|
+
"events",
|
|
356
|
+
"facts",
|
|
357
|
+
"fact_contents",
|
|
358
|
+
"fact_names",
|
|
359
|
+
"fact_paths",
|
|
360
|
+
"nodes",
|
|
361
|
+
"producers",
|
|
362
|
+
"reports",
|
|
363
|
+
"resources",
|
|
364
|
+
]
|
|
336
365
|
|
|
337
366
|
if endpoint in valid_entities:
|
|
338
367
|
self.endpoint = endpoint
|
|
339
368
|
else:
|
|
340
|
-
raise APIError(
|
|
341
|
-
|
|
342
|
-
|
|
369
|
+
raise APIError(
|
|
370
|
+
"Endpoint is invalid. Must be "
|
|
371
|
+
"one of the following : %s" % valid_entities
|
|
372
|
+
)
|
|
343
373
|
|
|
344
374
|
self.query = None
|
|
345
375
|
self.order_by = []
|
|
@@ -349,13 +379,19 @@ class FromOperator(object):
|
|
|
349
379
|
def add_query(self, query):
|
|
350
380
|
if self.query is not None:
|
|
351
381
|
raise APIError("Only one main query is supported by FromOperator")
|
|
352
|
-
elif isinstance(
|
|
353
|
-
|
|
354
|
-
|
|
382
|
+
elif isinstance(
|
|
383
|
+
query,
|
|
384
|
+
(
|
|
385
|
+
InOperator,
|
|
386
|
+
ExtractOperator,
|
|
387
|
+
BinaryOperator,
|
|
388
|
+
BooleanOperator,
|
|
389
|
+
FunctionOperator,
|
|
390
|
+
),
|
|
391
|
+
):
|
|
355
392
|
self.query = query.json_data()
|
|
356
393
|
else:
|
|
357
|
-
raise APIError("FromOperator.add_field only supports "
|
|
358
|
-
"Operator Objects")
|
|
394
|
+
raise APIError("FromOperator.add_field only supports " "Operator Objects")
|
|
359
395
|
|
|
360
396
|
def add_order_by(self, fields):
|
|
361
397
|
def depth(a_list):
|
|
@@ -367,13 +403,17 @@ class FromOperator(object):
|
|
|
367
403
|
if fields_depth == 1 or fields_depth == 2:
|
|
368
404
|
self.order_by = fields
|
|
369
405
|
else:
|
|
370
|
-
raise APIError(
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
406
|
+
raise APIError(
|
|
407
|
+
"ExtractOperator.add_order_by only "
|
|
408
|
+
"supports lists of fields of depth "
|
|
409
|
+
"one or two: [value, <desc/asc>] or "
|
|
410
|
+
"[value]"
|
|
411
|
+
)
|
|
374
412
|
else:
|
|
375
|
-
raise APIError(
|
|
376
|
-
|
|
413
|
+
raise APIError(
|
|
414
|
+
"ExtractOperator.add_group_by only supports "
|
|
415
|
+
"lists of one or more fields"
|
|
416
|
+
)
|
|
377
417
|
|
|
378
418
|
def add_limit(self, lim):
|
|
379
419
|
if isinstance(lim, int):
|
|
@@ -388,7 +428,7 @@ class FromOperator(object):
|
|
|
388
428
|
raise APIError("ExtractOperator.add_offset only supports ints")
|
|
389
429
|
|
|
390
430
|
def __repr__(self):
|
|
391
|
-
return
|
|
431
|
+
return f"Query: {self}"
|
|
392
432
|
|
|
393
433
|
def __str__(self):
|
|
394
434
|
return json.dumps(self.json_data())
|
|
@@ -397,14 +437,14 @@ class FromOperator(object):
|
|
|
397
437
|
if self.query is None:
|
|
398
438
|
raise APIError("FromOperator needs one main query")
|
|
399
439
|
|
|
400
|
-
arr = [
|
|
440
|
+
arr = ["from", self.endpoint, self.query]
|
|
401
441
|
|
|
402
442
|
if len(self.order_by) > 0:
|
|
403
|
-
arr.append([
|
|
443
|
+
arr.append(["order_by", self.order_by])
|
|
404
444
|
if self.limit is not None:
|
|
405
|
-
arr.append([
|
|
445
|
+
arr.append(["limit", self.limit])
|
|
406
446
|
if self.offset is not None:
|
|
407
|
-
arr.append([
|
|
447
|
+
arr.append(["offset", self.offset])
|
|
408
448
|
|
|
409
449
|
return arr
|
|
410
450
|
|
|
@@ -431,7 +471,7 @@ class EqualsOperator(BinaryOperator):
|
|
|
431
471
|
"""
|
|
432
472
|
|
|
433
473
|
def __init__(self, field, value):
|
|
434
|
-
super(
|
|
474
|
+
super().__init__("=", field, value)
|
|
435
475
|
|
|
436
476
|
|
|
437
477
|
class GreaterOperator(BinaryOperator):
|
|
@@ -456,7 +496,7 @@ class GreaterOperator(BinaryOperator):
|
|
|
456
496
|
"""
|
|
457
497
|
|
|
458
498
|
def __init__(self, field, value):
|
|
459
|
-
super(
|
|
499
|
+
super().__init__(">", field, value)
|
|
460
500
|
|
|
461
501
|
|
|
462
502
|
class LessOperator(BinaryOperator):
|
|
@@ -481,7 +521,7 @@ class LessOperator(BinaryOperator):
|
|
|
481
521
|
"""
|
|
482
522
|
|
|
483
523
|
def __init__(self, field, value):
|
|
484
|
-
super(
|
|
524
|
+
super().__init__("<", field, value)
|
|
485
525
|
|
|
486
526
|
|
|
487
527
|
class GreaterEqualOperator(BinaryOperator):
|
|
@@ -507,7 +547,7 @@ class GreaterEqualOperator(BinaryOperator):
|
|
|
507
547
|
"""
|
|
508
548
|
|
|
509
549
|
def __init__(self, field, value):
|
|
510
|
-
super(
|
|
550
|
+
super().__init__(">=", field, value)
|
|
511
551
|
|
|
512
552
|
|
|
513
553
|
class LessEqualOperator(BinaryOperator):
|
|
@@ -533,7 +573,7 @@ class LessEqualOperator(BinaryOperator):
|
|
|
533
573
|
"""
|
|
534
574
|
|
|
535
575
|
def __init__(self, field, value):
|
|
536
|
-
super(
|
|
576
|
+
super().__init__("<=", field, value)
|
|
537
577
|
|
|
538
578
|
|
|
539
579
|
class RegexOperator(BinaryOperator):
|
|
@@ -558,7 +598,7 @@ class RegexOperator(BinaryOperator):
|
|
|
558
598
|
"""
|
|
559
599
|
|
|
560
600
|
def __init__(self, field, value):
|
|
561
|
-
super(
|
|
601
|
+
super().__init__("~", field, value)
|
|
562
602
|
|
|
563
603
|
|
|
564
604
|
class RegexArrayOperator(BinaryOperator):
|
|
@@ -584,7 +624,7 @@ class RegexArrayOperator(BinaryOperator):
|
|
|
584
624
|
"""
|
|
585
625
|
|
|
586
626
|
def __init__(self, field, value):
|
|
587
|
-
super(
|
|
627
|
+
super().__init__("~>", field, value)
|
|
588
628
|
|
|
589
629
|
|
|
590
630
|
class NullOperator(BinaryOperator):
|
|
@@ -612,10 +652,10 @@ class NullOperator(BinaryOperator):
|
|
|
612
652
|
"""
|
|
613
653
|
|
|
614
654
|
def __init__(self, field, value):
|
|
615
|
-
if
|
|
655
|
+
if not isinstance(value, bool):
|
|
616
656
|
raise APIError("NullOperator value must be boolean")
|
|
617
657
|
|
|
618
|
-
super(
|
|
658
|
+
super().__init__("null?", field, value)
|
|
619
659
|
|
|
620
660
|
|
|
621
661
|
class AndOperator(BooleanOperator):
|
|
@@ -639,7 +679,7 @@ class AndOperator(BooleanOperator):
|
|
|
639
679
|
"""
|
|
640
680
|
|
|
641
681
|
def __init__(self):
|
|
642
|
-
super(
|
|
682
|
+
super().__init__("and")
|
|
643
683
|
|
|
644
684
|
|
|
645
685
|
class OrOperator(BooleanOperator):
|
|
@@ -661,7 +701,7 @@ class OrOperator(BooleanOperator):
|
|
|
661
701
|
"""
|
|
662
702
|
|
|
663
703
|
def __init__(self):
|
|
664
|
-
super(
|
|
704
|
+
super().__init__("or")
|
|
665
705
|
|
|
666
706
|
|
|
667
707
|
class NotOperator(BooleanOperator):
|
|
@@ -685,11 +725,11 @@ class NotOperator(BooleanOperator):
|
|
|
685
725
|
"""
|
|
686
726
|
|
|
687
727
|
def __init__(self):
|
|
688
|
-
super(
|
|
728
|
+
super().__init__("not")
|
|
689
729
|
|
|
690
730
|
def add(self, query):
|
|
691
731
|
if len(self.operations) > 0:
|
|
692
732
|
raise APIError("This operator only accept one query string")
|
|
693
733
|
elif isinstance(query, list) and len(query) > 1:
|
|
694
734
|
raise APIError("This operator only accept one query string")
|
|
695
|
-
super(
|
|
735
|
+
super().add(query)
|