naeural-client 2.5.31__py3-none-any.whl → 2.6.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.
naeural_client/_ver.py CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "2.5.31"
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,
naeural_client/bc/base.py CHANGED
@@ -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'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_client
3
- Version: 2.5.31
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,10 +1,10 @@
1
1
  naeural_client/__init__.py,sha256=YimqgDbjLuywsf8zCWE0EaUXH4MBUrqLxt0TDV558hQ,632
2
- naeural_client/_ver.py,sha256=P1eYAwo10GNYpHbjm3Vj2wUQGqv-iglPMssAp1Oao1k,331
2
+ naeural_client/_ver.py,sha256=8l5htl3vbgo8TfOaTMzZk4pKVa_lEaGc7XDdqAOdqCI,330
3
3
  naeural_client/base_decentra_object.py,sha256=C4iwZTkhKNBS4VHlJs5DfElRYLo4Q9l1V1DNVSk1fyQ,4412
4
4
  naeural_client/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
5
5
  naeural_client/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
6
6
  naeural_client/base/distributed_custom_code_presets.py,sha256=cvz5R88P6Z5V61Ce1vHVVh8bOkgXd6gve_vdESDNAsg,2544
7
- naeural_client/base/generic_session.py,sha256=CrG66_XsMtnM4VrMNeLNlZv6UDJUf9J9pODvqpPTBek,91553
7
+ naeural_client/base/generic_session.py,sha256=o-qY5Ml72597qM04cgugqzkN9n74LBLrDVOUEZmmgUs,92433
8
8
  naeural_client/base/instance.py,sha256=kcZJmjLBtx8Bjj_ysIOx1JmLA-qSpG7E28j5rq6IYus,20444
9
9
  naeural_client/base/pipeline.py,sha256=b4uNHrEIOlAtw4PGUx20dxwBhDck5__SrVXaHcSi8ZA,58251
10
10
  naeural_client/base/plugin_template.py,sha256=qGaXByd_JZFpjvH9GXNbT7KaitRxIJB6-1IhbKrZjq4,138123
@@ -14,7 +14,7 @@ naeural_client/base/webapp_pipeline.py,sha256=QmPLVmhP0CPdi0YuvbZEH4APYz2Amtw3gy
14
14
  naeural_client/base/payload/__init__.py,sha256=y8fBI8tG2ObNfaXFWjyWZXwu878FRYj_I8GIbHT4GKE,29
15
15
  naeural_client/base/payload/payload.py,sha256=x-au7l67Z_vfn_4R2C_pjZCaFuUVXHngJiGOfIAYVdE,2690
16
16
  naeural_client/bc/__init__.py,sha256=FQj23D1PrY06NUOARiKQi4cdj0-VxnoYgYDEht8lpr8,158
17
- naeural_client/bc/base.py,sha256=Nd0THGidmlLZOD8k8vwldQqIZ_LnvMgAE6l5U5OA45E,32286
17
+ naeural_client/bc/base.py,sha256=gKpwivIyxBeuTdbNTfAJEWTi5U6a4XAV63tD3QsuhYE,34280
18
18
  naeural_client/bc/chain.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  naeural_client/bc/ec.py,sha256=qI8l7YqiS4MNftlx-tF7IZUswrSeQc7KMn5OZ0fEaJs,23370
20
20
  naeural_client/certs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -32,7 +32,7 @@ naeural_client/comm/mqtt_wrapper.py,sha256=Ig3bFZkCbWd4y_Whn2PPa91Z3aLgNbNPau6Tn
32
32
  naeural_client/const/README.md,sha256=6OHesr-f5NBuuJGryEoi_TCu2XdlhfQYlDKx_IJoXeg,177
33
33
  naeural_client/const/__init__.py,sha256=MM6Zib6i7M2qWcMkLtLx14zqU-lE-u2uPHjNvbh2jAM,478
34
34
  naeural_client/const/apps.py,sha256=gIONTZUkqPveu3DwelyJWpbFMeIR9l6DlaNg-xEfK1A,611
35
- naeural_client/const/base.py,sha256=cL4TfOo6zKUx1fF5ssOOMV0WBouvzxM23YRZk2jFoo0,4198
35
+ naeural_client/const/base.py,sha256=ToCqp_JW6mq3J2Ul2dJ3Xhp8gxSg7rg4nTYjIPtvDOI,4220
36
36
  naeural_client/const/comms.py,sha256=La6JXWHexH8CfcBCKyT4fCIoeaoZlcm7KtZ57ab4ZgU,2201
37
37
  naeural_client/const/environment.py,sha256=iytmTDgbOjvORPwHQmc0K0r-xJx7dnnzNnqAJJiFCDA,870
38
38
  naeural_client/const/formatter.py,sha256=AW3bWlqf39uaqV4BBUuW95qKYfF2OkkU4f9hy3kSVhM,200
@@ -81,8 +81,8 @@ naeural_client/utils/__init__.py,sha256=mAnke3-MeRzz3nhQvhuHqLnpaaCSmDxicd7Ck9uw
81
81
  naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,1072
82
82
  naeural_client/utils/config.py,sha256=JfW2gMQMYx9NzF2M4mJpioXawDHcOQ3deJprpCRtdOI,5874
83
83
  naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
84
- naeural_client-2.5.31.dist-info/METADATA,sha256=EkMVKKJGhbTKtA3MLXJnYLLTsASfhaH3Zt3cbIVS9Qs,14619
85
- naeural_client-2.5.31.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
86
- naeural_client-2.5.31.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
87
- naeural_client-2.5.31.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
88
- naeural_client-2.5.31.dist-info/RECORD,,
84
+ naeural_client-2.6.0.dist-info/METADATA,sha256=BduegOU9wXWNr2DsNAurIRJjBgf2l4o6X12UmlOiipY,14618
85
+ naeural_client-2.6.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
86
+ naeural_client-2.6.0.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
87
+ naeural_client-2.6.0.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
88
+ naeural_client-2.6.0.dist-info/RECORD,,