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,139 +0,0 @@
1
- """
2
- Alias api as a mixin
3
- """
4
- from jaseci.extens.api.interface import Interface
5
-
6
-
7
- class AliasAPI:
8
- """
9
- Alias APIs for creating nicknames for UUIDs and other long strings
10
-
11
- The alias set of APIs provide a set of `alias' management functions for
12
- creating and managing aliases for long strings such as UUIDs. If an alias'
13
- name is used as a parameter value in any API call, that parameter will see
14
- the alias' value instead. Given that references to all sentinels, walkers,
15
- nodes, etc. utilize UUIDs, it becomes quite useful to create pneumonic
16
- names for them. Also, when registering sentinels, walkers, architype
17
- handy aliases are automatically generated. These generated aliases can
18
- then be managed using the alias APIs. Keep in mind that whenever an alias
19
- is created, all parameter values submitted to any API with the alias name
20
- will be replaced internally by its value. If you get in a bind, simply use
21
- the clear or delete alias APIs.
22
- """
23
-
24
- def __init__(self):
25
- self.alias_map = {}
26
-
27
- @Interface.private_api(cli_args=["name"])
28
- def alias_register(self, name: str, value: str):
29
- """Create string to string alias mapping that caller can use.
30
-
31
- Either create new alias string to string mappings or replace
32
- an existing mappings of a given alias name. Once registered the
33
- alias mapping is instantly active.
34
-
35
- Args:
36
- name (str): The name for the alias created by caller.
37
- value (str): The value for that name to map to (i.e., UUID)
38
-
39
- Returns:
40
- json: Fields include
41
- 'response': Message of mapping that was created
42
- """
43
- self.alias_map[name] = value
44
- self.save()
45
- return {"response": f"Alias from '{name}' to '{value}' set!"}
46
-
47
- @Interface.private_api()
48
- def alias_list(self):
49
- """List all string to string alias that caller can use.
50
-
51
- Returns dictionary object of name to value mappings currently active.
52
- This API is quite useful to track not only the aliases the caller
53
- creates, but also the aliases automatically created as various Jaseci
54
- objects (walkers, architypes, sentinels, etc.) are created, changed,
55
- or destroyed.
56
-
57
- Returns:
58
- dictionary: Dictionary of active mappings
59
- 'name': 'value'
60
- ...
61
- """
62
- return self.alias_map
63
-
64
- @Interface.private_api(cli_args=["name"])
65
- def alias_delete(self, name: str):
66
- """Delete an active string to string alias mapping.
67
-
68
- Removes a specific alias by its name. Only the alias is removed no
69
- actual objects are affected. Future uses of this name will not be
70
- mapped.
71
-
72
- Args:
73
- name (str): The name for the alias to be removed from caller.
74
-
75
- Returns:
76
- dictionary: Fields include
77
- 'response': Message of success/failure to remove alias
78
- 'success': True/False based on delete actually happening
79
- """
80
- if name in self.alias_map.keys():
81
- del self.alias_map[name]
82
- self.save()
83
- return {"response": f"Alias {name} successfully deleted", "success": True}
84
- else:
85
- return {"response": f"Alias {name} not present", "success": False}
86
-
87
- @Interface.private_api()
88
- def alias_clear(self):
89
- """Remove all string to string alias that client can use.
90
-
91
- Removes a all aliases. No actual objects are affected. Aliases will
92
- continue to be automatically generated when creating other Jaseci
93
- objects.
94
-
95
- Returns:
96
- dictionary: Fields include
97
- 'response': Message of number of alias removed
98
- 'removed': Number of aliases removed
99
- """
100
- n = len(self.alias_map.keys())
101
- self.alias_map = {}
102
- self.save()
103
- return {"response": f"All {n} aliases deleted", "removed": n}
104
-
105
- def extract_snt_aliases(self, snt):
106
- """
107
- Extract and register all aliases from sentinel
108
- """
109
- self.alias_register(f"sentinel:{snt.name}", snt.jid)
110
- for i in snt.arch_ids.obj_list():
111
- self.extract_arch_aliases(snt, i)
112
- self.save()
113
-
114
- def extract_arch_aliases(self, snt, arch):
115
- """
116
- Extract and register all aliases from architype
117
- """
118
- if arch.kind == "walker":
119
- self.alias_register(f"{snt.name}:walker:{arch.name}", arch.jid)
120
- else:
121
- self.alias_register(f"{snt.name}:architype:{arch.name}", arch.jid)
122
-
123
- def remove_snt_aliases(self, snt):
124
- """
125
- Extract and register all aliases from sentinel
126
- """
127
- self.alias_delete(f"sentinel:{snt.name}")
128
- for i in snt.arch_ids.obj_list():
129
- self.remove_arch_aliases(snt, i)
130
- self.save()
131
-
132
- def remove_arch_aliases(self, snt, arch):
133
- """
134
- Extract and register all aliases from architype
135
- """
136
- if arch.kind == "walker":
137
- self.alias_delete(f"{snt.name}:walker:{arch.name}")
138
- else:
139
- self.alias_delete(f"{snt.name}:architype:{arch.name}")
@@ -1,196 +0,0 @@
1
- """
2
- Architype api functions as a mixin
3
- """
4
- from jaseci.extens.api.interface import Interface
5
- from jaseci.prim.architype import Architype
6
- from jaseci.prim.sentinel import Sentinel
7
- from jaseci.utils.utils import b64decode_str
8
-
9
-
10
- class ArchitypeApi:
11
- """Architype APIs for creating and managing Jaseci architypes
12
-
13
- The architype set of APIs allow for the addition and removing of
14
- architypes. Given a Jac implementation of an architype these APIs are
15
- designed for creating, compiling, and managing architypes that can be
16
- used by Jaseci. There are two ways to add an architype to Jaseci, either
17
- through the management of sentinels using the sentinel API, or by
18
- registering independent architypes with these architype APIs. These
19
- APIs are also used for inspecting and managing existing arichtypes that
20
- a Jaseci instance is aware of.
21
- """
22
-
23
- @Interface.private_api(cli_args=["code"])
24
- def architype_register(
25
- self, code: str, encoded: bool = False, snt: Sentinel = None
26
- ):
27
- """Create an architype based on the code passed and return object.
28
-
29
- This register API allows for the creation or replacement/update of
30
- an architype that can then be used by walkers in their interactions
31
- of graphs. The code argument takes Jac source code for the single
32
- architype. To load multiple architypes and walkers at the same time,
33
- use sentinel register API.
34
-
35
- Args:
36
- code (str): The text (or filename) for an architypes Jac code
37
- encoded (bool): True/False flag as to whether code is encode
38
- in base64
39
- snt (uuid): The UUID of the sentinel to be the owner of this
40
- architype
41
-
42
- Returns:
43
- json: Fields include
44
- 'architype': Architype object if created otherwise null
45
- 'success': True/False whether register was successful
46
- 'errors': List of errors if register failed
47
- 'response': Message on outcome of register call
48
- """
49
- ret = {"architype": None, "success": False, "errors": []}
50
- if encoded:
51
- code = b64decode_str(code)
52
- arch = snt.register_architype(code)
53
- if arch:
54
- self.extract_arch_aliases(snt, arch)
55
- ret["architype"] = arch.serialize()
56
- ret["success"] = True
57
- ret["response"] = f"Successfully created {arch.name} architype"
58
- else:
59
- ret["errors"] = snt.errors
60
- ret["response"] = "Errors occured"
61
- return ret
62
-
63
- @Interface.private_api()
64
- def architype_get(
65
- self, arch: Architype, mode: str = "default", detailed: bool = False
66
- ):
67
- """Get an architype rendered with specific mode
68
-
69
- Args:
70
- arch (uuid): The architype being accessed
71
- mode (str): Valid modes: {default, code, ir, }
72
- detailed (bool): Flag to give summary or complete set of fields
73
-
74
- Returns:
75
- json: Fields include (depends on mode)
76
- 'code': Formal source code for architype
77
- 'ir': Intermediate representation of architype
78
- 'architype': Architype object print
79
- """
80
- # ternary python example
81
- a = 1 if True else 2
82
-
83
- if mode == "code":
84
- try:
85
- return {"code": arch.get_jac_ast().src}
86
- except AttributeError:
87
- return {"code": "No code available for architype"}
88
- elif mode == "ir":
89
- return {"ir": arch.ir_dict()}
90
- else:
91
- return {"architype": arch.serialize(detailed=detailed)}
92
-
93
- @Interface.private_api(cli_args=["code"])
94
- def architype_set(self, arch: Architype, code: str, mode: str = "default"):
95
- """Set code/ir for a architype
96
-
97
- Args:
98
- arch (uuid): The architype being set
99
- code (str): The text (or filename) for an architypes Jac code/ir
100
- mode (str): Valid modes: {default, code, ir, }
101
-
102
- Returns:
103
- json: Fields include (depends on mode)
104
- 'success': True/False whether set was successful
105
- 'errors': List of errors if set failed
106
- 'response': Message on outcome of set call
107
- """
108
- if mode == "code" or mode == "default":
109
- arch.register(code)
110
- elif mode == "ir":
111
- arch.apply_ir(code)
112
- else:
113
- return {
114
- "response": f"Invalid mode to set {arch}",
115
- "success": False,
116
- "errors": [],
117
- }
118
- if arch.is_active:
119
- return {
120
- "response": f"{arch} registered and active!",
121
- "success": True,
122
- "errors": [],
123
- }
124
- else:
125
- return {
126
- "response": f"{arch} registered and active!",
127
- "success": True,
128
- "errors": arch.errors,
129
- }
130
-
131
- @Interface.private_api()
132
- def architype_list(
133
- self, snt: Sentinel = None, kind: str = None, detailed: bool = False
134
- ):
135
- """List architypes known to sentinel
136
-
137
- Args:
138
- snt (uuid): The sentinel for which to list its architypes
139
- detailed (bool): Flag to give summary or complete set of fields
140
- kind (str): Architype kind used to narrow the result set
141
-
142
- Returns:
143
- json: List of architype objects
144
- """
145
- archs = []
146
-
147
- for i in snt.arch_ids.obj_list():
148
- if not kind:
149
- archs.append(i.serialize(detailed=detailed))
150
- elif i.kind == kind:
151
- archs.append(i.serialize(detailed=detailed))
152
-
153
- return archs
154
-
155
- @Interface.private_api()
156
- def architype_count(self, snt: Sentinel = None, kind: str = None):
157
- """Return count of architypes
158
-
159
- Args:
160
- snt (uuid): The sentinel for which to list its architypes
161
- detailed (bool): Flag to give summary or complete set of fields
162
- kind (str): Architype kind used to narrow the result set from which the count is evaluated
163
-
164
- Returns:
165
- int: Count of architype objects
166
- """
167
- arch_objects = snt.arch_ids.obj_list()
168
-
169
- if kind:
170
- arch_objects = list(filter(lambda obj: obj.kind == kind, arch_objects))
171
-
172
- return len(arch_objects)
173
-
174
- @Interface.private_api(cli_args=["arch"])
175
- def architype_delete(self, arch: Architype, snt: Sentinel = None):
176
- """Permanently delete sentinel with given id
177
-
178
- Args:
179
- arch (uuid): The architype being set
180
- snt (uuid): The sentinel for which to list its architypes
181
-
182
- Returns:
183
- json: Fields include (depends on mode)
184
- 'success': True/False whether command was successful
185
- 'response': Message on outcome of command
186
- """
187
-
188
- if arch.jid not in snt.arch_ids:
189
- return {
190
- "response": f"Architype {arch} not in sentinel {snt}",
191
- "success": False,
192
- }
193
- self.remove_arch_aliases(snt, arch)
194
- archid = arch.jid
195
- snt.arch_ids.destroy_obj(arch)
196
- return {"response": f"Architype {archid} successfully deleted", "success": True}
@@ -1,129 +0,0 @@
1
- """
2
- Admin config api functions as a mixin
3
- """
4
-
5
- from typing import Optional
6
- from json import dumps, loads
7
- from jaseci.extens.api.interface import Interface
8
-
9
-
10
- class ConfigApi:
11
- """
12
- Admin config APIs
13
- Abstracted since there are no valid configs in core atm, see jaseci_serv
14
- to see how used.
15
- """
16
-
17
- def __init__(self, *args, **kwargs):
18
- self._valid_configs = [
19
- "CONFIG_EXAMPLE",
20
- "ACTION_SETS",
21
- "REDIS_CONFIG",
22
- "TASK_CONFIG",
23
- "MAIL_CONFIG",
24
- "PROME_CONFIG",
25
- "ELASTIC_CONFIG",
26
- "STRIPE_CONFIG",
27
- "KUBE_CONFIG",
28
- "JSORC_CONFIG",
29
- ]
30
-
31
- @Interface.admin_api(cli_args=["name"])
32
- def config_get(self, name: str, do_check: bool = True):
33
- """
34
- Get a config
35
- """
36
- if do_check and not self.name_check(name):
37
- return self.name_error(name)
38
- return self._h.get_glob(name)
39
-
40
- @Interface.admin_api(cli_args=["name"])
41
- def config_set(self, name: str, value: str or dict, do_check: bool = True):
42
- """
43
- Set a config
44
- """
45
- if do_check and not self.name_check(name):
46
- return self.name_error(name)
47
-
48
- if not (value is None) and type(value) is dict:
49
- value = dumps(value)
50
-
51
- self._h.save_glob(name, value)
52
- return [f"Config of '{name}' to '{value}' set!"]
53
-
54
- @Interface.admin_api(cli_args=["name"])
55
- def config_update(
56
- self,
57
- name: str,
58
- field_key: str,
59
- field_value: str
60
- or int
61
- or float
62
- or list
63
- or dict
64
- or bool
65
- or tuple
66
- or None, # json serializable types
67
- do_check: bool = True,
68
- ):
69
- """
70
- Update a key-value of a config
71
- """
72
- if do_check and not self.name_check(name):
73
- return self.name_error(name)
74
-
75
- conf = self._h.get_glob(name)
76
- try:
77
- conf = loads(conf)
78
- except Exception:
79
- return [
80
- f"Config {name} is not a dictionary. Uses config_set to set the value for this config."
81
- ]
82
- if field_key not in conf:
83
- return [f"Field {field_key} does not exist in config {name}"]
84
-
85
- conf[field_key] = field_value
86
- conf = dumps(conf)
87
- self._h.save_glob(name, conf)
88
- return [
89
- f"Config of '{name}' is updated with {field_key}:{field_value}. Current config value: {conf}"
90
- ]
91
-
92
- @Interface.admin_api()
93
- def config_list(self):
94
- """
95
- Check a config is present
96
- """
97
- return [v for v in self._h.list_glob() if v in self._valid_configs]
98
-
99
- @Interface.admin_api()
100
- def config_index(self):
101
- """
102
- List all valid configs
103
- """
104
- return self._valid_configs
105
-
106
- @Interface.admin_api(cli_args=["name"])
107
- def config_exists(self, name: str):
108
- """
109
- Check a config is present
110
- """
111
- return self._h.has_glob(name)
112
-
113
- @Interface.admin_api(cli_args=["name"])
114
- def config_delete(self, name: str, do_check: bool = True):
115
- """
116
- Delete a config
117
- """
118
- if do_check and not self.name_check(name):
119
- return self.name_error(name)
120
- self._h.destroy_glob(name)
121
- return [f"{name} Deleted."]
122
-
123
- def name_error(self, name):
124
- """Much used error output"""
125
- return [f"Config {name} not recognized, must be in {self._valid_configs}!"]
126
-
127
- def name_check(self, name):
128
- """Much used name check"""
129
- return name in self._valid_configs
@@ -1,84 +0,0 @@
1
- """
2
- Admin Global api functions as a mixin
3
- """
4
- from jaseci.extens.api.interface import Interface
5
- from jaseci.prim.sentinel import Sentinel
6
- import uuid
7
-
8
-
9
- class GlobalApi:
10
- """
11
- Admin global APIs
12
- """
13
-
14
- @Interface.admin_api(cli_args=["name"])
15
- def global_set(self, name: str, value: str):
16
- """
17
- Set a global
18
- """
19
- ret = {"success": True}
20
- if name == "GLOB_SENTINEL" or name in self._valid_configs:
21
- ret["response"] = f"{name} is sacred!"
22
- ret["success"] = False
23
- else:
24
- self._h.save_glob(name, value)
25
- ret["response"] = f"Global variable '{name}' to '{value}' set!"
26
- return ret
27
-
28
- @Interface.admin_api(cli_args=["name"])
29
- def global_delete(self, name: str):
30
- """
31
- Delete a global
32
- """
33
- ret = {"success": True}
34
- if name == "GLOB_SENTINEL" or name in self._valid_configs:
35
- ret["response"] = f"{name} is sacred!"
36
- ret["success"] = False
37
- else:
38
- self._h.destroy_glob(name)
39
- ret["response"] = f"Global {name} deleted."
40
- return ret
41
-
42
- @Interface.admin_api()
43
- def global_sentinel_set(self, snt: Sentinel = None):
44
- """
45
- Make a sentinel globally accessible and set it as the global sentinel
46
- """
47
- snt.make_read_only()
48
- snt.propagate_access()
49
- self._h.save_glob("GLOB_SENTINEL", snt.jid)
50
- return {"response": f"Global sentinel set to '{snt}'!"}
51
-
52
- @Interface.admin_api()
53
- def global_sentinel_setaccess(self, snt: Sentinel = None):
54
- """
55
- Make a sentinel globally accessible
56
- """
57
- snt.make_read_only()
58
- snt.propagate_access()
59
- return {"response": f"Sentinel '{snt}' is now globally accessible (read-only)."}
60
-
61
- @Interface.admin_api()
62
- def global_sentinel_revokeaccess(self, snt: Sentinel = None):
63
- """
64
- Revoke the global accessibility of a sentinel. Making it private.
65
- """
66
- if snt.check_write_access(self._m_id):
67
- snt.make_private()
68
- snt.propagate_access()
69
- return {"response": f"Sentinel '{snt}' is now private."}
70
- else:
71
- return {"response:" "Insufficient permission."}
72
-
73
- @Interface.admin_api()
74
- def global_sentinel_unset(self):
75
- """
76
- Unset a global sentinel
77
- """
78
- current = self.global_get("GLOB_SENTINEL")["value"]
79
- if current:
80
- snt = self._h.get_obj(self._m_id, current)
81
- for i in snt.get_deep_obj_list():
82
- i.make_private()
83
- self._h.destroy_glob("GLOB_SENTINEL")
84
- return {"response": "Global sentinel cleared!"}