naeural-client 2.5.30__tar.gz → 2.6.0__tar.gz

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. {naeural_client-2.5.30 → naeural_client-2.6.0}/PKG-INFO +1 -1
  2. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/_ver.py +1 -1
  3. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/generic_session.py +70 -30
  4. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/bc/base.py +56 -1
  5. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/base.py +1 -0
  6. {naeural_client-2.5.30 → naeural_client-2.6.0}/pyproject.toml +1 -1
  7. naeural_client-2.6.0/xperimental/auth/t1.py +27 -0
  8. {naeural_client-2.5.30 → naeural_client-2.6.0}/.devcontainer/Dockerfile +0 -0
  9. {naeural_client-2.5.30 → naeural_client-2.6.0}/.devcontainer/devcontainer.json +0 -0
  10. {naeural_client-2.5.30 → naeural_client-2.6.0}/.gitattributes +0 -0
  11. {naeural_client-2.5.30 → naeural_client-2.6.0}/.github/workflows/python-publish.yml +0 -0
  12. {naeural_client-2.5.30 → naeural_client-2.6.0}/.gitignore +0 -0
  13. {naeural_client-2.5.30 → naeural_client-2.6.0}/.vscode/launch.json +0 -0
  14. {naeural_client-2.5.30 → naeural_client-2.6.0}/LICENSE +0 -0
  15. {naeural_client-2.5.30 → naeural_client-2.6.0}/README.md +0 -0
  16. {naeural_client-2.5.30 → naeural_client-2.6.0}/TODOs.md +0 -0
  17. {naeural_client-2.5.30 → naeural_client-2.6.0}/__init__.py +0 -0
  18. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/__init__.py +0 -0
  19. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/__init__.py +0 -0
  20. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/distributed_custom_code_presets.py +0 -0
  21. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/instance.py +0 -0
  22. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/payload/__init__.py +0 -0
  23. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/payload/payload.py +0 -0
  24. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/pipeline.py +0 -0
  25. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/plugin_template.py +0 -0
  26. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/responses.py +0 -0
  27. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/transaction.py +0 -0
  28. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base/webapp_pipeline.py +0 -0
  29. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/base_decentra_object.py +0 -0
  30. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/bc/__init__.py +0 -0
  31. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/bc/chain.py +0 -0
  32. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/bc/ec.py +0 -0
  33. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/certs/__init__.py +0 -0
  34. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt +0 -0
  35. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/cli/README.md +0 -0
  36. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/cli/cli.py +0 -0
  37. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/cli/cli_commands.py +0 -0
  38. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/cli/nodes.py +0 -0
  39. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/code_cheker/__init__.py +0 -0
  40. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/code_cheker/base.py +0 -0
  41. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/code_cheker/checker.py +0 -0
  42. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/comm/__init__.py +0 -0
  43. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/comm/amqp_wrapper.py +0 -0
  44. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/comm/mqtt_wrapper.py +0 -0
  45. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/README.md +0 -0
  46. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/__init__.py +0 -0
  47. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/apps.py +0 -0
  48. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/comms.py +0 -0
  49. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/environment.py +0 -0
  50. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/formatter.py +0 -0
  51. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/heartbeat.py +0 -0
  52. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/misc.py +0 -0
  53. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/const/payload.py +0 -0
  54. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/__init__.py +0 -0
  55. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/instance/__init__.py +0 -0
  56. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/instance/chain_dist_custom_job_01_plugin.py +0 -0
  57. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/instance/custom_webapi_01_plugin.py +0 -0
  58. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/instance/net_mon_01_plugin.py +0 -0
  59. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/instance/telegram_basic_bot_01_plugin.py +0 -0
  60. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/instance/telegram_conversational_bot_01_plugin.py +0 -0
  61. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/instance/view_scene_01_plugin.py +0 -0
  62. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/default/session/mqtt_session.py +0 -0
  63. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/io_formatter/__init__.py +0 -0
  64. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/io_formatter/base/__init__.py +0 -0
  65. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/io_formatter/base/base_formatter.py +0 -0
  66. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/io_formatter/default/__init__.py +0 -0
  67. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/io_formatter/default/a_dummy.py +0 -0
  68. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/io_formatter/default/aixp1.py +0 -0
  69. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/io_formatter/default/default.py +0 -0
  70. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/io_formatter/io_formatter_manager.py +0 -0
  71. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/__init__.py +0 -0
  72. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/base_logger.py +0 -0
  73. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/__init__.py +0 -0
  74. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/class_instance_mixin.py +0 -0
  75. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/computer_vision_mixin.py +0 -0
  76. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/datetime_mixin.py +0 -0
  77. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/download_mixin.py +0 -0
  78. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/general_serialization_mixin.py +0 -0
  79. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/json_serialization_mixin.py +0 -0
  80. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/pickle_serialization_mixin.py +0 -0
  81. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/process_mixin.py +0 -0
  82. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/resource_size_mixin.py +0 -0
  83. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/timers_mixin.py +0 -0
  84. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/upload_mixin.py +0 -0
  85. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/logger_mixins/utils_mixin.py +0 -0
  86. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/small_logger.py +0 -0
  87. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/tzlocal/__init__.py +0 -0
  88. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/tzlocal/unix.py +0 -0
  89. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/tzlocal/utils.py +0 -0
  90. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/tzlocal/win32.py +0 -0
  91. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/logging/tzlocal/windows_tz.py +0 -0
  92. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/plugins_manager_mixin.py +0 -0
  93. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/utils/__init__.py +0 -0
  94. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/utils/comm_utils.py +0 -0
  95. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/utils/config.py +0 -0
  96. {naeural_client-2.5.30 → naeural_client-2.6.0}/naeural_client/utils/dotenv.py +0 -0
  97. {naeural_client-2.5.30 → naeural_client-2.6.0}/nepctl.MD +0 -0
  98. {naeural_client-2.5.30 → naeural_client-2.6.0}/requirements.txt +0 -0
  99. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/.example_env +0 -0
  100. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/8. custom_code_fastapi_assets/index.html +0 -0
  101. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/9. code_sandbox_from_scratch_assets/index.html +0 -0
  102. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/_example_pk_sdk.pem +0 -0
  103. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex01_part1_connect.py +0 -0
  104. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex01_part2_filter.py +0 -0
  105. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex01_part3_adv_filter.py +0 -0
  106. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex02_first_deploy.py +0 -0
  107. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex03_custom_code_on_one_remote__example_1.py +0 -0
  108. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex04_custom_code_on_one_remote__example_2.py +0 -0
  109. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex05_custom_code_on_one_remote__example_3.py +0 -0
  110. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex06_custom_code_on_multiple_remotes__example_1.py +0 -0
  111. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex07_custom_code_on_multiple_remotes__example_2.py +0 -0
  112. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex08_custom_webapi.py +0 -0
  113. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex09_code_sandbox_from_scratch.py +0 -0
  114. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex10_telegram_echo_bot.py +0 -0
  115. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex11_telegram_blackjack_bot.py +0 -0
  116. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex12_telegram_smart_bot.py +0 -0
  117. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/ex13_launch_repo_based_webapp.py +0 -0
  118. {naeural_client-2.5.30 → naeural_client-2.6.0}/tutorials/video_presentation/1. hello_world.ipynb +0 -0
  119. {naeural_client-2.5.30 → naeural_client-2.6.0}/winrun.bat +0 -0
  120. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/.example_env +0 -0
  121. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/_archive/test.py +0 -0
  122. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/_tutorials/3. simple_real_time_custom_code.py +0 -0
  123. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/_tutorials/4. real_time_custom_code_2.py +0 -0
  124. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/_tutorials/8. chatbot.py +0 -0
  125. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/check_local_keys/check1.py +0 -0
  126. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/decentralized/chain_dist_example.py +0 -0
  127. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/decentralized/chain_dist_example_initiator.py +0 -0
  128. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/decentralized/chain_dist_example_worker.py +0 -0
  129. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/enc_dec/enc_dec_test.py +0 -0
  130. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/eth/eth_sign.py +0 -0
  131. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/eth/info.md +0 -0
  132. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/eth/sign.py +0 -0
  133. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/multi-enc-dec/multi_test1.py +0 -0
  134. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/multi-enc-dec/multi_test2.py +0 -0
  135. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/sign/test_sign1.py +0 -0
  136. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/utils/get_documentation.py +0 -0
  137. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/various/README.md +0 -0
  138. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/various/attach_example.py +0 -0
  139. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/various/ex1.py +0 -0
  140. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/various/hello.py +0 -0
  141. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/various/remote_exec.py +0 -0
  142. {naeural_client-2.5.30 → naeural_client-2.6.0}/xperimental/various/save_images.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_client
3
- Version: 2.5.30
3
+ Version: 2.6.0
4
4
  Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol Edge Protocol framework
5
5
  Project-URL: Homepage, https://github.com/NaeuralEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/NaeuralEdgeProtocol/naeural_client/issues
@@ -1,4 +1,4 @@
1
- __VER__ = "2.5.30"
1
+ __VER__ = "2.6.0"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
@@ -1,3 +1,12 @@
1
+ """
2
+
3
+ TODO:
4
+ - config precedence when starting a session - env vs manually provided data
5
+ - add support for remaining commands from EE
6
+
7
+
8
+ """
9
+
1
10
  import json
2
11
  import os
3
12
  import traceback
@@ -30,7 +39,7 @@ from ..utils.config import (
30
39
 
31
40
  # from ..default.instance import PLUGIN_TYPES # circular import
32
41
 
33
- # TODO: add support for remaining commands from EE
42
+
34
43
 
35
44
  DEBUG_MQTT_SERVER = "r9092118.ala.eu-central-1.emqxsl.com"
36
45
 
@@ -87,6 +96,7 @@ class GenericSession(BaseDecentrAIObject):
87
96
  local_cache_app_folder='_local_cache',
88
97
  use_home_folder=False,
89
98
  eth_enabled=True,
99
+ auto_configuration=True,
90
100
  **kwargs
91
101
  ) -> None:
92
102
  """
@@ -166,6 +176,8 @@ class GenericSession(BaseDecentrAIObject):
166
176
  nr_empty = self._config[key]["TOPIC"].count("{}")
167
177
  self._config[key]["TOPIC"] = self._config[key]["TOPIC"].format(root_topic, *(["{}"] * (nr_empty - 1)))
168
178
  # end if root_topic
179
+
180
+ self.__auto_configuration = auto_configuration
169
181
 
170
182
  self.log = log
171
183
  self.name = name
@@ -188,13 +200,12 @@ class GenericSession(BaseDecentrAIObject):
188
200
  # this is used to store data received from net-mon instances
189
201
  self.__current_network_statuses = {}
190
202
 
191
- pwd = pwd or kwargs.get('password', kwargs.get('pass', None))
192
- user = user or kwargs.get('username', None)
193
- host = host or kwargs.get('hostname', None)
203
+ self.__pwd = pwd or kwargs.get('password', kwargs.get('pass', None))
204
+ self.__user = user or kwargs.get('username', None)
205
+ self.__host = host or kwargs.get('hostname', None)
206
+ self.__port = port
207
+ self.__secured = secured
194
208
 
195
- ## now we prepare config via ~/.naeural/config or .env
196
- self.__fill_config(host, port, user, pwd, secured, dotenv_path)
197
- ## end config
198
209
 
199
210
  self.custom_on_payload = on_payload
200
211
  self.custom_on_heartbeat = on_heartbeat
@@ -206,15 +217,15 @@ class GenericSession(BaseDecentrAIObject):
206
217
  self.__running_main_loop_thread = False
207
218
  self.__closed_everything = False
208
219
 
209
- self.sdk_main_loop_thread = Thread(target=self.__main_loop, daemon=True)
210
220
  self.__formatter_plugins_locations = formatter_plugins_locations
211
221
 
212
222
  self.__blockchain_config = blockchain_config
213
-
214
- # TODO: needs refactoring - suboptimal design
223
+
224
+ self.__dotenv_path = dotenv_path
225
+
215
226
  self.__bc_engine : DefaultBlockEngine = bc_engine
216
227
  self.bc_engine : DefaultBlockEngine = None
217
- # END TODO
228
+
218
229
 
219
230
 
220
231
  self.__open_transactions: list[Transaction] = []
@@ -246,13 +257,37 @@ class GenericSession(BaseDecentrAIObject):
246
257
  )
247
258
  return
248
259
 
249
- def startup(self):
260
+ def startup(self):
261
+ ## 1st config step - we prepare config via ~/.naeural/config or .env
262
+ self.__load_user_config(dotenv_path=self.__dotenv_path)
263
+
264
+ # TODO: needs refactoring - suboptimal design
250
265
  # start the blockchain engine assuming config is already set
266
+
251
267
  self.__start_blockchain(
252
268
  self.__bc_engine, self.__blockchain_config,
253
269
  user_config=self.__user_config_loaded,
254
270
  )
271
+
272
+ # this next call will attempt to complete the dauth process
273
+ dct_env = self.bc_engine.dauth_autocomplete(
274
+ dauth_endp=None, # get from consts or env
275
+ add_env=self.__auto_configuration,
276
+ debug=False,
277
+ )
255
278
  # end bc_engine
279
+ # END TODO
280
+
281
+ ## last config step
282
+ self.__fill_config(
283
+ host=self.__host,
284
+ port=self.__port,
285
+ user=self.__port,
286
+ pwd=self.__pwd,
287
+ secured=self.__secured,
288
+ )
289
+ ## end config
290
+
256
291
  self.formatter_wrapper = IOFormatterWrapper(self.log, plugin_search_locations=self.__formatter_plugins_locations)
257
292
 
258
293
  msg = f"Connection to {self._config[comm_ct.USER]}:*****@{self._config[comm_ct.HOST]}:{self._config[comm_ct.PORT]} {'<secured>' if self._config[comm_ct.SECURED] else '<UNSECURED>'}"
@@ -895,9 +930,29 @@ class GenericSession(BaseDecentrAIObject):
895
930
 
896
931
  # Utils
897
932
  if True:
898
- def __fill_config(self, host, port, user, pwd, secured, dotenv_path):
933
+
934
+ def __load_user_config(self, dotenv_path):
935
+ # if the ~/.naeural/config file exists, load the credentials from there else try to load them from .env
936
+ if not load_user_defined_config():
937
+ # this method will search for the credentials in the environment variables
938
+ # the path to env file, if not specified, will be search in the following order:
939
+ # 1. current working directory
940
+ # 2-N. directories of the files from the call stack
941
+ load_dotenv(dotenv_path=dotenv_path, verbose=False)
942
+ if not self.silent:
943
+ keys = [k for k in os.environ if k.startswith("EE_")]
944
+ print("Loaded credentials from environment variables: {keys}", flush=True)
945
+ self.__user_config_loaded = False
946
+ else:
947
+ if not self.silent:
948
+ keys = [k for k in os.environ if k.startswith("EE_")]
949
+ print(f"Loaded credentials from `{get_user_config_file()}`: {keys}.", flush=True)
950
+ self.__user_config_loaded = True
951
+ # endif config loading from ~ or ./.env
952
+
953
+ def __fill_config(self, host, port, user, pwd, secured):
899
954
  """
900
- Fill the configuration dictionary with the credentials provided when creating this instance.
955
+ Fill the configuration dictionary with the ceredentials provided when creating this instance.
901
956
 
902
957
 
903
958
  Parameters
@@ -925,23 +980,8 @@ class GenericSession(BaseDecentrAIObject):
925
980
  ------
926
981
  ValueError
927
982
  Missing credentials
928
- """
983
+ """
929
984
 
930
- # if the ~/.naeural/config file exists, load the credentials from there else try to load them from .env
931
- if not load_user_defined_config():
932
- # this method will search for the credentials in the environment variables
933
- # the path to env file, if not specified, will be search in the following order:
934
- # 1. current working directory
935
- # 2-N. directories of the files from the call stack
936
- load_dotenv(dotenv_path=dotenv_path, verbose=False)
937
- if not self.silent:
938
- print("Loaded credentials from environment variables.", flush=True)
939
- self.__user_config_loaded = False
940
- else:
941
- if not self.silent:
942
- print(f"Loaded credentials from `{get_user_config_file()}`.", flush=True)
943
- self.__user_config_loaded = True
944
- # endif config loading from ~ or ./.env
945
985
 
946
986
  possible_user_values = [
947
987
  user,
@@ -4,6 +4,8 @@ import json
4
4
  import binascii
5
5
  import numpy as np
6
6
  import datetime
7
+ import uuid
8
+ import requests
7
9
 
8
10
  from hashlib import sha256, md5
9
11
  from threading import Lock
@@ -14,7 +16,7 @@ from cryptography.hazmat.primitives import serialization
14
16
 
15
17
  from ..utils.config import get_user_folder
16
18
 
17
- from ..const.base import BCctbase, BCct
19
+ from ..const.base import BCctbase, BCct, DAUTH_SUBKEY, DAUTH_URL
18
20
 
19
21
 
20
22
 
@@ -1212,3 +1214,56 @@ class BaseBlockEngine:
1212
1214
  return self.__eth_account
1213
1215
 
1214
1216
  ### end Ethereum
1217
+
1218
+
1219
+ def dauth_autocomplete(self, dauth_endp=None, add_env=True, debug=False, max_tries=5):
1220
+ dct_env = {}
1221
+ done = False
1222
+ tries = 0
1223
+ in_env = False
1224
+ url = dauth_endp
1225
+
1226
+ if url is None:
1227
+ if isinstance(DAUTH_URL, str) and len(DAUTH_URL) > 0:
1228
+ url = DAUTH_URL
1229
+ else:
1230
+ url = os.environ.get('DAUTH_URL')
1231
+ in_env = True
1232
+
1233
+ if isinstance(url, str) and len(url) > 0:
1234
+ if dauth_endp is None:
1235
+ self.P("Found dAuth URL in environment: '{}'".format(url), color='g')
1236
+
1237
+ while not done:
1238
+ self.P(f"Trying dAuth `{url}` information... (try {tries})")
1239
+ try:
1240
+ nonce_data = {
1241
+ 'nonce' : str(uuid.uuid4())[:8]
1242
+ }
1243
+ self.sign(nonce_data)
1244
+ response = requests.post(url, json={'body' : nonce_data})
1245
+ dct_response = response.json()
1246
+ if debug:
1247
+ self.P(f"Response:\n {json.dumps(dct_response, indent=2)}")
1248
+ dct_result = dct_response.get('result', {}).get(DAUTH_SUBKEY, {})
1249
+ error = dct_response.get('error', None)
1250
+ if error is not None:
1251
+ self.P(f"Error in dAuth response: {dct_response}", color='r')
1252
+ dct_env = {k : v for k,v in dct_result.items() if k.startswith('EE_')}
1253
+ self.P("Found {} keys in dAuth response.".format(len(dct_env)), color='g')
1254
+ for k, v in dct_env.items():
1255
+ if k not in os.environ:
1256
+ self.P(f" Adding key `{k}{'=' + str(v) if debug else ''}` to env.", color='y')
1257
+ else:
1258
+ self.P(f" Overwrite `{k}{'=' + str(v) if debug else ''}` in env.", color='y')
1259
+ if add_env:
1260
+ os.environ[k] = v
1261
+ done = True
1262
+ except Exception as exc:
1263
+ self.P(f"Error in dAuth URL request: {exc}", color='r')
1264
+ #end try
1265
+ tries += 1
1266
+ if tries >= max_tries:
1267
+ done = True
1268
+ #end while
1269
+ return dct_env
@@ -3,6 +3,7 @@ SB_ID = 'SB_ID' # change to SB_ID = EE_ID post mod from sb to ee
3
3
 
4
4
 
5
5
  DAUTH_URL = 'https://dauth.ratio1.ai/get_auth_data'
6
+ DAUTH_SUBKEY = 'auth'
6
7
 
7
8
  class LocalInfo:
8
9
  LOCAL_INFO_FILE = 'local_info.json'
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "naeural_client"
7
- version = "2.5.30"
7
+ version = "2.6.0"
8
8
  authors = [
9
9
  { name="Andrei Ionut Damian", email="andrei.damian@me.com" },
10
10
  { name="Cristan Bleotiu", email="cristibleotiu@gmail.com" },
@@ -0,0 +1,27 @@
1
+
2
+ import json
3
+
4
+
5
+ from naeural_client import Logger, const
6
+ from naeural_client.bc import DefaultBlockEngine
7
+
8
+
9
+
10
+ if __name__ == '__main__' :
11
+ l = Logger("ENC", base_folder=".", app_folder="_local_cache")
12
+ eng1 = DefaultBlockEngine(
13
+ log=l, name="test1",
14
+ config={
15
+ "PEM_FILE" : "test1.pem",
16
+ "PASSWORD" : None,
17
+ "PEM_LOCATION" : "data"
18
+ }
19
+ )
20
+
21
+ d = eng1.dauth_autocomplete(
22
+ add_env=False,
23
+ debug=True,
24
+ max_tries=1,
25
+ )
26
+
27
+ l.P(f"Result: {d}", color='b')
File without changes
File without changes