jaseci 1.4.2.5__py3-none-any.whl → 2.0.0__py3-none-any.whl
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.
Potentially problematic release.
This version of jaseci might be problematic. Click here for more details.
- jaseci/__init__.py +3 -37
- jaseci-2.0.0.dist-info/METADATA +65 -0
- jaseci-2.0.0.dist-info/RECORD +4 -0
- {jaseci-1.4.2.5.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
- jaseci/VERSION +0 -1
- jaseci/cli_tools/__init__.py +0 -0
- jaseci/cli_tools/book_tools.py +0 -457
- jaseci/cli_tools/jsctl.py +0 -500
- jaseci/cli_tools/tests/__init__.py +0 -0
- jaseci/cli_tools/tests/test_jsctl.py +0 -556
- jaseci/extens/__init__.py +0 -0
- jaseci/extens/act_lib/__init__.py +0 -0
- jaseci/extens/act_lib/date.py +0 -117
- jaseci/extens/act_lib/elastic.py +0 -87
- jaseci/extens/act_lib/file.py +0 -76
- jaseci/extens/act_lib/file_handler.py +0 -189
- jaseci/extens/act_lib/internal.py +0 -18
- jaseci/extens/act_lib/jaseci.py +0 -61
- jaseci/extens/act_lib/mail.py +0 -10
- jaseci/extens/act_lib/maths.py +0 -168
- jaseci/extens/act_lib/net.py +0 -191
- jaseci/extens/act_lib/rand.py +0 -82
- jaseci/extens/act_lib/regex.py +0 -85
- jaseci/extens/act_lib/request.py +0 -169
- jaseci/extens/act_lib/std.py +0 -235
- jaseci/extens/act_lib/storage.py +0 -53
- jaseci/extens/act_lib/stripe.py +0 -337
- jaseci/extens/act_lib/task.py +0 -13
- jaseci/extens/act_lib/tests/__init__.py +0 -0
- jaseci/extens/act_lib/tests/std_test_code.py +0 -37
- jaseci/extens/act_lib/tests/test_date.py +0 -26
- jaseci/extens/act_lib/tests/test_elastic.py +0 -159
- jaseci/extens/act_lib/tests/test_file.py +0 -116
- jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
- jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
- jaseci/extens/act_lib/tests/test_maths.py +0 -147
- jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
- jaseci/extens/act_lib/tests/test_regex.py +0 -61
- jaseci/extens/act_lib/tests/test_std.py +0 -51
- jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
- jaseci/extens/act_lib/tests/test_url.py +0 -32
- jaseci/extens/act_lib/tests/test_vector.py +0 -36
- jaseci/extens/act_lib/tests/test_webtool.py +0 -44
- jaseci/extens/act_lib/tests/test_zlib.py +0 -24
- jaseci/extens/act_lib/url.py +0 -79
- jaseci/extens/act_lib/vector.py +0 -157
- jaseci/extens/act_lib/webtool.py +0 -28
- jaseci/extens/act_lib/zip.py +0 -33
- jaseci/extens/api/__init__.py +0 -0
- jaseci/extens/api/actions_api.py +0 -170
- jaseci/extens/api/alias_api.py +0 -139
- jaseci/extens/api/architype_api.py +0 -196
- jaseci/extens/api/config_api.py +0 -129
- jaseci/extens/api/global_api.py +0 -84
- jaseci/extens/api/graph_api.py +0 -167
- jaseci/extens/api/health_api.py +0 -20
- jaseci/extens/api/interface.py +0 -268
- jaseci/extens/api/jac_api.py +0 -171
- jaseci/extens/api/jsorc_api.py +0 -316
- jaseci/extens/api/logger_api.py +0 -89
- jaseci/extens/api/master_api.py +0 -133
- jaseci/extens/api/object_api.py +0 -101
- jaseci/extens/api/prometheus_api.py +0 -74
- jaseci/extens/api/queue_api.py +0 -140
- jaseci/extens/api/sentinel_api.py +0 -270
- jaseci/extens/api/super_api.py +0 -64
- jaseci/extens/api/tests/__init__.py +0 -0
- jaseci/extens/api/tests/test_architype_api.py +0 -66
- jaseci/extens/api/tests/test_global_api.py +0 -179
- jaseci/extens/api/tests/test_graph_api.py +0 -64
- jaseci/extens/api/tests/test_logger_api.py +0 -43
- jaseci/extens/api/tests/test_object_api.py +0 -20
- jaseci/extens/api/tests/test_sentinel_api.py +0 -66
- jaseci/extens/api/tests/test_uncommon.py +0 -107
- jaseci/extens/api/tests/test_user_api.py +0 -32
- jaseci/extens/api/tests/test_walker_api.py +0 -316
- jaseci/extens/api/user_api.py +0 -144
- jaseci/extens/api/walker_api.py +0 -298
- jaseci/extens/api/webhook_api.py +0 -74
- jaseci/extens/svc/__init__.py +0 -0
- jaseci/extens/svc/elastic_svc.py +0 -366
- jaseci/extens/svc/kube_svc.py +0 -432
- jaseci/extens/svc/mail_svc.py +0 -156
- jaseci/extens/svc/prome_svc.py +0 -378
- jaseci/extens/svc/redis_svc.py +0 -63
- jaseci/extens/svc/storage_svc.py +0 -193
- jaseci/extens/svc/stripe_svc.py +0 -51
- jaseci/extens/svc/task_svc.py +0 -155
- jaseci/extens/svc/tasks.py +0 -302
- jaseci/jac/__init__.py +0 -0
- jaseci/jac/interpreter/__init__.py +0 -0
- jaseci/jac/interpreter/architype_interp.py +0 -214
- jaseci/jac/interpreter/interp.py +0 -1783
- jaseci/jac/interpreter/sentinel_interp.py +0 -257
- jaseci/jac/interpreter/tests/__init__.py +0 -0
- jaseci/jac/interpreter/tests/test_interp.py +0 -42
- jaseci/jac/interpreter/walker_interp.py +0 -248
- jaseci/jac/ir/__init__.py +0 -0
- jaseci/jac/ir/ast.py +0 -73
- jaseci/jac/ir/ast_builder.py +0 -249
- jaseci/jac/ir/jac_code.py +0 -152
- jaseci/jac/ir/passes/__init__.py +0 -6
- jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
- jaseci/jac/ir/passes/codegen_pass.py +0 -244
- jaseci/jac/ir/passes/ir_pass.py +0 -29
- jaseci/jac/ir/passes/printer_pass.py +0 -23
- jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
- jaseci/jac/ir/passes/schedule.py +0 -23
- jaseci/jac/ir/passes/stats_pass.py +0 -16
- jaseci/jac/jac.g4 +0 -450
- jaseci/jac/jac_parse/__init__.py +0 -0
- jaseci/jac/jac_parse/jacLexer.py +0 -809
- jaseci/jac/jac_parse/jacListener.py +0 -853
- jaseci/jac/jac_parse/jacParser.py +0 -9192
- jaseci/jac/jac_set.py +0 -119
- jaseci/jac/jsci_vm/__init__.py +0 -0
- jaseci/jac/jsci_vm/disasm.py +0 -94
- jaseci/jac/jsci_vm/inst_ptr.py +0 -31
- jaseci/jac/jsci_vm/machine.py +0 -188
- jaseci/jac/jsci_vm/op_codes.py +0 -82
- jaseci/jac/jsci_vm/tests/__init__.py +0 -0
- jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
- jaseci/jac/machine/__init__.py +0 -0
- jaseci/jac/machine/jac_scope.py +0 -85
- jaseci/jac/machine/jac_value.py +0 -226
- jaseci/jac/machine/machine_state.py +0 -383
- jaseci/jac/tests/__init__.py +0 -0
- jaseci/jac/tests/book_code.py +0 -624
- jaseci/jac/tests/test_book.py +0 -380
- jaseci/jac/tests/test_lang_14.py +0 -49
- jaseci/jsorc/__init__.py +0 -7
- jaseci/jsorc/jsorc.py +0 -642
- jaseci/jsorc/jsorc_settings.py +0 -211
- jaseci/jsorc/jsorc_utils.py +0 -298
- jaseci/jsorc/live_actions.py +0 -364
- jaseci/jsorc/manifests/__init__.py +0 -0
- jaseci/jsorc/manifests/database.yaml +0 -109
- jaseci/jsorc/manifests/elastic.yaml +0 -6024
- jaseci/jsorc/manifests/prometheus.yaml +0 -1383
- jaseci/jsorc/manifests/redis.yaml +0 -64
- jaseci/jsorc/memory.py +0 -258
- jaseci/jsorc/redis.py +0 -139
- jaseci/jsorc/remote_actions.py +0 -157
- jaseci/jsorc/tests/__init__.py +0 -0
- jaseci/jsorc/tests/test_actions.py +0 -542
- jaseci/jsorc/tests/test_jsorc.py +0 -112
- jaseci/prim/__init__.py +0 -0
- jaseci/prim/ability.py +0 -93
- jaseci/prim/architype.py +0 -89
- jaseci/prim/edge.py +0 -172
- jaseci/prim/element.py +0 -233
- jaseci/prim/graph.py +0 -26
- jaseci/prim/master.py +0 -64
- jaseci/prim/node.py +0 -532
- jaseci/prim/obj_mixins.py +0 -235
- jaseci/prim/sentinel.py +0 -281
- jaseci/prim/super_master.py +0 -31
- jaseci/prim/walker.py +0 -261
- jaseci/svc/__init__.py +0 -0
- jaseci/tests/__init__.py +0 -0
- jaseci/tests/infer.py +0 -39
- jaseci/tests/jac_test_code.py +0 -1293
- jaseci/tests/jac_test_progs.py +0 -774
- jaseci/tests/test_core.py +0 -153
- jaseci/tests/test_jac.py +0 -824
- jaseci/tests/test_node.py +0 -89
- jaseci/tests/test_progs.py +0 -702
- jaseci/tests/test_stack.py +0 -220
- jaseci/tests/test_stripe.py +0 -225
- jaseci/utils/__init__.py +0 -0
- jaseci/utils/actions/__init__.py +0 -0
- jaseci/utils/actions/actions_manager.py +0 -254
- jaseci/utils/actions/actions_optimizer.py +0 -516
- jaseci/utils/actions/actions_state.py +0 -95
- jaseci/utils/file_handler.py +0 -171
- jaseci/utils/gprof2dot.py +0 -3786
- jaseci/utils/id_list.py +0 -168
- jaseci/utils/json_handler.py +0 -70
- jaseci/utils/log_utils.py +0 -57
- jaseci/utils/test_core.py +0 -62
- jaseci/utils/utils.py +0 -387
- jaseci-1.4.2.5.dist-info/LICENSE +0 -21
- jaseci-1.4.2.5.dist-info/METADATA +0 -39
- jaseci-1.4.2.5.dist-info/RECORD +0 -184
- jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
- jaseci-1.4.2.5.dist-info/top_level.txt +0 -1
jaseci/extens/svc/elastic_svc.py
DELETED
|
@@ -1,366 +0,0 @@
|
|
|
1
|
-
import re
|
|
2
|
-
from jaseci.jsorc.jsorc import JsOrc
|
|
3
|
-
from jaseci.jsorc.jsorc_settings import JsOrcSettings
|
|
4
|
-
from jaseci.extens.svc.kube_svc import KubeService
|
|
5
|
-
from jaseci.utils.utils import logger, app_logger
|
|
6
|
-
from requests import get, post, put
|
|
7
|
-
from datetime import datetime
|
|
8
|
-
from copy import copy
|
|
9
|
-
from base64 import b64encode
|
|
10
|
-
import multiprocessing
|
|
11
|
-
import logging.handlers
|
|
12
|
-
|
|
13
|
-
LOG_QUEUES = {}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def format_elastic_record(record):
|
|
17
|
-
# Strip out color code from message before sending to elastic
|
|
18
|
-
msg = record.getMessage()
|
|
19
|
-
msg = re.sub(r"\033\[[0-9]*m", "", msg)
|
|
20
|
-
ts = "%s.%03d" % (
|
|
21
|
-
logging.Formatter().formatTime(record, "%Y-%m-%dT%H:%M:%S"),
|
|
22
|
-
record.msecs,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
elastic_record = {
|
|
26
|
-
"@timestamp": ts,
|
|
27
|
-
"message": msg,
|
|
28
|
-
"level": record.levelname,
|
|
29
|
-
}
|
|
30
|
-
extra_fields = record.__dict__.get("extra_fields", [])
|
|
31
|
-
elastic_record.update(dict([(k, record.__dict__[k]) for k in extra_fields]))
|
|
32
|
-
return elastic_record
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
#################################################
|
|
36
|
-
# ELASTIC APP #
|
|
37
|
-
#################################################
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@JsOrc.service(name="elastic", config="ELASTIC_CONFIG", manifest="ELASTIC_MANIFEST")
|
|
41
|
-
class ElasticService(JsOrc.CommonService):
|
|
42
|
-
###################################################
|
|
43
|
-
# BUILDER #
|
|
44
|
-
###################################################
|
|
45
|
-
|
|
46
|
-
def run(self):
|
|
47
|
-
kube = JsOrc.svc("kube", KubeService)
|
|
48
|
-
if kube.is_running():
|
|
49
|
-
elasticsearches = kube.resolve_manifest(
|
|
50
|
-
self.manifest, *JsOrc.overrided_namespace("elastic", self.manifest_type)
|
|
51
|
-
).get("Elasticsearch", [])
|
|
52
|
-
|
|
53
|
-
if elasticsearches:
|
|
54
|
-
metadata: dict = elasticsearches["jaseci"]["metadata"]
|
|
55
|
-
|
|
56
|
-
cert = kube.get_secret(
|
|
57
|
-
f'{metadata.get("name")}-es-http-certs-internal',
|
|
58
|
-
"ca.crt",
|
|
59
|
-
metadata.get("namespace"),
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
if cert:
|
|
63
|
-
with open("elastic-certificate.crt", "w") as cert_file:
|
|
64
|
-
cert_file.write(cert)
|
|
65
|
-
self.config["verifier"] = "elastic-certificate.crt"
|
|
66
|
-
|
|
67
|
-
if not self.config.get("auth"):
|
|
68
|
-
auth = kube.get_secret(
|
|
69
|
-
f'{metadata.get("name")}-es-elastic-user',
|
|
70
|
-
"elastic",
|
|
71
|
-
metadata.get("namespace"),
|
|
72
|
-
)
|
|
73
|
-
self.config[
|
|
74
|
-
"auth"
|
|
75
|
-
] = f'basic {b64encode(f"elastic:{auth}".encode()).decode()}'
|
|
76
|
-
|
|
77
|
-
self.app = Elastic(self.config)
|
|
78
|
-
self.app.health("timeout=1s")
|
|
79
|
-
|
|
80
|
-
def post_run(self):
|
|
81
|
-
if multiprocessing.current_process().name == "MainProcess":
|
|
82
|
-
under_test = self.config.get("under_test", False)
|
|
83
|
-
if not under_test:
|
|
84
|
-
self.configure_elastic()
|
|
85
|
-
LOG_QUEUES["core"] = self.add_elastic_log_handler(
|
|
86
|
-
logger, self.config.get("core_log_index") or "core", under_test
|
|
87
|
-
)
|
|
88
|
-
LOG_QUEUES["app"] = self.add_elastic_log_handler(
|
|
89
|
-
app_logger, self.config.get("app_log_index") or "app", under_test
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
def configure_elastic(self):
|
|
93
|
-
"""
|
|
94
|
-
Configure elastic logging with desired configuration
|
|
95
|
-
- Data stream for core* and app* index pattern
|
|
96
|
-
- Index template with the data-streams-mappings component mapping rules
|
|
97
|
-
- @timestamp is converted to date field type
|
|
98
|
-
- text fields are converted as keywords for search
|
|
99
|
-
- An index lifecycle management (ILM) policy
|
|
100
|
-
- hot index for 7 days or 5GB max size
|
|
101
|
-
- delete indices older than 30 days
|
|
102
|
-
"""
|
|
103
|
-
# Create the ILM policy
|
|
104
|
-
self.app.create_ilm_policy(
|
|
105
|
-
policy_name=self.config.get(
|
|
106
|
-
"ilm_policy_name", JsOrcSettings.ELASTIC_ILM_POLICY_NAME
|
|
107
|
-
),
|
|
108
|
-
policy_config=self.config.get(
|
|
109
|
-
"ilm_policy", JsOrcSettings.ELASTIC_ILM_POLICY
|
|
110
|
-
),
|
|
111
|
-
overwrite=False,
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
# Create index template and attach ILM policy
|
|
115
|
-
self.app.create_index_template(
|
|
116
|
-
template_name=self.config.get(
|
|
117
|
-
"index_template_name", JsOrcSettings.ELASTIC_INDEX_TEMPLATE_NAME
|
|
118
|
-
),
|
|
119
|
-
template_config=self.config.get(
|
|
120
|
-
"index_template", JsOrcSettings.ELASTIC_INDEX_TEMPLATE
|
|
121
|
-
),
|
|
122
|
-
overwrite=False,
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
def add_elastic_log_handler(self, logger_instance, index, under_test=False):
|
|
126
|
-
has_queue_handler = any(
|
|
127
|
-
isinstance(h, logging.handlers.QueueHandler)
|
|
128
|
-
for h in logger_instance.handlers
|
|
129
|
-
)
|
|
130
|
-
if not has_queue_handler:
|
|
131
|
-
log_queue = multiprocessing.Queue()
|
|
132
|
-
queue_handler = logging.handlers.QueueHandler(log_queue)
|
|
133
|
-
logger_instance.addHandler(queue_handler)
|
|
134
|
-
|
|
135
|
-
def elastic_log_worker(elastic_index):
|
|
136
|
-
while True:
|
|
137
|
-
try:
|
|
138
|
-
record = log_queue.get()
|
|
139
|
-
if record is None:
|
|
140
|
-
# This is temporary
|
|
141
|
-
# for debugging purposes
|
|
142
|
-
from datetime import datetime
|
|
143
|
-
|
|
144
|
-
self.app.doc(
|
|
145
|
-
{
|
|
146
|
-
"@timestamp": datetime.now().strftime(
|
|
147
|
-
"%Y-%m-%dT%H:%M:%S"
|
|
148
|
-
),
|
|
149
|
-
"message": f"Stopping process for {elastic_index}",
|
|
150
|
-
"level": "SYSTEM",
|
|
151
|
-
},
|
|
152
|
-
index=elastic_index,
|
|
153
|
-
)
|
|
154
|
-
# end of temporary code
|
|
155
|
-
break
|
|
156
|
-
elastic_record = format_elastic_record(record)
|
|
157
|
-
self.app.doc(log=elastic_record, index=elastic_index)
|
|
158
|
-
except Exception:
|
|
159
|
-
pass
|
|
160
|
-
|
|
161
|
-
# if under test, don't spawn the log worker process. Tests will validate two things:
|
|
162
|
-
# 1. logs are added to the log queue
|
|
163
|
-
# 2. format_elastic_record process the log properly and create the record for elastic
|
|
164
|
-
if not under_test:
|
|
165
|
-
worker_proc = multiprocessing.Process(
|
|
166
|
-
target=elastic_log_worker, args=(index,)
|
|
167
|
-
)
|
|
168
|
-
worker_proc.start()
|
|
169
|
-
|
|
170
|
-
return log_queue
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
class Elastic:
|
|
174
|
-
def __init__(self, config: dict):
|
|
175
|
-
if not config.get("url"):
|
|
176
|
-
raise Exception("URL is required!")
|
|
177
|
-
self.url = config["url"]
|
|
178
|
-
|
|
179
|
-
if not config.get("common_index"):
|
|
180
|
-
raise Exception("Common Index is required!")
|
|
181
|
-
self.common_index = config["common_index"]
|
|
182
|
-
|
|
183
|
-
if not config.get("activity_index"):
|
|
184
|
-
raise Exception("Activity Index is required!")
|
|
185
|
-
self.activity_index = config["activity_index"]
|
|
186
|
-
|
|
187
|
-
self.headers = {"Content-Type": "application/json"}
|
|
188
|
-
|
|
189
|
-
if config["auth"]:
|
|
190
|
-
self.headers["Authorization"] = config["auth"]
|
|
191
|
-
|
|
192
|
-
self.verifier = config.get("verifier")
|
|
193
|
-
|
|
194
|
-
def _get(self, url: str, json: dict = None):
|
|
195
|
-
return get(
|
|
196
|
-
f"{self.url}{url}",
|
|
197
|
-
json=json,
|
|
198
|
-
headers=self.headers,
|
|
199
|
-
verify=self.verifier,
|
|
200
|
-
).json()
|
|
201
|
-
|
|
202
|
-
def _post(self, url: str, json: dict = None):
|
|
203
|
-
return post(
|
|
204
|
-
f"{self.url}{url}",
|
|
205
|
-
json=json,
|
|
206
|
-
headers=self.headers,
|
|
207
|
-
verify=self.verifier,
|
|
208
|
-
).json()
|
|
209
|
-
|
|
210
|
-
def post(self, url: str, body: dict, index: str = "", suffix: str = ""):
|
|
211
|
-
return self._post(f"/{index or self.common_index}{suffix}{url}", body)
|
|
212
|
-
|
|
213
|
-
def post_act(self, url: str, body: dict, suffix: str = ""):
|
|
214
|
-
return self.post(url, body, self.activity_index, suffix)
|
|
215
|
-
|
|
216
|
-
def get(self, url: str, body: dict, index: str = "", suffix: str = ""):
|
|
217
|
-
return self._get(f"/{index or self.common_index}{suffix}{url}", body)
|
|
218
|
-
|
|
219
|
-
def get_act(self, url: str, body: dict, suffix: str = ""):
|
|
220
|
-
return self.get(url, body, self.activity_index, suffix)
|
|
221
|
-
|
|
222
|
-
def doc(self, log: dict, query: str = "", index: str = "", suffix: str = ""):
|
|
223
|
-
return self.post(f"/_doc?{query}", log, index, suffix)
|
|
224
|
-
|
|
225
|
-
def doc_activity(self, log: dict, query: str = "", suffix: str = ""):
|
|
226
|
-
return self.doc(log, query, self.activity_index, suffix)
|
|
227
|
-
|
|
228
|
-
def search(self, body: dict, query: str = "", index: str = "", suffix: str = ""):
|
|
229
|
-
return self.get(f"/_search?{query}", body, index, suffix)
|
|
230
|
-
|
|
231
|
-
def search_activity(self, body: dict, query: str = "", suffix: str = ""):
|
|
232
|
-
return self.search(body, query, self.activity_index, suffix)
|
|
233
|
-
|
|
234
|
-
def mapping(self, query: str = "", index: str = "", suffix: str = ""):
|
|
235
|
-
return self.get(f"/_mapping?{query}", None, index, suffix)
|
|
236
|
-
|
|
237
|
-
def mapping_activity(self, query: str = "", suffix: str = ""):
|
|
238
|
-
return self.mapping(query, self.activity_index, suffix)
|
|
239
|
-
|
|
240
|
-
def refresh(self, index: str = "", suffix: str = ""):
|
|
241
|
-
return self.get(f"/_refresh", None, index, suffix)
|
|
242
|
-
|
|
243
|
-
def refresh_activity(self, suffix: str = ""):
|
|
244
|
-
return self.refresh(self.activity_index, suffix)
|
|
245
|
-
|
|
246
|
-
def aliases(self, query: str = "pretty=true"):
|
|
247
|
-
return self._get(f"/_aliases?{query}")
|
|
248
|
-
|
|
249
|
-
def reindex(self, body: dict, query: str = "pretty"):
|
|
250
|
-
return self._post(f"/_reindex?{query}", body)
|
|
251
|
-
|
|
252
|
-
def create_ilm_policy(
|
|
253
|
-
self, policy_name: str, policy_config: dict, overwrite: bool = False
|
|
254
|
-
):
|
|
255
|
-
if not overwrite:
|
|
256
|
-
res = get(
|
|
257
|
-
f"{self.url}/_ilm/policy/{policy_name}",
|
|
258
|
-
headers=self.headers,
|
|
259
|
-
verify=self.verifier,
|
|
260
|
-
)
|
|
261
|
-
if res.status_code == 200 and policy_name in res.json():
|
|
262
|
-
# policy already exists
|
|
263
|
-
return False
|
|
264
|
-
res = put(
|
|
265
|
-
f"{self.url}/_ilm/policy/{policy_name}",
|
|
266
|
-
headers=self.headers,
|
|
267
|
-
json=policy_config,
|
|
268
|
-
verify=self.verifier,
|
|
269
|
-
)
|
|
270
|
-
if res.status_code == 200:
|
|
271
|
-
return res.json()
|
|
272
|
-
else:
|
|
273
|
-
return False
|
|
274
|
-
|
|
275
|
-
def create_index_template(
|
|
276
|
-
self, template_name: str, template_config: dict, overwrite: bool = False
|
|
277
|
-
):
|
|
278
|
-
if not overwrite:
|
|
279
|
-
res = get(
|
|
280
|
-
f"{self.url}/_index_template/{template_name}",
|
|
281
|
-
headers=self.headers,
|
|
282
|
-
verify=self.verifier,
|
|
283
|
-
)
|
|
284
|
-
if res.status_code == 200 and template_name in res.json():
|
|
285
|
-
# policy already exists
|
|
286
|
-
return False
|
|
287
|
-
res = put(
|
|
288
|
-
f"{self.url}/_index_template/{template_name}",
|
|
289
|
-
headers=self.headers,
|
|
290
|
-
json=template_config,
|
|
291
|
-
verify=self.verifier,
|
|
292
|
-
)
|
|
293
|
-
if res.status_code == 200:
|
|
294
|
-
return res.json()
|
|
295
|
-
else:
|
|
296
|
-
return False
|
|
297
|
-
|
|
298
|
-
# standard methods
|
|
299
|
-
def generate_from_meta(self, meta: dict, override: dict, action: str = None):
|
|
300
|
-
scope = meta["scope"].local_scope
|
|
301
|
-
|
|
302
|
-
walker = scope["visitor"]
|
|
303
|
-
node = walker.current_node
|
|
304
|
-
|
|
305
|
-
override_misc = override.get("misc")
|
|
306
|
-
override["misc"] = {
|
|
307
|
-
"report": copy(walker.report),
|
|
308
|
-
"node": node.serialize(detailed=False),
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if override_misc and isinstance(override_misc, dict):
|
|
312
|
-
override["misc"].update(override_misc)
|
|
313
|
-
|
|
314
|
-
master = meta["h"].get_obj(meta["m_id"], meta["m_id"]).master_self(True)
|
|
315
|
-
|
|
316
|
-
headers = walker.request_context.get("headers", {})
|
|
317
|
-
if headers.get("Authorization"):
|
|
318
|
-
del headers["Authorization"]
|
|
319
|
-
|
|
320
|
-
activity = {
|
|
321
|
-
"datetime": datetime.utcnow().isoformat(),
|
|
322
|
-
"activity_action": action or walker.name.replace("_", " ").title(),
|
|
323
|
-
"activity_type": walker.name,
|
|
324
|
-
"activity_point": node.name,
|
|
325
|
-
"walker_id": walker.jid,
|
|
326
|
-
"node_id": node.jid,
|
|
327
|
-
"master_id": master["jid"],
|
|
328
|
-
"user": master.get("__meta__") or {"email": master["name"]},
|
|
329
|
-
"request_context": walker.request_context,
|
|
330
|
-
"data": walker.context,
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
activity.update(override)
|
|
334
|
-
|
|
335
|
-
return activity
|
|
336
|
-
|
|
337
|
-
def generate_from_request(self, request):
|
|
338
|
-
headers = dict(request.headers)
|
|
339
|
-
if headers.get("Authorization"):
|
|
340
|
-
del headers["Authorization"]
|
|
341
|
-
|
|
342
|
-
data = request.data.dict() if type(request.data) is not dict else request.data
|
|
343
|
-
password = data.get("password")
|
|
344
|
-
if password:
|
|
345
|
-
data["password"] = len(password) * "*"
|
|
346
|
-
|
|
347
|
-
user = request.user
|
|
348
|
-
|
|
349
|
-
return {
|
|
350
|
-
"datetime": datetime.utcnow().isoformat(),
|
|
351
|
-
"activity_action": "User Manage",
|
|
352
|
-
"activity_type": "user_manage",
|
|
353
|
-
"master_id": user.master.urn,
|
|
354
|
-
"user": {"email": user.email},
|
|
355
|
-
"request_context": {
|
|
356
|
-
"method": request.method,
|
|
357
|
-
"headers": headers,
|
|
358
|
-
"query": request.GET.dict(),
|
|
359
|
-
"body": data,
|
|
360
|
-
},
|
|
361
|
-
"data": data,
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
def health(self, query: str = ""):
|
|
365
|
-
if self._get(f"/_cluster/health?{query}").get("timed_out", True):
|
|
366
|
-
raise Exception("Cannot connect on elastic service!")
|