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.

Files changed (186) hide show
  1. jaseci/__init__.py +3 -37
  2. jaseci-2.0.0.dist-info/METADATA +65 -0
  3. jaseci-2.0.0.dist-info/RECORD +4 -0
  4. {jaseci-1.4.2.5.dist-info → jaseci-2.0.0.dist-info}/WHEEL +1 -2
  5. jaseci/VERSION +0 -1
  6. jaseci/cli_tools/__init__.py +0 -0
  7. jaseci/cli_tools/book_tools.py +0 -457
  8. jaseci/cli_tools/jsctl.py +0 -500
  9. jaseci/cli_tools/tests/__init__.py +0 -0
  10. jaseci/cli_tools/tests/test_jsctl.py +0 -556
  11. jaseci/extens/__init__.py +0 -0
  12. jaseci/extens/act_lib/__init__.py +0 -0
  13. jaseci/extens/act_lib/date.py +0 -117
  14. jaseci/extens/act_lib/elastic.py +0 -87
  15. jaseci/extens/act_lib/file.py +0 -76
  16. jaseci/extens/act_lib/file_handler.py +0 -189
  17. jaseci/extens/act_lib/internal.py +0 -18
  18. jaseci/extens/act_lib/jaseci.py +0 -61
  19. jaseci/extens/act_lib/mail.py +0 -10
  20. jaseci/extens/act_lib/maths.py +0 -168
  21. jaseci/extens/act_lib/net.py +0 -191
  22. jaseci/extens/act_lib/rand.py +0 -82
  23. jaseci/extens/act_lib/regex.py +0 -85
  24. jaseci/extens/act_lib/request.py +0 -169
  25. jaseci/extens/act_lib/std.py +0 -235
  26. jaseci/extens/act_lib/storage.py +0 -53
  27. jaseci/extens/act_lib/stripe.py +0 -337
  28. jaseci/extens/act_lib/task.py +0 -13
  29. jaseci/extens/act_lib/tests/__init__.py +0 -0
  30. jaseci/extens/act_lib/tests/std_test_code.py +0 -37
  31. jaseci/extens/act_lib/tests/test_date.py +0 -26
  32. jaseci/extens/act_lib/tests/test_elastic.py +0 -159
  33. jaseci/extens/act_lib/tests/test_file.py +0 -116
  34. jaseci/extens/act_lib/tests/test_file_lib.py +0 -40
  35. jaseci/extens/act_lib/tests/test_mail_lib.py +0 -33
  36. jaseci/extens/act_lib/tests/test_maths.py +0 -147
  37. jaseci/extens/act_lib/tests/test_net_lib.py +0 -62
  38. jaseci/extens/act_lib/tests/test_regex.py +0 -61
  39. jaseci/extens/act_lib/tests/test_std.py +0 -51
  40. jaseci/extens/act_lib/tests/test_std_lib.py +0 -36
  41. jaseci/extens/act_lib/tests/test_url.py +0 -32
  42. jaseci/extens/act_lib/tests/test_vector.py +0 -36
  43. jaseci/extens/act_lib/tests/test_webtool.py +0 -44
  44. jaseci/extens/act_lib/tests/test_zlib.py +0 -24
  45. jaseci/extens/act_lib/url.py +0 -79
  46. jaseci/extens/act_lib/vector.py +0 -157
  47. jaseci/extens/act_lib/webtool.py +0 -28
  48. jaseci/extens/act_lib/zip.py +0 -33
  49. jaseci/extens/api/__init__.py +0 -0
  50. jaseci/extens/api/actions_api.py +0 -170
  51. jaseci/extens/api/alias_api.py +0 -139
  52. jaseci/extens/api/architype_api.py +0 -196
  53. jaseci/extens/api/config_api.py +0 -129
  54. jaseci/extens/api/global_api.py +0 -84
  55. jaseci/extens/api/graph_api.py +0 -167
  56. jaseci/extens/api/health_api.py +0 -20
  57. jaseci/extens/api/interface.py +0 -268
  58. jaseci/extens/api/jac_api.py +0 -171
  59. jaseci/extens/api/jsorc_api.py +0 -316
  60. jaseci/extens/api/logger_api.py +0 -89
  61. jaseci/extens/api/master_api.py +0 -133
  62. jaseci/extens/api/object_api.py +0 -101
  63. jaseci/extens/api/prometheus_api.py +0 -74
  64. jaseci/extens/api/queue_api.py +0 -140
  65. jaseci/extens/api/sentinel_api.py +0 -270
  66. jaseci/extens/api/super_api.py +0 -64
  67. jaseci/extens/api/tests/__init__.py +0 -0
  68. jaseci/extens/api/tests/test_architype_api.py +0 -66
  69. jaseci/extens/api/tests/test_global_api.py +0 -179
  70. jaseci/extens/api/tests/test_graph_api.py +0 -64
  71. jaseci/extens/api/tests/test_logger_api.py +0 -43
  72. jaseci/extens/api/tests/test_object_api.py +0 -20
  73. jaseci/extens/api/tests/test_sentinel_api.py +0 -66
  74. jaseci/extens/api/tests/test_uncommon.py +0 -107
  75. jaseci/extens/api/tests/test_user_api.py +0 -32
  76. jaseci/extens/api/tests/test_walker_api.py +0 -316
  77. jaseci/extens/api/user_api.py +0 -144
  78. jaseci/extens/api/walker_api.py +0 -298
  79. jaseci/extens/api/webhook_api.py +0 -74
  80. jaseci/extens/svc/__init__.py +0 -0
  81. jaseci/extens/svc/elastic_svc.py +0 -366
  82. jaseci/extens/svc/kube_svc.py +0 -432
  83. jaseci/extens/svc/mail_svc.py +0 -156
  84. jaseci/extens/svc/prome_svc.py +0 -378
  85. jaseci/extens/svc/redis_svc.py +0 -63
  86. jaseci/extens/svc/storage_svc.py +0 -193
  87. jaseci/extens/svc/stripe_svc.py +0 -51
  88. jaseci/extens/svc/task_svc.py +0 -155
  89. jaseci/extens/svc/tasks.py +0 -302
  90. jaseci/jac/__init__.py +0 -0
  91. jaseci/jac/interpreter/__init__.py +0 -0
  92. jaseci/jac/interpreter/architype_interp.py +0 -214
  93. jaseci/jac/interpreter/interp.py +0 -1783
  94. jaseci/jac/interpreter/sentinel_interp.py +0 -257
  95. jaseci/jac/interpreter/tests/__init__.py +0 -0
  96. jaseci/jac/interpreter/tests/test_interp.py +0 -42
  97. jaseci/jac/interpreter/walker_interp.py +0 -248
  98. jaseci/jac/ir/__init__.py +0 -0
  99. jaseci/jac/ir/ast.py +0 -73
  100. jaseci/jac/ir/ast_builder.py +0 -249
  101. jaseci/jac/ir/jac_code.py +0 -152
  102. jaseci/jac/ir/passes/__init__.py +0 -6
  103. jaseci/jac/ir/passes/ast_prune_pass.py +0 -9
  104. jaseci/jac/ir/passes/codegen_pass.py +0 -244
  105. jaseci/jac/ir/passes/ir_pass.py +0 -29
  106. jaseci/jac/ir/passes/printer_pass.py +0 -23
  107. jaseci/jac/ir/passes/pt_prune_pass.py +0 -29
  108. jaseci/jac/ir/passes/schedule.py +0 -23
  109. jaseci/jac/ir/passes/stats_pass.py +0 -16
  110. jaseci/jac/jac.g4 +0 -450
  111. jaseci/jac/jac_parse/__init__.py +0 -0
  112. jaseci/jac/jac_parse/jacLexer.py +0 -809
  113. jaseci/jac/jac_parse/jacListener.py +0 -853
  114. jaseci/jac/jac_parse/jacParser.py +0 -9192
  115. jaseci/jac/jac_set.py +0 -119
  116. jaseci/jac/jsci_vm/__init__.py +0 -0
  117. jaseci/jac/jsci_vm/disasm.py +0 -94
  118. jaseci/jac/jsci_vm/inst_ptr.py +0 -31
  119. jaseci/jac/jsci_vm/machine.py +0 -188
  120. jaseci/jac/jsci_vm/op_codes.py +0 -82
  121. jaseci/jac/jsci_vm/tests/__init__.py +0 -0
  122. jaseci/jac/jsci_vm/tests/test_codegen.py +0 -31
  123. jaseci/jac/machine/__init__.py +0 -0
  124. jaseci/jac/machine/jac_scope.py +0 -85
  125. jaseci/jac/machine/jac_value.py +0 -226
  126. jaseci/jac/machine/machine_state.py +0 -383
  127. jaseci/jac/tests/__init__.py +0 -0
  128. jaseci/jac/tests/book_code.py +0 -624
  129. jaseci/jac/tests/test_book.py +0 -380
  130. jaseci/jac/tests/test_lang_14.py +0 -49
  131. jaseci/jsorc/__init__.py +0 -7
  132. jaseci/jsorc/jsorc.py +0 -642
  133. jaseci/jsorc/jsorc_settings.py +0 -211
  134. jaseci/jsorc/jsorc_utils.py +0 -298
  135. jaseci/jsorc/live_actions.py +0 -364
  136. jaseci/jsorc/manifests/__init__.py +0 -0
  137. jaseci/jsorc/manifests/database.yaml +0 -109
  138. jaseci/jsorc/manifests/elastic.yaml +0 -6024
  139. jaseci/jsorc/manifests/prometheus.yaml +0 -1383
  140. jaseci/jsorc/manifests/redis.yaml +0 -64
  141. jaseci/jsorc/memory.py +0 -258
  142. jaseci/jsorc/redis.py +0 -139
  143. jaseci/jsorc/remote_actions.py +0 -157
  144. jaseci/jsorc/tests/__init__.py +0 -0
  145. jaseci/jsorc/tests/test_actions.py +0 -542
  146. jaseci/jsorc/tests/test_jsorc.py +0 -112
  147. jaseci/prim/__init__.py +0 -0
  148. jaseci/prim/ability.py +0 -93
  149. jaseci/prim/architype.py +0 -89
  150. jaseci/prim/edge.py +0 -172
  151. jaseci/prim/element.py +0 -233
  152. jaseci/prim/graph.py +0 -26
  153. jaseci/prim/master.py +0 -64
  154. jaseci/prim/node.py +0 -532
  155. jaseci/prim/obj_mixins.py +0 -235
  156. jaseci/prim/sentinel.py +0 -281
  157. jaseci/prim/super_master.py +0 -31
  158. jaseci/prim/walker.py +0 -261
  159. jaseci/svc/__init__.py +0 -0
  160. jaseci/tests/__init__.py +0 -0
  161. jaseci/tests/infer.py +0 -39
  162. jaseci/tests/jac_test_code.py +0 -1293
  163. jaseci/tests/jac_test_progs.py +0 -774
  164. jaseci/tests/test_core.py +0 -153
  165. jaseci/tests/test_jac.py +0 -824
  166. jaseci/tests/test_node.py +0 -89
  167. jaseci/tests/test_progs.py +0 -702
  168. jaseci/tests/test_stack.py +0 -220
  169. jaseci/tests/test_stripe.py +0 -225
  170. jaseci/utils/__init__.py +0 -0
  171. jaseci/utils/actions/__init__.py +0 -0
  172. jaseci/utils/actions/actions_manager.py +0 -254
  173. jaseci/utils/actions/actions_optimizer.py +0 -516
  174. jaseci/utils/actions/actions_state.py +0 -95
  175. jaseci/utils/file_handler.py +0 -171
  176. jaseci/utils/gprof2dot.py +0 -3786
  177. jaseci/utils/id_list.py +0 -168
  178. jaseci/utils/json_handler.py +0 -70
  179. jaseci/utils/log_utils.py +0 -57
  180. jaseci/utils/test_core.py +0 -62
  181. jaseci/utils/utils.py +0 -387
  182. jaseci-1.4.2.5.dist-info/LICENSE +0 -21
  183. jaseci-1.4.2.5.dist-info/METADATA +0 -39
  184. jaseci-1.4.2.5.dist-info/RECORD +0 -184
  185. jaseci-1.4.2.5.dist-info/entry_points.txt +0 -3
  186. jaseci-1.4.2.5.dist-info/top_level.txt +0 -1
@@ -1,316 +0,0 @@
1
- """
2
- JSORC APIs
3
- """
4
- import json
5
- from json import dumps
6
- from time import time
7
-
8
- from jaseci.jsorc.jsorc import JsOrc
9
- from jaseci.jsorc.jsorc_utils import convert_yaml_manifest, ManifestType
10
- from jaseci.utils.utils import logger
11
- from jaseci.extens.svc.kube_svc import KubeService
12
- from jaseci.utils.file_handler import FileHandler
13
- from jaseci.utils.actions.actions_manager import ActionManager
14
-
15
- from jaseci.extens.api.interface import Interface
16
-
17
-
18
- class JsOrcApi:
19
- """
20
- API for managing JsOrc
21
- """
22
-
23
- @Interface.admin_api()
24
- def load_yaml(
25
- self,
26
- files: list,
27
- manifest_type: str = "DEDICATED",
28
- manual_namespace: str = "default",
29
- ):
30
- """
31
- applying list of yaml files without associating to any modules/services
32
- """
33
-
34
- try:
35
- kube = JsOrc.svc("kube").poke(KubeService)
36
-
37
- res = {}
38
- for file in files:
39
- file: FileHandler = self._h.get_file_handler(file)
40
- file.open()
41
-
42
- for kind, confs in kube.resolve_manifest(
43
- convert_yaml_manifest(file.buffer),
44
- ManifestType[manifest_type],
45
- manual_namespace,
46
- ).items():
47
- for name, conf in confs.items():
48
- metadata: dict = conf["metadata"]
49
- kube.create(
50
- kind,
51
- metadata["name"],
52
- conf,
53
- metadata.get("namespace"),
54
- )
55
- if not res.get(kind):
56
- res[kind] = {}
57
- res[kind].update({name: conf})
58
-
59
- file.close()
60
- return res
61
- except Exception:
62
- logger.exception("Error loading yaml!")
63
- return {"message": "load_yaml is not supported on non automated JsOrc!"}
64
-
65
- @Interface.admin_api(cli_args=["service"])
66
- def apply_yaml(self, service: str, file: list, unsafe_paraphrase: str = ""):
67
- """
68
- apply manifest yaml to specific service
69
- """
70
- svc = JsOrc.svc(service)
71
-
72
- new_config = {}
73
-
74
- config_version = str(time())
75
-
76
- file: FileHandler = self._h.get_file_handler(file[0])
77
- file.open()
78
-
79
- for kind, confs in convert_yaml_manifest(file.buffer).items():
80
- for name, conf in confs.items():
81
- metadata = conf["metadata"]
82
- labels: dict = metadata.get("labels", {})
83
- if not labels.get("config_version"):
84
- labels["config_version"] = config_version
85
- metadata["labels"] = labels
86
-
87
- if not new_config.get(kind):
88
- new_config[kind] = {}
89
- new_config[kind].update({name: conf})
90
-
91
- file.close()
92
-
93
- if unsafe_paraphrase == JsOrc.settings("UNSAFE_PARAPHRASE"):
94
- new_config["__UNSAFE_PARAPHRASE__"] = unsafe_paraphrase
95
-
96
- self._h.save_glob(svc.source["manifest"], dumps(new_config))
97
- JsOrc.add_regeneration_queue(service)
98
-
99
- return new_config
100
-
101
- @Interface.admin_api()
102
- def jsorc_refresh(self):
103
- """
104
- refreshing jsorc's config.
105
- """
106
-
107
- JsOrc.configure()
108
-
109
- return {
110
- "running_interval": JsOrc._running_interval,
111
- "config": JsOrc._config,
112
- }
113
-
114
- @Interface.admin_api(cli_args=["name"])
115
- def service_info(self, name: str):
116
- """
117
- getting service's info.
118
- """
119
-
120
- # will throw exception if not existing
121
- return JsOrc.svc(name).info()
122
-
123
- @Interface.admin_api(cli_args=["name"])
124
- def service_config_set(self, name: str, config: dict):
125
- """
126
- Set a service config
127
- """
128
- return JsOrc.svc_conf_set(name, config, self._h)
129
-
130
- @Interface.admin_api(cli_args=["name"])
131
- def service_refresh(self, name: str):
132
- """
133
- refreshing service's config. If JsOrc is not automated, service will restart else JsOrc will handle the rest
134
- """
135
-
136
- # will throw exception if not existing
137
- JsOrc.svc_reset(name)
138
-
139
- return {"success": True}
140
-
141
- @Interface.admin_api(cli_args=["name"])
142
- def service_call(self, svc: str, attrs: list = []):
143
- """
144
- temporary api for retreiving/calling attributes of specific instance.
145
- """
146
-
147
- svc = JsOrc.svc(svc)
148
-
149
- if not svc:
150
- return "Service (svc) field is required!"
151
-
152
- if not attrs:
153
- return "Attributes (attrs) field is required!"
154
-
155
- res = svc
156
- for at in attrs:
157
- attr = at.get("attr", False)
158
- if attr:
159
- res = getattr(res, attr)
160
-
161
- if at.get("callable", False):
162
- args = at.get("args", [])
163
- kwargs = at.get("kwargs", {})
164
- res = res(*args, **kwargs)
165
-
166
- try:
167
- # test if json serializable
168
- json.dumps(res)
169
- return res
170
- except Exception:
171
- return {"error": f"Not JSON Serializable! class {res.__class__.__name__}"}
172
-
173
- @Interface.admin_api(cli_args=["name"])
174
- def jsorc_actions_load(self, name: str, mode: str):
175
- """
176
- Load an action as remote or local mode through JSORC.
177
- JSORC will load the corresponding module or start a microservice if needed.
178
- Return the current status of the action.
179
- """
180
- action_manager = JsOrc.get("action_manager", ActionManager)
181
- action_manager.load_actions(name, mode)
182
- status = action_manager.get_actions_status(name)
183
-
184
- return {"success": True, "action_status": status}
185
-
186
- @Interface.admin_api(cli_args=["name"])
187
- def jsorc_actions_status(self, name: str):
188
- """
189
- Get the current status of an action
190
- """
191
- status = JsOrc.get("action_manager", ActionManager).get_actions_status(name)
192
- return {"success": True, "action_status": status}
193
-
194
- @Interface.admin_api(cli_args=["name"])
195
- def jsorc_actions_unload(
196
- self, name: str, mode: str = "auto", retire_svc: bool = True
197
- ):
198
- """
199
- Unload an action through JSORC.
200
- If retire_svc is set to True (true by default), it will also retire the corresponding microservice.
201
- """
202
- res = JsOrc.get("action_manager", ActionManager).unload_actions(
203
- name, mode, retire_svc
204
- )
205
- return {"success": res[0], "message": res[1]}
206
-
207
- @Interface.admin_api(cli_args=["config", "name"])
208
- def jsorc_actions_config(self, config: str, name: str):
209
- """
210
- Loading the config of an action module
211
- config: name of the ai kit package (e.g. jac_nlp.config, jac_vision.config)
212
- name: name of the action module (e.g. use_enc, bi_enc)
213
- """
214
- res = JsOrc.get("action_manager", ActionManager).load_action_config(
215
- config, name
216
- )
217
- return {"success": res}
218
-
219
- @Interface.admin_api()
220
- def jsorc_trackact_start(self):
221
- """ "
222
- Instruct JSORC to start tracking any changes in actions state
223
- """
224
- JsOrc.get("action_manager", ActionManager).actions_tracking_start()
225
- return {"success": True}
226
-
227
- @Interface.admin_api()
228
- def jsorc_trackact_stop(self):
229
- """ "
230
- Instruct JSORC to start tracking any changes in actions state
231
- """
232
- return JsOrc.get("action_manager", ActionManager).actions_tracking_stop()
233
-
234
- @Interface.admin_api()
235
- def jsorc_benchmark_start(self):
236
- """
237
- Tell JSORC to start collecting request performance metrics
238
- """
239
- JsOrc.get("action_manager", ActionManager).benchmark_start()
240
- return {"success": True}
241
-
242
- @Interface.admin_api()
243
- def jsorc_benchmark_report(self):
244
- """
245
- Report the collected request performance metrics of the currently ongoing benchmark
246
- """
247
- return JsOrc.get("action_manager", ActionManager).benchmark_report()
248
-
249
- @Interface.admin_api()
250
- def jsorc_benchmark_stop(self, report: bool = True):
251
- """
252
- End the benchmark period and report performance metrics
253
- """
254
- return JsOrc.get("action_manager", ActionManager).benchmark_stop(report)
255
-
256
- @Interface.admin_api()
257
- def jsorc_tracksys_start(self):
258
- """
259
- Ask JSORC to start tracking the state of the system as observed by JSORC on every interval.
260
- """
261
- JsOrc.get("action_manager", ActionManager).state_tracking_start()
262
- return {"success": True}
263
-
264
- @Interface.admin_api()
265
- def jsorc_tracksys_report(self):
266
- """
267
- Report the tracked system states so far
268
- """
269
- return JsOrc.get("action_manager", ActionManager).state_tracking_report()
270
-
271
- @Interface.admin_api()
272
- def jsorc_tracksys_stop(self):
273
- """
274
- Stop state tracking for JSORC
275
- """
276
- return JsOrc.get("action_manager", ActionManager).state_tracking_stop()
277
-
278
- @Interface.admin_api()
279
- def jsorc_actionpolicy_set(self, policy_name: str, policy_params: dict = {}):
280
- """
281
- Set an action optimization policy for JSORC
282
- """
283
- res = JsOrc.get("action_manager", ActionManager).set_action_policy(
284
- policy_name, policy_params
285
- )
286
- if res is True:
287
- return {
288
- "success": True,
289
- "message": f"Action optimization policy configured as {policy_name} with params {policy_params}",
290
- }
291
- else:
292
- return {"success": False, "message": res}
293
-
294
- @Interface.admin_api()
295
- def jsorc_actionpolicy_get(self):
296
- """
297
- Get the current active action optimization policy
298
- """
299
- policy = JsOrc.get("action_manager", ActionManager).get_action_policy()
300
- return {"success": True, "policy": policy}
301
-
302
- @Interface.admin_api()
303
- def jsorc_loadtest(
304
- self,
305
- test: str,
306
- experiment: str = "",
307
- mem: int = 0,
308
- policy: str = "all_local",
309
- experiment_duration: int = 180,
310
- eval_phase: int = 10,
311
- perf_phase: int = 100,
312
- ):
313
- """
314
- load test API. overwritten in jaseci_serv
315
- """
316
- pass
@@ -1,89 +0,0 @@
1
- """
2
- Logger api as a mixin
3
- """
4
- import re
5
- from jaseci.extens.api.interface import Interface
6
- from jaseci.utils.log_utils import parse_logs
7
- from jaseci.utils.utils import logger, app_logger, logs
8
- from jaseci.utils.utils import connect_logger_handler
9
- from logging.handlers import HTTPHandler
10
-
11
-
12
- class LoggerApi:
13
- """
14
- APIs for Jaseci Logging configuration
15
- """
16
-
17
- @Interface.admin_api(cli_args=["host"])
18
- def logger_http_connect(self, host: str, port: int, url: str, log: str = "all"):
19
- """
20
- Connects internal logging to http(s) (log msgs sent via POSTs)
21
- Valid log params: {sys, app, all }
22
- """
23
- num = 0
24
- if log == "sys" or log == "all":
25
- connect_logger_handler(
26
- logger, HTTPHandler(host=f"{host}:{port}", url=url, method="POST")
27
- )
28
- num += 1
29
- if log == "app" or log == "all":
30
- connect_logger_handler(
31
- app_logger, HTTPHandler(host=f"{host}:{port}", url=url, method="POST")
32
- )
33
- num += 1
34
- return [f"{num} http handlers added!"]
35
-
36
- @Interface.admin_api()
37
- def logger_http_clear(self, log: str = "all"):
38
- """
39
- Connects internal logging to http(s) (log msgs sent via POSTs)
40
- Valid log params: {sys, app, all }
41
- """
42
- num = 0
43
- if log == "sys" or log == "all":
44
- for i in logger.handlers:
45
- if i.__class__.__name__ == "HTTPHandler":
46
- logger.removeHandler(i)
47
- num += 1
48
- if log == "app" or log == "all":
49
- for i in app_logger.handlers:
50
- if i.__class__.__name__ == "HTTPHandler":
51
- app_logger.removeHandler(i)
52
- num += 1
53
- return [f"{num} http handlers removed!"]
54
-
55
- @Interface.admin_api()
56
- def logger_get(self, search: str = "", level: str = None):
57
- """Get logs across loggers"""
58
- result = []
59
- for log in logs.getvalue().splitlines():
60
- # skip logs produced by calling this endpoint
61
- if re.search("Incoming call to logger_get", log):
62
- continue
63
-
64
- if search:
65
- if re.search(search, log):
66
- result.append(log)
67
- continue
68
-
69
- result.append(log)
70
-
71
- result = parse_logs(result)
72
-
73
- if level:
74
- result = list(filter(lambda item: level and item["level"] == level, result))
75
-
76
- return result
77
-
78
- @Interface.admin_api()
79
- def logger_list(self):
80
- """
81
- Check active loggers
82
- """
83
- core = []
84
- app = []
85
- for i in logger.handlers:
86
- core.append(str(type(i)))
87
- for i in app_logger.handlers:
88
- app.append(str(type(i)))
89
- return {"core": core, "app": app}
@@ -1,133 +0,0 @@
1
- """
2
- Master api as a mixin
3
- """
4
- from jaseci.extens.api.interface import Interface
5
- from jaseci.utils.id_list import IdList
6
- import uuid
7
-
8
-
9
- class MasterApi:
10
- """
11
- Master APIs for users creating and managing groups of sub users
12
-
13
- These APIs
14
- """
15
-
16
- def __init__(self, head_master):
17
- self.caller = None
18
- self.head_master_id = head_master
19
- self.sub_master_ids = IdList(self)
20
-
21
- @Interface.private_api(cli_args=["name"])
22
- def master_create(
23
- self,
24
- name: str,
25
- password: str = "",
26
- global_init: str = "",
27
- global_init_ctx: dict = {},
28
- other_fields: dict = {},
29
- ):
30
- """
31
- Create a master instance and return root node master object
32
-
33
- other_fields used for additional feilds for overloaded interfaces
34
- (i.e., Dango interface)
35
- """
36
- if self.sub_master_ids.has_obj_by_name(name):
37
- return {"response": f"{name} already exists", "success": False}
38
- ret = {}
39
- mast = self.user_creator(name, password, other_fields)
40
- ret["user"] = mast.serialize()
41
- if len(global_init):
42
- ret["global_init"] = self.user_global_init(
43
- mast, global_init, global_init_ctx
44
- )
45
- self.take_ownership(mast)
46
- ret["success"] = True
47
- return ret
48
-
49
- @Interface.private_api(cli_args=["name"])
50
- def master_get(self, name: str, mode: str = "default", detailed: bool = False):
51
- """
52
- Return the content of the master with mode
53
- Valid modes: {default, }
54
- """
55
- mas = self.sub_master_ids.get_obj_by_name(name)
56
- if not mas:
57
- return {"response": f"{name} not found"}
58
- else:
59
- return mas.serialize(detailed=detailed)
60
-
61
- @Interface.private_api()
62
- def master_list(self, detailed: bool = False):
63
- """
64
- Provide complete list of all master objects (list of root node objects)
65
- """
66
- masts = []
67
- for i in self.sub_master_ids.obj_list():
68
- masts.append(i.serialize(detailed=detailed))
69
- return masts
70
-
71
- @Interface.private_api(cli_args=["name"])
72
- def master_active_set(self, name: str):
73
- """
74
- Sets the default master master should use
75
- NOTE: Specail handler included in general_interface_to_api
76
- """
77
- mas = self.sub_master_ids.get_obj_by_name(name)
78
- if not mas:
79
- return {"response": f"{name} not found"}
80
- self.caller = mas.jid
81
- return {"response": f"You are now {mas.name}"}
82
-
83
- @Interface.private_api()
84
- def master_active_unset(self):
85
- """
86
- Unsets the default sentinel master should use
87
- """
88
- self.caller = None
89
- return {"response": f"You are now {self.name}"}
90
-
91
- @Interface.private_api()
92
- def master_active_get(self, detailed: bool = False):
93
- """
94
- Returns the default master master is using
95
- """
96
- if self.caller:
97
- return self._h.get_obj(self._m_id, self.caller).serialize(detailed=detailed)
98
- else:
99
- return self.serialize(detailed=detailed)
100
-
101
- @Interface.private_api()
102
- def master_self(self, detailed: bool = False):
103
- """
104
- Returns the masters object
105
- """
106
- return self.serialize(detailed=detailed)
107
-
108
- @Interface.private_api(cli_args=["name"])
109
- def master_delete(self, name: str):
110
- """
111
- Permanently delete master with given id
112
- """
113
- if not self.sub_master_ids.has_obj_by_name(name):
114
- return {"response": f"{name} not found", "success": False}
115
- self.sub_master_ids.destroy_obj_by_name(name)
116
- self.user_destroyer(name)
117
- return {"response": f"{name} has been destroyed", "success": True}
118
-
119
- def take_ownership(self, m):
120
- """
121
- Assumes owenership over another master
122
- """
123
- m.head_master_id = self.jid
124
- m.give_access(self)
125
- m.save()
126
- self.sub_master_ids.add_obj(m)
127
-
128
- def destroy(self):
129
- """
130
- Destroys self from memory and persistent storage
131
- """
132
- for i in self.sub_master_ids.obj_list():
133
- i.destroy()
@@ -1,101 +0,0 @@
1
- """
2
- Object api as a mixin
3
- """
4
- from jaseci.extens.api.interface import Interface
5
- from jaseci.prim.element import Element
6
-
7
-
8
- class ObjectApi:
9
- """Object APIs for generalized operations on Jaseci objects
10
-
11
- ...
12
- """
13
-
14
- def __init__(self):
15
- self.perm_default = "private"
16
- self._valid_perms = ["public", "private", "read_only"]
17
-
18
- @Interface.private_api(cli_args=["name"])
19
- def global_get(self, name: str):
20
- """
21
- Get a global var
22
- """
23
- return {"value": self._h.get_glob(name)}
24
-
25
- @Interface.private_api(cli_args=["obj"])
26
- def object_get(self, obj: Element, depth: int = 0, detailed: bool = False):
27
- """Returns object details for any Jaseci object."""
28
- ret = obj.serialize(deep=depth, detailed=detailed)
29
- return ret
30
-
31
- @Interface.private_api(cli_args=["obj"])
32
- def object_set(
33
- self, obj: Element, ctx: dict, depth: int = 0, detailed: bool = False
34
- ):
35
- """Update a field in an object."""
36
- if "jid" in ctx:
37
- del ctx["jid"]
38
- for i in ctx.keys():
39
- if i in dir(obj) and not callable(getattr(obj, i)):
40
- setattr(obj, i, ctx[i])
41
- return obj.serialize(deep=depth, detailed=detailed)
42
-
43
- @Interface.private_api(cli_args=["obj"])
44
- def object_perms_get(self, obj: Element):
45
- """Returns object access mode for any Jaseci object."""
46
- return {"access": obj.j_access}
47
-
48
- @Interface.private_api(cli_args=["obj"])
49
- def object_perms_set(self, obj: Element, mode: str):
50
- """Sets object access mode for any Jaseci object."""
51
- ret = {}
52
- if mode not in self._valid_perms:
53
- ret["success"] = False
54
- ret["response"] = f"{mode} not valid, must be in {self._valid_perms}"
55
- else:
56
- getattr(obj, "make_" + mode)()
57
- ret["success"] = True
58
- ret["response"] = f"{obj} set to {mode}"
59
- return ret
60
-
61
- @Interface.private_api(cli_args=["mode"])
62
- def object_perms_default(self, mode: str):
63
- """Sets object access mode for any Jaseci object."""
64
- ret = {}
65
- if mode not in self._valid_perms:
66
- ret["success"] = False
67
- ret["response"] = f"{mode} not valid, must be in {self._valid_perms}"
68
- else:
69
- self.perm_default = mode
70
- ret["success"] = True
71
- ret["response"] = f"Default access for future objects set to {mode}"
72
- return ret
73
-
74
- @Interface.private_api(cli_args=["obj"])
75
- def object_perms_grant(self, obj: Element, mast: Element, read_only: bool = False):
76
- """Grants another user permissions to access a Jaseci object."""
77
- granted = obj.give_access(mast, read_only=read_only)
78
- ret = {"success": granted}
79
- if granted:
80
- ret["response"] = f"Access to {obj} granted to {mast}"
81
- else:
82
- ret["response"] = f"Cannot grant {mast} access to {obj}"
83
- return ret
84
-
85
- @Interface.private_api(cli_args=["obj"])
86
- def object_perms_revoke(self, obj: Element, mast: Element):
87
- """Remove permissions for user to access a Jaseci object."""
88
- revoked = obj.remove_access(mast)
89
- ret = {"success": revoked}
90
- if revoked:
91
- ret["response"] = f"Access to {obj} revoked from {mast}"
92
- else:
93
- ret["response"] = f"{mast} did not have access to {obj}"
94
- return ret
95
-
96
- @Interface.public_api()
97
- def info(self):
98
- """Provide information about this instance of Jaseci"""
99
- from jaseci import __version__, __creator__, __url__
100
-
101
- return {"Version": __version__, "Creator": __creator__, "URL": __url__}