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